Use proper Object methods

Signed-off-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
XhmikosR
2025-04-02 18:37:28 +03:00
parent 04760b55c8
commit ba3b76421b
5 changed files with 23 additions and 33 deletions

View File

@@ -104,14 +104,14 @@ function updateQueryTypesPie() {
let sum = 0;
// Compute total number of queries
for (const item of Object.keys(data.types)) {
sum += data.types[item];
for (const value of Object.values(data.types)) {
sum += value;
}
// Fill chart with data (only include query types which appeared recently)
for (const item of Object.keys(data.types)) {
if (data.types[item] > 0) {
v.push((100 * data.types[item]) / sum);
for (const [item, value] of Object.entries(data.types)) {
if (value > 0) {
v.push((100 * value) / sum);
c.push(THEME_COLORS[i % THEME_COLORS.length]);
k.push(item);
}
@@ -149,9 +149,9 @@ function updateClientsOverTime() {
let numClients = 0;
const labels = [];
const clients = {};
for (const ip of Object.keys(data.clients)) {
for (const [ip, clientData] of Object.entries(data.clients)) {
clients[ip] = numClients++;
labels.push(data.clients[ip].name !== null ? data.clients[ip].name : ip);
labels.push(clientData.name !== null ? clientData.name : ip);
}
// Remove possibly already existing data
@@ -176,15 +176,11 @@ function updateClientsOverTime() {
// Add data for each dataset that is available
// We need to iterate over all time slots and fill in the data for each client
for (const item of Object.keys(data.history)) {
for (const client of Object.keys(clients)) {
if (data.history[item].data[client] === undefined) {
// If there is no data for this client in this timeslot, we push 0
clientsChart.data.datasets[clients[client]].data.push(0);
} else {
// Otherwise, we push the data
clientsChart.data.datasets[clients[client]].data.push(data.history[item].data[client]);
}
for (const item of Object.values(data.history)) {
for (const [client, index] of Object.entries(clients)) {
const clientData = item.data[client];
// If there is no data for this client in this timeslot, we push 0, otherwise the data
clientsChart.data.datasets[index].data.push(clientData === undefined ? 0 : clientData);
}
}

View File

@@ -265,8 +265,7 @@ function valueDetails(key, value) {
function generateRow(topic, key, value) {
// If the value is an object, we need to recurse
if (!("description" in value)) {
for (const subkey of Object.keys(value)) {
const subvalue = value[subkey];
for (const [subkey, subvalue] of Object.entries(value)) {
generateRow(topic, key + "." + subkey, subvalue);
}
@@ -304,9 +303,7 @@ function createDynamicConfigTabs() {
})
.done(data => {
// Create the tabs for the advanced dynamic config topics
for (const n of Object.keys(data.topics)) {
const topic = data.topics[n];
for (const topic of Object.values(data.topics)) {
$("#advanced-settings-tabs").append(`
<div id="advanced-content-${topic.name}" role="tabpanel" class="tab-pane fade">
<h3 class="page-header">${topic.description} (<code>${topic.name}</code>)</h3>
@@ -325,8 +322,7 @@ function createDynamicConfigTabs() {
}
// Dynamically fill the tabs with config topics
for (const topic of Object.keys(data.config)) {
const value = data.config[topic];
for (const [topic, value] of Object.entries(data.config)) {
generateRow(topic, topic, value);
}

View File

@@ -60,16 +60,16 @@ function updateCachePie(data) {
data.empty.valid = cacheSize - cacheEntries;
// Fill chart with data
for (const item of Object.keys(data)) {
if (data[item].valid > 0) {
v.push((100 * data[item].valid) / cacheSize);
for (const [item, value] of Object.entries(data)) {
if (value.valid > 0) {
v.push((100 * value.valid) / cacheSize);
c.push(item !== "empty" ? THEME_COLORS[i++ % THEME_COLORS.length] : "#80808040");
k.push(item);
}
if (data[item].stale > 0) {
if (value.stale > 0) {
// There are no stale empty entries
v.push((100 * data[item].stale) / cacheSize);
v.push((100 * value.stale) / cacheSize);
c.push(THEME_COLORS[i++ % THEME_COLORS.length]);
k.push(item + " (stale)");
}

View File

@@ -28,8 +28,7 @@ $(() => {
function setConfigValues(topic, key, value) {
// If the value is an object, we need to recurse
if (!("description" in value)) {
for (const subkey of Object.keys(value)) {
const subvalue = value[subkey];
for (const [subkey, subvalue] of Object.entries(value)) {
// If the key is empty, we are at the top level
const newKey = key === "" ? subkey : key + "." + subkey;
setConfigValues(topic, newKey, subvalue);

View File

@@ -294,9 +294,8 @@ function stateLoadCallback(itemName) {
data = JSON.parse(data);
// Clear possible filtering settings
// TODO Maybe Object.values() is meant to be used here?
for (const [index, _value] of data.columns.entries()) {
data.columns[index].search.search = "";
for (const column of Object.values(data.columns)) {
column.search.search = "";
}
// Always start on the first page to show most recent queries