From 25cb7652e10871663ea30cb843e304190eca5d1d Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Tue, 12 Jul 2022 09:40:49 +0200 Subject: [PATCH] Dashboard: server-side data processing Signed-off-by: Romein van Buren --- gui/dashboard/app.svelte | 46 +++++++++++++++++++---------------- gui/dashboard/lib.js | 38 +++++++++++++++++++++++++++++ gui/dashboard/settings.svelte | 2 +- gui/dashboard/stores.js | 18 -------------- lib/dashboard/socket.js | 37 +++++++++++++++++++++------- 5 files changed, 92 insertions(+), 49 deletions(-) create mode 100644 gui/dashboard/lib.js delete mode 100644 gui/dashboard/stores.js diff --git a/gui/dashboard/app.svelte b/gui/dashboard/app.svelte index 3db1db5..5befafa 100644 --- a/gui/dashboard/app.svelte +++ b/gui/dashboard/app.svelte @@ -2,11 +2,16 @@ import { onMount } from 'svelte'; import TileRawValue from './tile-rawvalue.svelte'; import Settings from './settings.svelte'; + //import { flip } from 'svelte/animate'; + //import { shuffle } from './lib'; + //const [ send, receive ] = shuffle; const size = 3 * 4; let lastUpdated = new Date(); let lastUpdatedFormatted = ''; - let services = []; + let servicesUp = []; + let servicesDown = []; + let servicesUnknown = []; let pageNum = -1; function tileProps(service) { @@ -21,7 +26,7 @@ props.color = 'grey'; props.sort = 20; } - if (service.lastBeat.down) { + else if (service.lastBeat.down) { props.value = 'down'; props.color = 'red'; props.sort = 0; @@ -50,24 +55,7 @@ break; case 'data': - const tempServices = []; - const d = data.data; - const ids = Object.keys(d); - ids.sort((a, b) => tileProps(d[a]).sort - tileProps(d[b]).sort); - - if ((ids.length > size) || (pageNum === -1)) { - pageNum++; - } - - if (pageNum * size >= ids.length) { - pageNum = 0; - } - - for (let i = pageNum * size; (i < ids.length) && (i < size + size * pageNum); i++) { - tempServices.push(d[ids[i]]); - } - - services = tempServices; + ({ servicesUp, servicesDown, servicesUnknown } = data); break; default: @@ -84,9 +72,25 @@
- {#each services as service} + {#each servicesDown as service (service.id)} {/each} + {#each servicesUp as service (service.id)} + + {/each} + {#each servicesUnknown as service (service.id)} + + {/each} + +
diff --git a/gui/dashboard/lib.js b/gui/dashboard/lib.js new file mode 100644 index 0000000..540e7b2 --- /dev/null +++ b/gui/dashboard/lib.js @@ -0,0 +1,38 @@ +import { get, writable } from 'svelte/store'; +//import { quintOut } from 'svelte/easing'; +//import { crossfade } from 'svelte/transition'; + +function createSettingsStore() { + const s = writable(0); + + function updateStorage(val) { + window.localStorage.setItem('statusdash', JSON.stringify(val)); + s.set(val); + } + + return { + subscribe: s.subscribe, + set: val => updateStorage(val), + update: val => updateStorage({ ...get(s), val }), + }; +} + +export const settings = createSettingsStore(); + +/* +export const shuffle = crossfade({ + fallback(node) { + const style = getComputedStyle(node); + const transform = style.transform === 'none' ? '' : style.transform; + + return { + duration: 600, + easing: quintOut, + css: t => ` + transform: ${transform} scale(${t}); + opacity: ${t} + `, + }; + }, +}); +*/ diff --git a/gui/dashboard/settings.svelte b/gui/dashboard/settings.svelte index 3cb06ff..5a8a2e8 100644 --- a/gui/dashboard/settings.svelte +++ b/gui/dashboard/settings.svelte @@ -1,6 +1,6 @@