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 08:30:37 +00:00
|
|
|
import { flip } from 'svelte/animate';
|
2022-07-12 10:28:53 +00:00
|
|
|
import { settings, shuffle, ringBell } from './lib';
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-12 08:30:37 +00:00
|
|
|
const [ send, receive ] = shuffle;
|
2022-07-12 10:28:53 +00:00
|
|
|
const size = ($settings.cols || 4) * ($settings.rows || 3) - 1;
|
2022-07-11 14:26:49 +00:00
|
|
|
let pageNum = -1;
|
2022-07-12 08:18:29 +00:00
|
|
|
let tiles = [];
|
|
|
|
let time = '';
|
2022-07-11 14:26:49 +00:00
|
|
|
|
|
|
|
function tileProps(service) {
|
|
|
|
let props = {
|
|
|
|
title: service.name.en,
|
|
|
|
subtitle: service.cluster,
|
|
|
|
date: service.lastBeat?.date ? new Date(service.lastBeat.date) : undefined,
|
2022-07-12 10:06:26 +00:00
|
|
|
since: service.checked ? new Date(service.checked) : undefined,
|
2022-07-11 14:26:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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 || '""');
|
|
|
|
|
2022-07-12 09:08:27 +00:00
|
|
|
switch (data.cmd) {
|
|
|
|
case 'data':
|
|
|
|
let servicesTemp = [];
|
|
|
|
const { servicesUp, servicesDown, servicesUnknown, total } = data;
|
|
|
|
const upOrUnknown = [ ...servicesUp, ...servicesUnknown ];
|
|
|
|
servicesTemp = servicesDown.slice(0, size);
|
2022-07-12 08:18:29 +00:00
|
|
|
|
2022-07-12 09:08:27 +00:00
|
|
|
if (pageNum === -1 || total >= size) {
|
|
|
|
pageNum++;
|
2022-07-12 08:18:29 +00:00
|
|
|
|
2022-07-12 09:08:27 +00:00
|
|
|
if (pageNum > Math.ceil(upOrUnknown.length / size)) {
|
|
|
|
pageNum = 0;
|
|
|
|
}
|
2022-07-12 08:18:29 +00:00
|
|
|
}
|
|
|
|
|
2022-07-12 09:08:27 +00:00
|
|
|
const placesLeft = size - servicesTemp.length;
|
|
|
|
const offset = placesLeft * pageNum;
|
|
|
|
if (placesLeft > 0) {
|
|
|
|
servicesTemp.push(
|
|
|
|
...upOrUnknown.slice(offset, placesLeft + offset)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
tiles = servicesTemp;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bell':
|
|
|
|
ringBell();
|
|
|
|
break;
|
2022-07-12 08:18:29 +00:00
|
|
|
|
2022-07-12 09:08:27 +00:00
|
|
|
default:
|
|
|
|
break;
|
2022-07-11 09:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-12 08:18:29 +00:00
|
|
|
|
|
|
|
const clockInterval = setInterval(() => {
|
|
|
|
time = new Date().toLocaleTimeString('en-GB', {
|
|
|
|
timeStyle: 'medium',
|
|
|
|
});
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
return () => clearInterval(clockInterval);
|
2022-07-11 09:20:44 +00:00
|
|
|
});
|
2022-07-08 12:50:15 +00:00
|
|
|
</script>
|
|
|
|
|
2022-07-11 10:07:05 +00:00
|
|
|
<Settings />
|
|
|
|
|
2022-07-12 10:28:53 +00:00
|
|
|
<div
|
|
|
|
class="center theme-{$settings.theme}"
|
|
|
|
style="--cols: {$settings.cols || 4}; --rows: {$settings.rows || 3};"
|
|
|
|
>
|
2022-07-08 15:17:17 +00:00
|
|
|
<div class="ratio">
|
2022-07-11 09:20:44 +00:00
|
|
|
<div class="tiles">
|
2022-07-12 08:18:29 +00:00
|
|
|
<TileRawValue value={time} center weight={200} />
|
2022-07-08 15:17:17 +00:00
|
|
|
|
2022-07-12 08:18:29 +00:00
|
|
|
{#each tiles as tile (tile.id)}
|
2022-07-12 07:40:49 +00:00
|
|
|
<div
|
2022-07-12 08:30:37 +00:00
|
|
|
in:receive={{ key: tile.id }}
|
|
|
|
out:send={{ key: tile.id }}
|
2022-07-12 07:40:49 +00:00
|
|
|
animate:flip
|
|
|
|
>
|
2022-07-12 08:30:37 +00:00
|
|
|
<TileRawValue {...tileProps(tile)} />
|
2022-07-12 07:40:49 +00:00
|
|
|
</div>
|
2022-07-12 08:30:37 +00:00
|
|
|
{/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;
|
2022-07-12 10:28:53 +00:00
|
|
|
background-color: var(--body-bg);
|
|
|
|
color: var(--body-fg);
|
2022-07-08 15:17:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.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-12 08:30:37 +00:00
|
|
|
margin: 1rem 0;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2022-07-08 12:50:15 +00:00
|
|
|
}
|
2022-07-11 09:20:44 +00:00
|
|
|
|
|
|
|
.tiles {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(var(--cols), 1fr);
|
|
|
|
grid-template-rows: repeat(var(--rows), 1fr);
|
|
|
|
gap: 1rem;
|
|
|
|
justify-items: stretch;
|
2022-07-12 08:30:37 +00:00
|
|
|
height: calc(100% - 2rem);
|
|
|
|
width: calc(100% - 2rem);
|
|
|
|
}
|
|
|
|
|
|
|
|
.tiles > * {
|
|
|
|
display: flex;
|
|
|
|
align-items: stretch;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tiles > * > :global(.tile) {
|
|
|
|
width: 100%;
|
2022-07-11 09:20:44 +00:00
|
|
|
}
|
2022-07-08 12:50:15 +00:00
|
|
|
</style>
|