2022-07-08 12:50:15 +00:00
|
|
|
<script>
|
2022-07-08 15:17:17 +00:00
|
|
|
import { onMount } from 'svelte';
|
2022-07-11 09:20:44 +00:00
|
|
|
import TileRawValue from './tile-rawvalue.svelte';
|
2022-07-11 10:07:05 +00:00
|
|
|
import Settings from './settings.svelte';
|
2022-07-12 07:40:49 +00:00
|
|
|
//import { flip } from 'svelte/animate';
|
|
|
|
//import { shuffle } from './lib';
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-12 07:40:49 +00:00
|
|
|
//const [ send, receive ] = shuffle;
|
2022-07-11 14:26:49 +00:00
|
|
|
const size = 3 * 4;
|
2022-07-11 09:20:44 +00:00
|
|
|
let lastUpdated = new Date();
|
|
|
|
let lastUpdatedFormatted = '';
|
2022-07-12 07:40:49 +00:00
|
|
|
let servicesUp = [];
|
|
|
|
let servicesDown = [];
|
|
|
|
let servicesUnknown = [];
|
2022-07-11 14:26:49 +00:00
|
|
|
let pageNum = -1;
|
|
|
|
|
|
|
|
function tileProps(service) {
|
|
|
|
let props = {
|
|
|
|
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;
|
|
|
|
}
|
2022-07-12 07:40:49 +00:00
|
|
|
else if (service.lastBeat.down) {
|
2022-07-11 14:26:49 +00:00
|
|
|
props.value = 'down';
|
|
|
|
props.color = 'red';
|
|
|
|
props.sort = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
props.value = 'up';
|
|
|
|
props.color = 'green';
|
|
|
|
props.sort = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return props;
|
|
|
|
}
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket');
|
|
|
|
|
|
|
|
ws.onmessage = async evt => {
|
|
|
|
const data = JSON.parse(evt.data || '""');
|
|
|
|
|
|
|
|
switch (data.cmd) {
|
|
|
|
case 'time':
|
|
|
|
lastUpdated = new Date(data.time);
|
|
|
|
lastUpdatedFormatted = lastUpdated.toLocaleTimeString('en-GB', {
|
|
|
|
timeStyle: 'short',
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'data':
|
2022-07-12 07:40:49 +00:00
|
|
|
({ servicesUp, servicesDown, servicesUnknown } = data);
|
2022-07-11 09:20:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-08 12:50:15 +00:00
|
|
|
</script>
|
|
|
|
|
2022-07-11 10:07:05 +00:00
|
|
|
<Settings />
|
|
|
|
|
2022-07-08 15:17:17 +00:00
|
|
|
<div class="center">
|
|
|
|
<div class="ratio">
|
2022-07-11 09:20:44 +00:00
|
|
|
<div class="tiles">
|
|
|
|
<TileRawValue title="Last updated" value={lastUpdatedFormatted} />
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-12 07:40:49 +00:00
|
|
|
{#each servicesDown as service (service.id)}
|
2022-07-11 14:26:49 +00:00
|
|
|
<TileRawValue {...tileProps(service)} />
|
|
|
|
{/each}
|
2022-07-12 07:40:49 +00:00
|
|
|
{#each servicesUp as service (service.id)}
|
|
|
|
<TileRawValue {...tileProps(service)} />
|
|
|
|
{/each}
|
|
|
|
{#each servicesUnknown as service (service.id)}
|
|
|
|
<TileRawValue {...tileProps(service)} />
|
|
|
|
{/each}
|
|
|
|
|
|
|
|
<!--{#each services as service (service.id)}
|
|
|
|
<div
|
|
|
|
in:receive={{ key: service.id }}
|
|
|
|
out:send={{ key: service.id }}
|
|
|
|
animate:flip
|
|
|
|
>
|
|
|
|
<TileRawValue {...tileProps(service)} />
|
|
|
|
</div>
|
|
|
|
{/each}-->
|
2022-07-11 09:20:44 +00:00
|
|
|
</div>
|
2022-07-08 15:17:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-08 12:50:15 +00:00
|
|
|
|
|
|
|
<style>
|
2022-07-08 15:17:17 +00:00
|
|
|
.center {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
width: 100vw;
|
|
|
|
height: 100vh;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ratio {
|
|
|
|
height: 56.25vw;
|
|
|
|
left: 50%;
|
|
|
|
max-height: 100vh;
|
|
|
|
max-width: 177.77778vh;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
transform: translate(-50%,-50%);
|
|
|
|
width: 100vw;
|
2022-07-08 12:50:15 +00:00
|
|
|
}
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
.tiles {
|
|
|
|
margin: 1rem;
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(var(--cols), 1fr);
|
|
|
|
grid-template-rows: repeat(var(--rows), 1fr);
|
|
|
|
gap: 1rem;
|
|
|
|
justify-items: stretch;
|
|
|
|
}
|
2022-07-08 12:50:15 +00:00
|
|
|
</style>
|