mirror of
https://github.com/smartyellow/status.git
synced 2025-01-19 05:57:58 +00:00
105 lines
2.2 KiB
Svelte
105 lines
2.2 KiB
Svelte
<script>
|
|
import './app.css';
|
|
import { onMount } from 'svelte';
|
|
import TileRawValue from './tile-rawvalue.svelte';
|
|
import Tiles from './tiles.svelte';
|
|
import Settings from './settings.svelte';
|
|
|
|
let lastUpdated = new Date();
|
|
let lastUpdatedFormatted = '';
|
|
let services = {};
|
|
let servicesUp = {};
|
|
let servicesDown = {};
|
|
let loading = true;
|
|
|
|
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':
|
|
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;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<Settings />
|
|
|
|
<div class="center">
|
|
<div class="ratio">
|
|
<div class="tiles">
|
|
<TileRawValue title="Last updated" value={lastUpdatedFormatted} />
|
|
|
|
{#if !loading}
|
|
<Tiles services={servicesDown} />
|
|
<Tiles services={servicesUp} />
|
|
{:else}
|
|
loading
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.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;
|
|
}
|
|
|
|
.tiles {
|
|
margin: 1rem;
|
|
display: grid;
|
|
grid-template-columns: repeat(var(--cols), 1fr);
|
|
grid-template-rows: repeat(var(--rows), 1fr);
|
|
gap: 1rem;
|
|
justify-items: stretch;
|
|
}
|
|
</style>
|