mirror of
https://github.com/smartyellow/status.git
synced 2025-01-18 21:47:58 +00:00
Print interval since last check on dashboard
Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
parent
0ff2202da0
commit
29af62bf80
@ -16,6 +16,7 @@
|
|||||||
title: service.name.en,
|
title: service.name.en,
|
||||||
subtitle: service.cluster,
|
subtitle: service.cluster,
|
||||||
date: service.lastBeat?.date ? new Date(service.lastBeat.date) : undefined,
|
date: service.lastBeat?.date ? new Date(service.lastBeat.date) : undefined,
|
||||||
|
since: service.checked ? new Date(service.checked) : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!service.lastBeat?.date) {
|
if (!service.lastBeat?.date) {
|
||||||
|
@ -41,3 +41,21 @@ export function ringBell() {
|
|||||||
const bell = new Audio('http://__SERVER__/statusdashboard/sound');
|
const bell = new Audio('http://__SERVER__/statusdashboard/sound');
|
||||||
bell.addEventListener('canplaythrough', () => bell.play());
|
bell.addEventListener('canplaythrough', () => bell.play());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDuration(ms) {
|
||||||
|
// modified from https://www.30secondsofcode.org/js/s/format-duration
|
||||||
|
|
||||||
|
if (ms < 0) {
|
||||||
|
ms = -ms;
|
||||||
|
}
|
||||||
|
const time = {
|
||||||
|
d: Math.floor(ms / 86400000),
|
||||||
|
h: Math.floor(ms / 3600000) % 24,
|
||||||
|
m: Math.floor(ms / 60000) % 60,
|
||||||
|
s: Math.floor(ms / 1000) % 60,
|
||||||
|
};
|
||||||
|
return Object.entries(time)
|
||||||
|
.filter(val => val[1] !== 0)
|
||||||
|
.map(([ key, val ]) => `${val} ${key}`)
|
||||||
|
.join(' ');
|
||||||
|
}
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
export let color;
|
export let color;
|
||||||
export let value;
|
export let value;
|
||||||
export let date;
|
export let date;
|
||||||
|
export let since;
|
||||||
export let center = false;
|
export let center = false;
|
||||||
export let weight = 600;
|
export let weight = 600;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Tile {title} {subtitle} {color} {date} {center}>
|
<Tile {title} {subtitle} {color} {date} {since} {center}>
|
||||||
<div class="value {color}" style:font-weight={weight} class:center>
|
<div class="value {color}" style:font-weight={weight} class:center>
|
||||||
{value}
|
{value}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,9 +1,32 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import { formatDuration } from './lib';
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
export let title;
|
export let title;
|
||||||
export let subtitle;
|
export let subtitle;
|
||||||
export let color;
|
export let color;
|
||||||
export let date;
|
export let date;
|
||||||
|
export let since;
|
||||||
export let center = false;
|
export let center = false;
|
||||||
|
|
||||||
|
let formattedDuration = '';
|
||||||
|
$: formattedDate = date ? date.toLocaleTimeString('en-GB', {
|
||||||
|
timeStyle: 'short',
|
||||||
|
}) : '';
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (since) {
|
||||||
|
function updateDuration() {
|
||||||
|
formattedDuration = formatDuration(
|
||||||
|
new Date().getTime() - since.getTime()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateDuration();
|
||||||
|
const interval = setInterval(updateDuration, 100);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="tile {color}">
|
<div class="tile {color}">
|
||||||
@ -19,10 +42,12 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if date}
|
{#if date || since}
|
||||||
<div class="time">{date.toLocaleTimeString('en-GB', {
|
<div class="time">
|
||||||
timeStyle: 'short',
|
{formattedDate}
|
||||||
})}</div>
|
{#if date && since}<br />{/if}
|
||||||
|
{formattedDuration}
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@ -79,6 +104,7 @@
|
|||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
font-size: 1.3vw;
|
font-size: 1.3vw;
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
|
@ -12,6 +12,7 @@ const mapService = (s, beat) => ({
|
|||||||
name: s.name,
|
name: s.name,
|
||||||
cluster: s.cluster,
|
cluster: s.cluster,
|
||||||
lastBeat: beat,
|
lastBeat: beat,
|
||||||
|
checked: s.lastChecked,
|
||||||
});
|
});
|
||||||
|
|
||||||
async function createDashboardSocket(server) {
|
async function createDashboardSocket(server) {
|
||||||
|
Loading…
Reference in New Issue
Block a user