dashboard: fix small issues and introduce dataChanged method

This commit is contained in:
Stephan de Wit 2024-07-03 13:52:19 +02:00
parent cf6359c8a3
commit 76ce0f431b
4 changed files with 23 additions and 4 deletions

View File

@ -454,8 +454,6 @@ class WidgetManager {
`);
});
}
this._updateGrid();
}
// Executed for each widget; starts the widget-specific tick routine.
@ -500,8 +498,10 @@ class WidgetManager {
// start the widget-specific tick routine
let onWidgetTick = widget.onWidgetTick.bind(widget);
await onWidgetTick();
this._updateGrid(this.widgetHTMLElements[widget.id]);
const interval = setInterval(async () => {
await onWidgetTick();
this._updateGrid();
}, widget.tickTimeout);
// store the reference to the tick routine so we can clear it later on widget removal
this.widgetTickRoutines[widget.id] = interval;

View File

@ -34,6 +34,7 @@ export default class BaseWidget {
this.eventSource = null;
this.eventSourceUrl = null;
this.eventSourceOnData = null;
this.cachedData = {};
}
/* Public functions */
@ -97,6 +98,20 @@ export default class BaseWidget {
/* Utility/protected functions */
dataChanged(id, data) {
if (id in this.cachedData) {
if (JSON.stringify(this.cachedData[id]) !== JSON.stringify(data)) {
this.cachedData[id] = data;
return true;
}
} else {
this.cachedData[id] = data;
return true;
}
return false;
}
setWidgetConfig(config) {
this.config['widget'] = config;
}

View File

@ -51,6 +51,10 @@ export default class Interfaces extends BaseTableWidget {
async onWidgetTick() {
await ajaxGet('/api/interfaces/overview/interfacesInfo', {}, (data, status) => {
if (!this.dataChanged('interfaces', data)) {
return;
}
let rows = [];
data.rows.map((intf_data) => {
if (!intf_data.hasOwnProperty('config') || intf_data.enabled == false) {

View File

@ -16,7 +16,7 @@
</endpoints>
<translations>
<title>System Information</title>
<name>name</name>
<name>Name</name>
<versions>Versions</versions>
<updates>Updates</updates>
<datetime>Current date/time</datetime>
@ -153,7 +153,7 @@
</translations>
</swap>
<carp>
<filename>CARP Status</filename>
<filename>Carp.js</filename>
<endpoints>
<endpoint>/api/diagnostics/interface/get_vip_status</endpoint>
</endpoints>