mirror of
https://github.com/smartyellow/status.git
synced 2025-01-18 21:47:58 +00:00
Dashboard works properly now
Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
parent
25cb7652e1
commit
1595bb9466
@ -6,13 +6,10 @@
|
|||||||
//import { shuffle } from './lib';
|
//import { shuffle } from './lib';
|
||||||
|
|
||||||
//const [ send, receive ] = shuffle;
|
//const [ send, receive ] = shuffle;
|
||||||
const size = 3 * 4;
|
const size = 3 * 4 - 1;
|
||||||
let lastUpdated = new Date();
|
|
||||||
let lastUpdatedFormatted = '';
|
|
||||||
let servicesUp = [];
|
|
||||||
let servicesDown = [];
|
|
||||||
let servicesUnknown = [];
|
|
||||||
let pageNum = -1;
|
let pageNum = -1;
|
||||||
|
let tiles = [];
|
||||||
|
let time = '';
|
||||||
|
|
||||||
function tileProps(service) {
|
function tileProps(service) {
|
||||||
let props = {
|
let props = {
|
||||||
@ -46,22 +43,39 @@
|
|||||||
ws.onmessage = async evt => {
|
ws.onmessage = async evt => {
|
||||||
const data = JSON.parse(evt.data || '""');
|
const data = JSON.parse(evt.data || '""');
|
||||||
|
|
||||||
switch (data.cmd) {
|
if (data.cmd === 'data') {
|
||||||
case 'time':
|
let servicesTemp = [];
|
||||||
lastUpdated = new Date(data.time);
|
const { servicesUp, servicesDown, servicesUnknown, total } = data;
|
||||||
lastUpdatedFormatted = lastUpdated.toLocaleTimeString('en-GB', {
|
const upOrUnknown = [ ...servicesUp, ...servicesUnknown ];
|
||||||
timeStyle: 'short',
|
servicesTemp = servicesDown.slice(0, size);
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'data':
|
if (pageNum === -1 || total >= size) {
|
||||||
({ servicesUp, servicesDown, servicesUnknown } = data);
|
pageNum++;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
if (pageNum > Math.ceil(upOrUnknown.length / size)) {
|
||||||
break;
|
pageNum = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const placesLeft = size - servicesTemp.length;
|
||||||
|
const offset = placesLeft * pageNum;
|
||||||
|
if (placesLeft > 0) {
|
||||||
|
servicesTemp.push(
|
||||||
|
...upOrUnknown.slice(offset, placesLeft + offset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles = servicesTemp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clockInterval = setInterval(() => {
|
||||||
|
time = new Date().toLocaleTimeString('en-GB', {
|
||||||
|
timeStyle: 'medium',
|
||||||
|
});
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
return () => clearInterval(clockInterval);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -70,17 +84,17 @@
|
|||||||
<div class="center">
|
<div class="center">
|
||||||
<div class="ratio">
|
<div class="ratio">
|
||||||
<div class="tiles">
|
<div class="tiles">
|
||||||
<TileRawValue title="Last updated" value={lastUpdatedFormatted} />
|
<TileRawValue value={time} center weight={200} />
|
||||||
|
|
||||||
{#each servicesDown as service (service.id)}
|
{#each tiles as tile (tile.id)}
|
||||||
<TileRawValue {...tileProps(service)} />
|
<TileRawValue {...tileProps(tile)} />
|
||||||
{/each}
|
{/each}
|
||||||
{#each servicesUp as service (service.id)}
|
<!--{#each servicesUp as service (service.id)}
|
||||||
<TileRawValue {...tileProps(service)} />
|
<TileRawValue {...tileProps(service)} />
|
||||||
{/each}
|
{/each}
|
||||||
{#each servicesUnknown as service (service.id)}
|
{#each servicesUnknown as service (service.id)}
|
||||||
<TileRawValue {...tileProps(service)} />
|
<TileRawValue {...tileProps(service)} />
|
||||||
{/each}
|
{/each}-->
|
||||||
|
|
||||||
<!--{#each services as service (service.id)}
|
<!--{#each services as service (service.id)}
|
||||||
<div
|
<div
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
export let color;
|
export let color;
|
||||||
export let value;
|
export let value;
|
||||||
export let date;
|
export let date;
|
||||||
|
export let center = false;
|
||||||
|
export let weight = 600;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Tile {title} {subtitle} {color} {date}>
|
<Tile {title} {subtitle} {color} {date}>
|
||||||
<div class="value {color}">
|
<div class="value {color}" class:center style:font-weight={weight}>
|
||||||
{value}
|
{value}
|
||||||
</div>
|
</div>
|
||||||
</Tile>
|
</Tile>
|
||||||
@ -19,4 +21,11 @@
|
|||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.value.center {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
background-color: var(--tile-bg);
|
background-color: var(--tile-bg);
|
||||||
border-radius: var(--radius);
|
border-radius: var(--radius);
|
||||||
border: 2px solid var(--tile-bg);
|
border: 2px solid var(--tile-bg);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile.red {
|
.tile.red {
|
||||||
@ -75,4 +77,8 @@
|
|||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -16,21 +16,6 @@ async function createDashboardSocket(server) {
|
|||||||
uws = server.ws({
|
uws = server.ws({
|
||||||
route: '/statusdashboard/socket',
|
route: '/statusdashboard/socket',
|
||||||
onOpen: async ws => {
|
onOpen: async ws => {
|
||||||
function sendTime() {
|
|
||||||
try {
|
|
||||||
ws.send(JSON.stringify({
|
|
||||||
cmd: 'time',
|
|
||||||
time: new Date().getTime(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sendTime();
|
|
||||||
setInterval(sendTime, 5000);
|
|
||||||
|
|
||||||
async function sendStatuses() {
|
async function sendStatuses() {
|
||||||
const services = await server.storage
|
const services = await server.storage
|
||||||
.store('smartyellow/webservice')
|
.store('smartyellow/webservice')
|
||||||
@ -62,12 +47,19 @@ async function createDashboardSocket(server) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const total = [
|
||||||
|
...servicesUp,
|
||||||
|
...servicesDown,
|
||||||
|
...servicesUnknown,
|
||||||
|
].length;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
cmd: 'data',
|
cmd: 'data',
|
||||||
servicesUp,
|
servicesUp,
|
||||||
servicesDown,
|
servicesDown,
|
||||||
servicesUnknown,
|
servicesUnknown,
|
||||||
|
total,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user