Dashboard pagination

Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
Romein van Buren 2022-07-11 16:26:49 +02:00
parent f3a0a4dc5b
commit 87b583e0dd
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
2 changed files with 47 additions and 56 deletions

View File

@ -1,17 +1,39 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import TileRawValue from './tile-rawvalue.svelte'; import TileRawValue from './tile-rawvalue.svelte';
import Tiles from './tiles.svelte';
import Settings from './settings.svelte'; import Settings from './settings.svelte';
const size = 3 * 4;
let lastUpdated = new Date(); let lastUpdated = new Date();
let lastUpdatedFormatted = ''; let lastUpdatedFormatted = '';
let services = {}; let services = [];
let servicesUp = {}; let pageNum = -1;
let servicesDown = {};
let servicesUnknown = {}; function tileProps(service) {
let loading = true; let props = {
let lock = false; title: service.name.en,
subtitle: service.cluster,
date: service.lastBeat?.date ? new Date(service.lastBeat.date) : undefined,
};
if (!service.lastBeat?.date) {
props.value = 'no data';
props.color = 'grey';
props.sort = 20;
}
if (service.lastBeat.down) {
props.value = 'down';
props.color = 'red';
props.sort = 0;
}
else {
props.value = 'up';
props.color = 'green';
props.sort = 10;
}
return props;
}
onMount(() => { onMount(() => {
const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket'); const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket');
@ -28,34 +50,24 @@
break; break;
case 'data': case 'data':
while (lock) {} const tempServices = [];
const d = data.data;
const ids = Object.keys(d);
ids.sort((a, b) => tileProps(d[a]).sort - tileProps(d[b]).sort);
services = data.data; if ((ids.length > size) || (pageNum === -1)) {
const ids = Object.keys(services); pageNum++;
for (const id of ids) {
const service = services[id];
if (!service.lastBeat || !service.lastBeat.date) {
servicesUnknown = {
...servicesUnknown,
[id]: service,
};
}
else if (service.lastBeat.down) {
servicesDown = {
...servicesDown,
[id]: service,
};
}
else {
servicesUp = {
...servicesUp,
[id]: service,
};
}
} }
loading = false; 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;
break; break;
default: default:
@ -72,13 +84,9 @@
<div class="tiles"> <div class="tiles">
<TileRawValue title="Last updated" value={lastUpdatedFormatted} /> <TileRawValue title="Last updated" value={lastUpdatedFormatted} />
{#if !loading} {#each services as service}
<Tiles services={servicesDown} color="red" value="down" /> <TileRawValue {...tileProps(service)} />
<Tiles services={servicesUp} color="green" value="up" /> {/each}
<Tiles services={servicesUnknown} color="grey" value="no data" />
{:else}
loading
{/if}
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,17 +0,0 @@
<script>
import TileRawValue from './tile-rawvalue.svelte';
export let services;
export let color;
export let value;
</script>
{#each Object.entries(services) as [ id, service ] (id)}
<TileRawValue
title={service.name.en}
subtitle={service.cluster}
date={service.lastBeat.date ? new Date(service.lastBeat.date) : false}
{value}
{color}
/>
{/each}