-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
61 lines (56 loc) · 1.76 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const MAX_ITEMS_STORE = 10;
const MAX_ITEMS_TO_DISPLAY = 5;
var app = new Vue({
el: "#app",
data: {
trackerId: "",
donePercentage: "",
hours: "",
commitMessage: "",
isCopied: false,
commitLine: "",
lastCopiedItems: [],
},
mounted() {
this.renderTickets();
},
methods: {
extractTrackerId(text) {
var jira_matcher = /([A-Z][A-Z0-9]+-[0-9]+)/g;
const jiraId = String(text).match(jira_matcher);
return String(jiraId);
},
async copyCommitLine() {
try {
const textToCopy = document.querySelector("#commitLine").textContent;
await navigator.clipboard.writeText(textToCopy);
this.isCopied = true;
const itemToStore = this.extractTrackerId(this.trackerId);
const lsItems = lsLoad("lastTickets");
if (lsItems && Array.isArray(lsItems) && !lsItems.includes(itemToStore)) {
lsPrependItemToArray("lastTickets", itemToStore);
}
this.renderTickets();
} catch (e) {
console.log(e);
alert("Cannot copy");
}
},
renderTickets() {
this.lastCopiedItems = lsLoad("lastTickets") || [];
if (this.lastCopiedItems.length === 0) lsStore("lastTickets", this.lastCopiedItems);
// localStorage clean up process
if (this.lastCopiedItems.length > MAX_ITEMS_STORE) {
const howManyToDelete = Number(this.lastCopiedItems.length - MAX_ITEMS_STORE);
this.lastCopiedItems.splice(this.lastCopiedItems.length - howManyToDelete, howManyToDelete);
lsStore("lastTickets", this.lastCopiedItems);
}
this.lastCopiedItems = this.lastCopiedItems.slice(0, MAX_ITEMS_TO_DISPLAY);
},
},
computed: {
getTrackerId() {
return this.extractTrackerId(this.trackerId);
},
},
});