-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
541 lines (453 loc) · 15.7 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
function moveRow(direction, btn) {
var row = btn.parentElement.parentElement;
var sibling;
if (direction > 0) {
sibling = row.nextElementSibling;
} else {
sibling = row.previousElementSibling;
}
if (sibling) {
var parent = row.parentElement;
parent.removeChild(row);
if (direction > 0) {
sibling.after(row);
} else {
sibling.before(row);
}
updatePriorities();
}
}
function copyTable() {
let originalTable = document.querySelector('table');
let copyTable = originalTable.cloneNode(true);
Array.from(copyTable.rows).forEach(row => row.deleteCell(-1));
Array.from(copyTable.rows).forEach(row => {
let priorityCell = row.cells[0];
let iconClass = priorityCell.querySelector('i').className;
let status;
switch(iconClass) {
case 'fas fa-exclamation-triangle text-warning':
status = 'KRITISCH';
break;
case 'fas fa-arrow-up text-primary':
status = 'HOCH';
break;
default:
status = 'NORMAL';
}
priorityCell.textContent = status;
});
let range = document.createRange();
range.selectNode(copyTable);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
alert('Tabelle kopiert!');
}
function toggleStrike(event) {
let target = event.target;
while (target && target.nodeName !== 'BUTTON') {
target = target.parentElement;
}
let row;
if (!target && event.nodeName != "TR") {
return;
} else if(event.nodeName == "TR") {
row = event;
} else {
row = target.parentElement.parentElement;
}
var cells = row.getElementsByTagName('td');
for (var i = 0; i < cells.length - 1; i++) {
cells[i].classList.toggle('strike');
}
var icon = target.getElementsByTagName('i')[0];
icon.classList.toggle('text-secondary');
icon.classList.toggle('text-danger');
}
function updatePriorities() {
var tableBody = document.getElementById('tableBody');
var rows = tableBody.getElementsByTagName('tr');
var criticalCount = 1;
var highCount = 2;
var normalCount = 4;
for (var i = 0; i < rows.length; i++) {
var priorityCell = rows[i].getElementsByTagName('td')[0];
var iconClass;
if (i < criticalCount) {
iconClass = 'fa-exclamation-triangle text-warning';
} else if (i < criticalCount + highCount) {
iconClass = 'fa-arrow-up text-primary';
} else if (i < criticalCount + highCount + normalCount) {
iconClass = 'fa-arrow-right text-primary';
} else {
iconClass = 'fa-arrow-down text-secondary';
}
var icon = document.createElement('i');
icon.className = 'fas ' + iconClass;
priorityCell.innerHTML = '';
priorityCell.appendChild(icon);
}
}
function openDeleteModal(event) {
$('#deleteModal').modal('show');
let rowToDelete = event;
if(event?.target?.closest('tr')) {
rowToDelete = event.target.closest('tr');
}
document.getElementById('confirmDelete').onclick = function() {
rowToDelete.remove();
$('#deleteModal').modal('hide');
if(document.getElementById('doNotAskAgain').checked) {
document.cookie = "doNotAskDelete=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
}
saveTable();
}
}
function addRow() {
var tableBody = document.getElementById('tableBody');
var newRow = document.createElement('tr');
var priorityCell = document.createElement('td');
newRow.appendChild(priorityCell);
for (var i = 0; i < 4; i++) {
var newCell = document.createElement('td');
newCell.contentEditable = 'true';
newRow.appendChild(newCell);
if (i === 3) {
newCell.addEventListener('input', onCellInput);
newCell.addEventListener('click', onCellClick);
}
}
var actionCell = document.createElement('td');
var upButton = createButton('fa-arrow-up', function() { moveRow(-1, this); });
actionCell.appendChild(upButton);
var downButton = createButton('fa-arrow-down', function() { moveRow(1, this); });
actionCell.appendChild(downButton);
var deleteRowButton = createButton('fa-times text-secondary', toggleStrike);
actionCell.appendChild(deleteRowButton);
var deleteButton = createButton('fa-trash-alt text-danger', openDeleteModal);
actionCell.appendChild(deleteButton);
var dragDropButton = createButton('fa-grip-vertical', null);
dragDropButton.setAttribute('draggable', true);
actionCell.appendChild(dragDropButton);
newRow.appendChild(actionCell);
tableBody.appendChild(newRow);
updatePriorities();
}
function createButton(iconClass, onClick) {
var button = document.createElement('button');
button.className = 'btn btn-light';
button.style.marginRight = '4px';
button.onclick = onClick;
var icon = document.createElement('i');
icon.className = 'fas ' + iconClass;
button.appendChild(icon);
return button;
}
function onCellClick(event) {
var cell = event.target;
if (event.ctrlKey) {
event.preventDefault();
var link = cell.querySelector('a');
console.log(link);
if (link) {
window.open(link.href, '_blank');
}
}
}
function setCellsEditable(editable) {
document.querySelectorAll('td[contenteditable]').forEach(function(cell) {
cell.contentEditable = editable.toString();
});
}
window.addEventListener('keydown', function(event) {
if (event.key === 'Control') {
setCellsEditable(false);
}
});
window.addEventListener('keyup', function(event) {
if (event.key === 'Control') {
setCellsEditable(true);
}
});
function onCellInput(event) {
var cell = event.target;
var row = cell.parentElement;
var table = row.parentElement.parentElement;
var columnIndex = Array.from(row.children).indexOf(cell);
if (table.rows[0].cells[columnIndex].textContent === 'Ticket-ID / Epic') {
var match = cell.textContent.match(/https:\/\/[^\s]+\/browse\/([A-Z0-9-]+)/);
if (match) {
var ticketId = match[1];
cell.innerHTML = '<a href="' + match[0] + '" target="_blank">' + ticketId + '</a>';
}
}
}
function saveTable() {
var tableBody = document.getElementById('tableBody');
var rows = Array.from(tableBody.rows);
var tableData = rows.map(row => {
var cells = Array.from(row.cells);
return cells.slice(0, -1).map(cell => cell.innerHTML);
});
localStorage.setItem('tableData', JSON.stringify(tableData));
}
function loadTable() {
var tableData = JSON.parse(localStorage.getItem('tableData') || '[]');
var tableBody = document.getElementById('tableBody');
tableBody.innerHTML = '';
tableData.forEach(rowData => {
var row = document.createElement('tr');
rowData.forEach((cellData, i) => {
var cell = document.createElement('td');
cell.innerHTML = cellData;
cell.contentEditable = 'true';
if (i === 3) {
cell.addEventListener('input', onCellInput);
cell.addEventListener('click', onCellClick);
}
row.appendChild(cell);
});
var actionCell = document.createElement('td');
actionCell.appendChild(createButton('fa-arrow-up', function() { moveRow(-1, this); }));
actionCell.appendChild(createButton('fa-arrow-down', function() { moveRow(1, this); }));
actionCell.appendChild(createButton('fa-times text-secondary', toggleStrike)); // Beispiel für das Öffnen eines Modal
actionCell.appendChild(createButton('fa-trash-alt text-danger', openDeleteModal));
var dragDropButton = createButton('fa-grip-vertical', null);
dragDropButton.setAttribute('draggable', true);
actionCell.appendChild(dragDropButton);
row.appendChild(actionCell);
tableBody.appendChild(row);
});
updatePriorities();
}
window.addEventListener('DOMContentLoaded', (event) => {
loadTable();
});
document.getElementById('tableBody').addEventListener('input', (event) => {
if (event.target.tagName === 'TD') {
saveTable();
}
});
function addRowAbove() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
if(targetRow) {
let newRow = createNewRow();
targetRow.before(newRow);
updatePriorities();
saveTable();
}
}
function addRowBelow() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
if(targetRow) {
let newRow = createNewRow();
targetRow.after(newRow);
updatePriorities();
saveTable();
}
}
function addColumnLeft() {
let contextMenu = document.getElementById('contextMenu');
let targetCell = contextMenu.targetCell;
if (!targetCell || targetCell.cellIndex === 0) return;
let table = document.querySelector('table');
Array.from(table.rows).forEach(row => {
let newCell;
if (row.sectionRowIndex === 0) {
newCell = document.createElement('th');
} else {
newCell = document.createElement('td');
newCell.contentEditable = 'true';
}
row.insertBefore(newCell, row.cells[targetCell.cellIndex]);
});
}
function addColumnRight() {
let contextMenu = document.getElementById('contextMenu');
let targetCell = contextMenu.targetCell;
let table = document.querySelector('table');
if (!targetCell || targetCell.cellIndex === table.rows[0].cells.length - 2) return;
Array.from(table.rows).forEach(row => {
let newCell;
if (row.sectionRowIndex === 0) {
newCell = document.createElement('th');
} else {
newCell = document.createElement('td');
newCell.contentEditable = 'true';
}
row.insertBefore(newCell, row.cells[targetCell.cellIndex + 1]);
});
}
function deleteColumn() {
let contextMenu = document.getElementById('contextMenu');
let targetCell = contextMenu.targetCell;
let table = document.querySelector('table');
if (confirm('Möchten Sie diese Spalte wirklich löschen?')) {
let table = document.querySelector('table');
Array.from(table.rows).forEach(row => {
row.deleteCell(targetCell.cellIndex);
});
}
}
function deleteRow() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
openDeleteModal(targetRow);
}
function toggleStrikeRow() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
toggleStrike(targetRow);
}
function moveRowToTop() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
if(targetRow) {
let parent = targetRow.parentElement;
parent.prepend(targetRow);
updatePriorities();
saveTable();
}
}
function moveRowToBottom() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
if(targetRow) {
let parent = targetRow.parentElement;
parent.append(targetRow);
updatePriorities();
saveTable();
}
}
function setOnHold() {
let contextMenu = document.getElementById('contextMenu');
let targetRow = contextMenu.targetRow;
if(targetRow) {
let priorityCell = targetRow.cells[0];
let icon = priorityCell.querySelector('i');
let onHoldMenuItem = contextMenu.querySelector('[onclick="setOnHold()"]');
let onHoldMenuIcon = onHoldMenuItem.querySelector('i');
if(icon.classList.contains('fa-pause')) {
let previousClass = priorityCell.dataset.previousClass || 'fa-arrow-right text-primary';
icon.className = 'fas ' + previousClass;
onHoldMenuItem.textContent = ' On Hold setzen';
onHoldMenuIcon.className = 'fas fa-pause';
onHoldMenuItem.prepend(onHoldMenuIcon);
} else {
priorityCell.dataset.previousClass = icon.className.split(' ').slice(1).join(' ');
icon.className = 'fas fa-pause text-secondary';
onHoldMenuItem.textContent = ' Fortsetzen';
onHoldMenuIcon.className = 'fas fa-play';
onHoldMenuItem.prepend(onHoldMenuIcon);
}
}
}
function createNewRow() {
let newRow = document.createElement('tr');
let priorityCell = document.createElement('td');
newRow.appendChild(priorityCell);
for (let i = 0; i < 4; i++) {
let newCell = document.createElement('td');
newCell.contentEditable = 'true';
newRow.appendChild(newCell);
if (i === 3) {
newCell.addEventListener('input', onCellInput);
newCell.addEventListener('click', onCellClick);
}
}
let actionCell = document.createElement('td');
actionCell.appendChild(createButton('fa-arrow-up', function() { moveRow(-1, this); }));
actionCell.appendChild(createButton('fa-arrow-down', function() { moveRow(1, this); }));
actionCell.appendChild(createButton('fa-times text-secondary', toggleStrike));
actionCell.appendChild(createButton('fa-trash-alt text-danger', openDeleteModal));
let dragDropButton = createButton('fa-grip-vertical', null);
dragDropButton.setAttribute('draggable', true);
actionCell.appendChild(dragDropButton);
newRow.appendChild(actionCell);
return newRow;
}
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
let target = e.target;
let contextMenu = document.getElementById('contextMenu');
let rowMenu = document.getElementById('rowMenu');
let columnMenu = document.getElementById('columnMenu');
let onHoldMenuItem = contextMenu.querySelector('[onclick="setOnHold()"]');
let onHoldMenuIcon = onHoldMenuItem.querySelector('i');
let targetCell = target.closest('td') || target.closest('th');
contextMenu.targetCell = targetCell;
contextMenu.style.top = e.pageY + 'px';
contextMenu.style.left = e.pageX + 'px';
if (target.closest('td')) {
rowMenu.style.display = 'block';
columnMenu.style.display = 'none';
let targetRow = target.closest('tr');
contextMenu.targetRow = targetRow;
let priorityCell = targetRow.cells[0];
let icon = priorityCell.querySelector('i');
if(icon.classList.contains('fa-pause')) {
onHoldMenuItem.textContent = ' Fortsetzen';
onHoldMenuIcon.className = 'fas fa-play';
} else {
onHoldMenuItem.textContent = ' On Hold setzen';
onHoldMenuIcon.className = 'fas fa-pause';
}
onHoldMenuItem.prepend(onHoldMenuIcon);
} else if (target.closest('th')) {
rowMenu.style.display = 'none';
columnMenu.style.display = 'block';
}
contextMenu.style.display = 'block';
});
document.getElementById('contextMenu').addEventListener('mouseleave', function() {
this.style.display = 'none';
});
document.addEventListener('mouseover', function(e) {
let target = e.target;
if (target.closest('.context-menu')) {
let row = contextMenu.targetRow;
let cell = contextMenu.targetCell;
if (row) row.style.backgroundColor = 'rgba(255,255,255,0.3)';
if (cell) cell.style.backgroundColor = 'rgba(255,255,255,0.5)';
}
});
document.addEventListener('mouseout', function(e) {
let target = e.target;
if (target.closest('.context-menu')) {
let row = contextMenu.targetRow;
let cell = contextMenu.targetCell;
if (row) row.style.backgroundColor = '';
if (cell) cell.style.backgroundColor = '';
}
});
document.getElementById('contextMenu').addEventListener('mouseleave', function() {
this.style.display = 'none';
});
document.addEventListener("dragstart", function(event) {
if(event.target.className.includes('fa-grip-vertical')) {
dragged = event.target.closest('tr');
event.dataTransfer.setData('text/plain', null);
}
}, false);
document.addEventListener("dragover", function(event) {
event.preventDefault();
}, false);
document.addEventListener("drop", function(event) {
event.preventDefault();
if (event.target.tagName === "TD" && dragged) {
let targetRow = event.target.closest('tr');
let parent = targetRow.parentNode;
parent.insertBefore(dragged, targetRow.nextSibling);
updatePriorities();
}
}, false);
document.getElementById('tableBody').addEventListener('DOMNodeInserted', saveTable);
document.getElementById('tableBody').addEventListener('DOMNodeRemoved', saveTable);
document.querySelectorAll('td[contenteditable="true"]').forEach(function(cell) {
cell.addEventListener('input', onCellInput);
cell.addEventListener('click', onCellClick);
});