Path:
strictdoc/export/html/_static/source_coverage_screen.js
Lines:
75
Non-empty lines:
62
Non-empty lines covered with requirements:
62 / 62 (100.0%)
Functions:
0
Functions covered by requirements:
0 / 0 (0.0%)
1
// @relation(SDOC-SRS-35, scope=file)2
3
(function () {
4
document.addEventListener("DOMContentLoaded", () => {
5
const table = document.querySelector(".project_coverage");
6
const tbody = table.querySelector("tbody");
7
const originalRows = Array.from(tbody.rows);
8
let sortState = null;
9
10
const handlers = table.querySelectorAll(".project_coverage-sort_handler");
11
const colgroupCols = table.querySelectorAll("colgroup col");
12
13
handlers.forEach((handler) => {
14
handler.addEventListener("click", () => {
15
16
const dataId = handler.getAttribute("data-id");
17
// We expect:
18
// - Each .project_coverage-sort_handler has a unique data-id
19
// - Each <td> in sortable rows has matching data-id and data-value
20
// - <colgroup> contains <col data-id="..."> matching the same data-id
21
22
console.assert(dataId, "Missing data-id on sort handler.");
23
if (!dataId) return;
24
25
const isSameColumn = sortState && sortState.id === dataId;
26
const asc = isSameColumn ? !sortState.asc : false;
27
28
const rows = Array.from(tbody.rows);
29
const validRows = rows.filter(row =>
30
row.classList.contains("project_coverage-file") &&
31
row.querySelector(`td[data-id="${dataId}"]`)
32
);
33
if (validRows.length === 0) return;
34
35
validRows.sort((a, b) => {
36
const aCell = a.querySelector(`td[data-id="${dataId}"]`);
37
const bCell = b.querySelector(`td[data-id="${dataId}"]`);
38
const aVal = parseFloat(aCell?.dataset.value || '0');
39
const bVal = parseFloat(bCell?.dataset.value || '0');
40
return asc ? aVal - bVal : bVal - aVal;
41
});
42
43
tbody.innerHTML = "";
44
validRows.forEach(row => tbody.appendChild(row));
45
table.classList.add("sorted");
46
47
handlers.forEach(h => h.removeAttribute("sorted"));
48
handler.setAttribute("sorted", asc ? "asc" : "dsc");
49
50
sortState = { id: dataId, asc };
51
52
// Highlight active <col>
53
colgroupCols.forEach(col => col.classList.remove("sorted_col"));
54
const activeCol = table.querySelector(`colgroup col[data-id="${dataId}"]`);
55
if (activeCol) {
56
activeCol.classList.add("sorted_col");
57
} else {
58
console.warn(`No <col> found for data-id="${dataId}"`);
59
}
60
});
61
});
62
63
const resetter = table.querySelector(".project_coverage-sort_reset");
64
if (resetter) {
65
resetter.addEventListener("click", () => {
66
tbody.innerHTML = "";
67
originalRows.forEach(row => tbody.appendChild(row));
68
table.classList.remove("sorted");
69
handlers.forEach(h => h.removeAttribute("sorted"));
70
colgroupCols.forEach(col => col.classList.remove("sorted_col"));
71
sortState = null;
72
});
73
}
74
});75
})();