Skip to content

Commit 8b717d2

Browse files
committed
Added styling to cloud encryption key table
1 parent 66a74c8 commit 8b717d2

File tree

1 file changed

+77
-5
lines changed

1 file changed

+77
-5
lines changed

webroot/adm/cloud-encryption-key.html

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<script src="/js/main.js"></script>
55
<script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script>
66
<link href="https://unpkg.com/gridjs/dist/theme/mermaid.min.css" rel="stylesheet" />
7+
<style>
8+
.active { color: darkgreen; }
9+
.inactive { color: darkred; }
10+
</style>
711
</head>
812
<body>
913
<h1>UID2 Env - Cloud Encryption Key Management</h1>
@@ -32,10 +36,51 @@ <h3>Output</h3>
3236

3337
<script language="JavaScript">
3438
const grid = new gridjs.Grid({
35-
columns: ["Key ID", "Site ID", "Activates", "Created"],
39+
columns: [
40+
{
41+
name: "Key ID",
42+
formatter: (cell, row) => {
43+
console.log(row.cells);
44+
return gridjs.html(`<span class="${row.cells[4].data}">${cell}</span>`)
45+
}
46+
},
47+
{
48+
name: "Site ID",
49+
formatter: (cell, row) => {
50+
return gridjs.html(`<span class="${row.cells[4].data}">${cell}</span>`)
51+
}
52+
},
53+
{
54+
name: "Activates",
55+
formatter: (cell, row) => {
56+
return gridjs.html(`<span class="${row.cells[4].data}">${formatDate(cell)}</span>`)
57+
}
58+
},
59+
{
60+
name: "Created",
61+
formatter: (cell, row) => {
62+
return gridjs.html(`<span class="${row.cells[4].data}">${formatDate(cell)}</span>`)
63+
}
64+
},
65+
{
66+
name: "Style",
67+
hidden: true
68+
}
69+
],
3670
data: [],
3771
sort: true,
38-
search: true
72+
search: {
73+
selector: (cell, rowIndex, cellIndex) => {
74+
if (cellIndex === 0 || cellIndex === 1) {
75+
return cell;
76+
}
77+
}
78+
},
79+
language: {
80+
search: {
81+
placeholder: "Search by Key ID or Site ID..."
82+
}
83+
}
3984
})
4085
.render(document.getElementById("output-table"));
4186

@@ -54,15 +99,42 @@ <h3>Output</h3>
5499
}
55100

56101
const updateGrid = (grid, data) => {
102+
const now = new Date();
103+
104+
const groupedData = data.cloudEncryptionKeys.reduce((acc, entry) => {
105+
if (!acc[entry.siteId]) {
106+
acc[entry.siteId] = [];
107+
}
108+
acc[entry.siteId].push(entry);
109+
return acc;
110+
}, {});
111+
112+
const gridData = [];
113+
for (const siteId in groupedData) {
114+
const entries = groupedData[siteId];
115+
const latestEntry = entries.reduce((latest, entry) => new Date(entry.activates) > new Date(latest.activates) ? entry : latest);
116+
117+
entries.forEach((entry) => {
118+
let style = "";
119+
if (entry === latestEntry) {
120+
style = "active";
121+
} else {
122+
style = "inactive";
123+
}
124+
125+
gridData.push([ entry.id, entry.siteId, entry.activates, entry.created, style ]);
126+
});
127+
}
128+
57129
grid
58-
.updateConfig({ data: data.cloudEncryptionKeys.map((entry) => [entry.id, entry.siteId, formatDate(entry.activates), formatDate(entry.created)]) })
59-
.forceRender(document.getElementById("output-table"));
130+
.updateConfig({ data: gridData })
131+
.forceRender();
60132
}
61133

62134
const clearGrid = (grid) => {
63135
grid
64136
.updateConfig({ data: [] })
65-
.forceRender(document.getElementById("output-table"));
137+
.forceRender();
66138
}
67139

68140
$(document).ready(function () {

0 commit comments

Comments
 (0)