Repository navigation
Expand file tree
/
Copy pathtrelloEngWorkInUrgencyDashboard.js
More file actions
96 lines (94 loc) · 3.59 KB
/
Copy pathtrelloEngWorkInUrgencyDashboard.js
File metadata and controls
96 lines (94 loc) · 3.59 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const TRELLO_CREDENTIALS_HELPER_FILE = "https://docs.google.com/document/d/1HwaedNa861gkj93TaradW5n0MID8cbeamiU5SXCvX64/edit#heading=h.ijjo2dol5z6v"
const LIST_IDS = [
"65e07588569c27c0664edf17", // https://trello.com/c/rWgYEIaP
"65d8c6c2bdf8fb6ece5c3288", // https://trello.com/c/FJrnjzoC
"65eb3c3f18360ab17df520fd", // https://trello.com/c/l4Qqa3lh
"65f86bf9394966aa2a03379f" // https://trello.com/c/jym1mHmg
]
new Vue({
el: '#app',
data: {
options: {
quarter: "",
squad: ""
},
error: null,
loading: false,
trelloCredentialsHelperFile: TRELLO_CREDENTIALS_HELPER_FILE,
credentials: {
trelloApiKey: "",
trelloOAuth1: ""
},
urgencyCardsBySquadName: {},
squadNames: null,
listIdBySquadName: {},
reportBuilt: false,
reportBuildForAllSquads: false
},
computed: {
areCredentialsFilled() {
return !! this.credentials.trelloApiKey && !! this.credentials.trelloOAuth1;
},
isAccessButtonDisabled() {
return ! this.areCredentialsFilled || this.loading;
},
isSubmitButtonDisabled() {
return ! this.areCredentialsFilled || this.loading || ! this.options.squad || ! this.options.quarter;
},
quarters() {
const currentQuarter = moment().quarter();
return [-3, -2, -1, 0].map(quarterOffset => moment().quarter(currentQuarter + quarterOffset).format("[Q]Q YYYY"));
}
},
methods: {
async buildReport() {
this.resetReport();
this.error = null;
this.loading = true;
const selectedSquadNames = this.getSelectedSquadNames();
try {
for (const selectedSquadName of selectedSquadNames) {
await this.buildReportForSquad(selectedSquadName);
}
this.reportBuilt = true;
this.reportBuildForAllSquads = (this.options.squad === "*");
} catch (error) {
this.error = error.message;
} finally {
this.loading = false;
}
},
async buildReportForSquad(squadName) {
const listId = this.listIdBySquadName[squadName];
const cards = await fetchCardsInList(listId, this.credentials);
const filteredCards = cards.filter(card => ! card.isTemplate && card.labels.map(label => label.name.replace("-", " ")).includes(this.options.quarter));
this.urgencyCardsBySquadName[squadName] = filteredCards.map(({name, url}) => ({ name, url }));
},
async fetchSquadNames() {
this.error = null;
this.loading = true;
try {
this.squadNames = (await Promise.all(LIST_IDS.map(this.getSquadNameFromListId))).sort();
}
catch (error) {
this.error = error.message;
} finally {
this.loading = false;
}
},
getSelectedSquadNames() {
return this.options.squad === "*" ? this.squadNames : [this.options.squad];
},
async getSquadNameFromListId(listId) {
const list = await fetchList(listId, this.credentials);
const squadName = list.name.match(/[^[]+(?=\])/g).pop();
this.listIdBySquadName[squadName] = listId;
return squadName;
},
resetReport() {
this.reportBuilt = false;
this.reportBuildForAllSquads = false;
this.urgencyCardsBySquadName = {};
}
}
});