Dashboard: show services that are down first.

Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
Romein van Buren 2022-07-11 11:32:28 +02:00
parent c561a00954
commit 8c2327ca68
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
4 changed files with 59 additions and 26 deletions

View File

@ -1,10 +1,13 @@
<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';
let lastUpdated = new Date(); let lastUpdated = new Date();
let lastUpdatedFormatted = ''; let lastUpdatedFormatted = '';
let services = {}; let services = {};
let servicesUp = {};
let servicesDown = {};
let loading = true; let loading = true;
$:console.log(services); $:console.log(services);
@ -25,6 +28,24 @@
case 'data': case 'data':
services = data.data; services = data.data;
const ids = Object.keys(services);
for (const id of ids) {
const service = services[id];
if (service.lastBeat && service.lastBeat.down) {
servicesDown = {
...servicesDown,
[id]: service,
};
}
else {
servicesUp = {
...servicesUp,
[id]: service,
};
}
}
loading = false; loading = false;
break; break;
@ -41,14 +62,8 @@
<TileRawValue title="Last updated" value={lastUpdatedFormatted} /> <TileRawValue title="Last updated" value={lastUpdatedFormatted} />
{#if !loading} {#if !loading}
{#each Object.entries(services) as [ id, service ] (id)} <Tiles services={servicesDown} />
{@const isDown = service.lastBeat.down} <Tiles services={servicesUp} />
<TileRawValue
title={service.name.en}
value={isDown ? 'down' : 'up'}
color={isDown ? 'red' : 'green'}
/>
{/each}
{:else} {:else}
loading loading
{/if} {/if}

View File

@ -7,7 +7,7 @@
export let value; export let value;
</script> </script>
<Tile {title} {subtitle}> <Tile {title} {subtitle} {color}>
<div class="value {color}"> <div class="value {color}">
{value} {value}
</div> </div>
@ -18,12 +18,4 @@
font-size: 3rem; font-size: 3rem;
font-weight: 600; font-weight: 600;
} }
.red {
color: var(--red);
}
.green {
color: var(--green);
}
</style> </style>

View File

@ -1,9 +1,10 @@
<script> <script>
export let title; export let title;
export let subtitle; export let subtitle;
export let color;
</script> </script>
<div class="tile"> <div class="tile {color}">
{#if title || subtitle} {#if title || subtitle}
<div class="desc"> <div class="desc">
{#if title} {#if title}
@ -20,22 +21,33 @@
</div> </div>
<style> <style>
.tile {
padding: 1rem;
background-color: var(--tile-bg);
border-radius: var(--radius);
border: 2px solid var(--tile-bg);
}
.tile.red {
background-color: var(--red);
border-color: var(--red);
color: #fff;
}
.tile.green {
border-color: var(--green);
}
.desc { .desc {
font-size: 1.3rem; font-size: 1.3rem;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.tile { .desc .title {
padding: 1rem;
background-color: var(--tile-bg);
border-radius: var(--radius);
}
.title {
font-weight: 200; font-weight: 200;
} }
.subtitle { .desc .subtitle {
font-weight: 100; font-weight: 100;
} }
</style> </style>

View File

@ -0,0 +1,14 @@
<script>
import TileRawValue from './tile-rawvalue.svelte';
export let services;
</script>
{#each Object.entries(services) as [ id, service ] (id)}
{@const isDown = service.lastBeat.down}
<TileRawValue
title={service.name.en}
value={isDown ? 'down' : 'up'}
color={isDown ? 'red' : 'green'}
/>
{/each}