forked from Tinkoff/jira-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwimlaneSettings.js
199 lines (166 loc) · 7.65 KB
/
SwimlaneSettings.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import each from '@tinkoff/utils/array/each';
import { PageModification } from '../shared/PageModification';
import { getSettingsTab } from '../routing';
import style from './styles.css';
import { BOARD_PROPERTIES } from '../shared/constants';
import { mergeSwimlaneSettings } from './utils';
import { settingsJiraDOM as DOM } from './constants';
const EMPTY_LIMIT_VALUE = ' - ';
export default class extends PageModification {
async shouldApply() {
return (await getSettingsTab()) === 'swimlanes';
}
getModificationId() {
return `add-swimlane-settings-${this.getSearchParam('rapidView')}`;
}
appendStyles() {
return `
<style>
.${style.limitInput} { display: none; }
.${style.ignoreWIPInColumnsInput} { display: none; }
.aui-restfultable-focused > td.${style.limitInfo} > .${style.limitInput} { display: inline; }
.aui-restfultable-focused > td.${style.limitInfo} > .${style.limitValue} { display: none; }
.aui-restfultable-focused > td.${style.ignoreWIPInColumns} > .${style.ignoreWIPInColumnsInput} { display: inline; }
.aui-restfultable-focused > td.${style.ignoreWIPInColumns} > .${style.ignoreWIPInColumnsValue} { display: none; }
.aui-restfultable-create > .aui-restfultable-focused > td.${style.limitInfo} > .${style.limitValue} { visibility: hidden; }
.aui-restfultable-create > .aui-restfultable-focused > td.${style.limitInfo} > .${style.limitInput} { display: none; }
.aui-restfultable-create > .aui-restfultable-focused > td.${style.ignoreWIPInColumns} > .${style.ignoreWIPInColumnsValue} { visibility: hidden; }
.aui-restfultable-create > .aui-restfultable-focused > td.${style.ignoreWIPInColumns} > .${style.ignoreWIPInColumnsInput} { display: none; }
</style>
`;
}
waitForLoading() {
return this.waitForElement('#swimlanes');
}
loadData() {
return Promise.all([
this.getBoardEditData(),
Promise.all([
this.getBoardProperty(BOARD_PROPERTIES.SWIMLANE_SETTINGS),
this.getBoardProperty(BOARD_PROPERTIES.OLD_SWIMLANE_SETTINGS),
]).then(mergeSwimlaneSettings),
]);
}
apply([boardData, settings]) {
this.settings = settings;
if (boardData && boardData.canEdit) {
this.renderClearButton();
this.modifyTableHeader();
this.modifyCreationRow();
this.modifySimpleRows();
}
}
renderClearButton() {
const resetSwimlaneLimitsBtnId = 'reset-swimlane-settings';
this.insertHTML(
document.querySelector('#ghx-swimlane-strategy-config'),
'beforebegin',
`
<div class="${style.resetSwimlaneWrapper}">
<button id="${resetSwimlaneLimitsBtnId}" class="aui-button" type="button">Reset swimlane limits</button>
</div>
`
);
const resetBtn = document.querySelector(`#${resetSwimlaneLimitsBtnId}`);
resetBtn.addEventListener('click', async () => {
try {
resetBtn.disabled = true;
await this.deleteBoardProperty(BOARD_PROPERTIES.SWIMLANE_SETTINGS);
this.settings = {};
each(limit => {
limit.querySelector('span').textContent = EMPTY_LIMIT_VALUE;
limit.querySelector('input').value = EMPTY_LIMIT_VALUE;
}, document.querySelectorAll('.wip-limit-cell'));
each(ignoreWip => {
ignoreWip.querySelector('span').textContent = 'false';
ignoreWip.querySelector('input').removeAttribute('checked');
}, document.querySelectorAll('.is-expedite-cell'));
} finally {
resetBtn.disabled = false;
}
});
}
modifyTableHeader() {
const tableHeaderRow = document.querySelector(`${DOM.table} > ${DOM.tableHead} > ${DOM.row}`);
const secondColumn = tableHeaderRow.querySelector(`${DOM.headCell}:nth-child(2)`);
this.insertHTML(secondColumn, 'beforebegin', `<th class="${style.limitInfo}">WIP Limits</th>`);
this.insertHTML(
secondColumn,
'beforebegin',
`<th class="${style.ignoreWIPInColumns}">Is expedite <i title="Issues from this swimlane will be ignored from column WIP limits" style="font-style: normal; cursor: pointer;">ⓘ</i></th>`
);
}
modifyCreationRow() {
const selector = `${DOM.table} > ${DOM.createTbody} > ${DOM.row}`;
const creationRow = document.querySelector(selector);
const secondColumn = creationRow.querySelector(`${DOM.cell}:nth-child(2)`);
this.insertHTML(secondColumn, 'beforebegin', this.renderLimitCell());
this.insertHTML(secondColumn, 'beforebegin', this.renderIgnoreWIPLimitsCell());
this.onDOMChangeOnce(selector, () => {
this.modifyCreationRow();
this.modifySimpleRows();
});
}
renderLimitCell(swimlineId, swimlineLimit = EMPTY_LIMIT_VALUE) {
return `
<td class="${style.limitInfo} wip-limit-cell">
<span class="${style.limitValue} ${style.textValue}" data-swimline-id="${swimlineId}">${swimlineLimit ||
EMPTY_LIMIT_VALUE}</span>
<input type="text" value="${swimlineLimit}" class="${style.limitInput}"/>
</td>
`;
}
renderIgnoreWIPLimitsCell(swimlineId, ignoreWipInColumns = false) {
return `
<td class="${style.ignoreWIPInColumns} is-expedite-cell">
<span class="${style.ignoreWIPInColumnsValue} ${
style.textValue
}" data-swimline-id="${swimlineId}">${ignoreWipInColumns}</span>
<input type="checkbox" ${ignoreWipInColumns ? 'checked' : ''} class="${style.ignoreWIPInColumnsInput}"/>
</td>
`;
}
modifySimpleRows = () => {
const swimlaneSelector = `${DOM.table} > ${DOM.sortableTbody} > ${DOM.row}`;
const swimlaneRows = document.querySelectorAll(swimlaneSelector);
each(row => {
if (row.classList.contains(DOM.everythingElseRow)) return;
const rowType = row.classList.contains('aui-restfultable-editrow') ? 'edit' : 'view';
if (row.dataset.modifiedRowType === rowType) return;
this.showInputBoxLimits(row);
this.showIgnoreWipInColumns(row);
row.querySelectorAll(`.${style.textValue}`).forEach(textValue => {
this.addEventListener(textValue, 'click', () => row.querySelector('.aui-restfultable-editable').click());
});
this.setDataAttr(row, 'modifiedRowType', rowType);
}, swimlaneRows);
each(button => {
this.addEventListener(button, 'click', e => this.handleSettingsChange(e));
}, document.querySelectorAll(`${swimlaneSelector} input[type=submit]`));
// переход в редактирование
this.onDOMChangeOnce(`${DOM.table} > ${DOM.sortableTbody}`, () => this.modifySimpleRows(), {
attributeFilter: ['class'],
subtree: true,
});
};
showInputBoxLimits(row) {
const secondColumn = row.querySelector(`${DOM.cell}:nth-child(2)`);
const swimlineId = row.getAttribute('data-id');
const swimlineLimit = this.settings[swimlineId] && this.settings[swimlineId].limit;
this.insertHTML(secondColumn, 'beforebegin', this.renderLimitCell(swimlineId, swimlineLimit));
}
showIgnoreWipInColumns(row) {
const thirdColumn = row.querySelector(`${DOM.cell}:nth-child(3)`);
const swimlineId = row.getAttribute('data-id');
const ignoreWipInColumns = this.settings[swimlineId] && this.settings[swimlineId].ignoreWipInColumns;
this.insertHTML(thirdColumn, 'beforebegin', this.renderIgnoreWIPLimitsCell(swimlineId, ignoreWipInColumns));
}
handleSettingsChange(event) {
const row = event.target.parentElement.parentElement;
const swimlaneId = Number(row.dataset.id);
const limit = Number(row.querySelector(`.${style.limitInput}`).value) || null;
const ignoreWipInColumns = row.querySelector(`.${style.ignoreWIPInColumnsInput}`).checked;
this.settings[swimlaneId] = { limit, ignoreWipInColumns };
this.updateBoardProperty(BOARD_PROPERTIES.SWIMLANE_SETTINGS, this.settings);
}
}