-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.js
More file actions
47 lines (47 loc) · 1.24 KB
/
ui.js
File metadata and controls
47 lines (47 loc) · 1.24 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
export const UiHelpers = {
setVal: (id, value) => {
document.getElementById(id).innerHTML = value;
},
setLoading: (enabled) => {
document.getElementById("StartTests").disabled = enabled;
document.getElementById("loading").style.display = enabled
? "block"
: "none";
},
clearUI: () => {
UiHelpers.resetTable();
},
// getPayloadSize: () => +document.getElementById("payload").value,
/**
* @param s { { [key: string]: {} } }
* @param id { string }
*/
outputTable: (s, id) => {
const cols = [];
for (const k in s) {
for (const c in s[k]) {
if (cols.indexOf(c) === -1) cols.push(c);
}
}
let html =
"<thead><tr><th></th>" +
cols.map((c) => "<th>" + c + "</th>").join("") +
"</tr></thead><tbody>";
for (const l in s) {
html +=
"<tr><th>" +
l +
"</th>" +
cols.map((c) => "<td>" + (s[l][c] || "") + "</td>").join("") +
"</tr>";
}
html += "</tbody>";
const table = document.createElement("table");
table.id = `results-table-${id}`;
table.innerHTML = html;
document.body.appendChild(table);
},
resetTable: () => {
document.querySelectorAll("table")?.forEach((t) => t.remove());
},
};