From 468718abda12979e34e6da8981a6976193ccf48b Mon Sep 17 00:00:00 2001 From: mutatrum Date: Mon, 2 Dec 2024 23:45:50 +0100 Subject: [PATCH] Add uptime to home screen (#425) --- .../src/app/components/home/home.component.html | 6 ++++++ .../axe-os/src/app/pipes/date-ago.pipe.ts | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main/http_server/axe-os/src/app/components/home/home.component.html b/main/http_server/axe-os/src/app/components/home/home.component.html index 8d0bab97b..0c14cdda3 100644 --- a/main/http_server/axe-os/src/app/components/home/home.component.html +++ b/main/http_server/axe-os/src/app/components/home/home.component.html @@ -218,6 +218,12 @@
Pool Information ({{info.isUsingFallbackStratum ? 'Fallback' : 'Primary' }}) +
+
+
Uptime
+ {{info.uptimeSeconds | dateAgo}} +
+
diff --git a/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts index 48659dd0b..8e5036899 100644 --- a/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts +++ b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts @@ -9,7 +9,7 @@ export class DateAgoPipe implements PipeTransform { transform(value: any, args?: any): any { if (value) { value = new Date().getTime() - value * 1000; - const seconds = Math.floor((+new Date() - +new Date(value)) / 1000); + let seconds = Math.floor((+new Date() - +new Date(value)) / 1000); if (seconds < 29) // less than 30 seconds ago will show as 'Just now' return 'Just now'; const intervals: { [key: string]: number } = { @@ -21,16 +21,21 @@ export class DateAgoPipe implements PipeTransform { 'minute': 60, 'second': 1 }; - let counter; + let result = ''; for (const i in intervals) { - counter = Math.floor(seconds / intervals[i]); + const counter = Math.floor(seconds / intervals[i]); if (counter > 0) if (counter === 1) { - return counter + ' ' + i + ''; // singular (1 day ago) + if (result) result += ', ' + result += counter + ' ' + i + ''; // singular (1 day ago) + seconds -= intervals[i] } else { - return counter + ' ' + i + 's'; // plural (2 days ago) + if (result) result += ', ' + result += counter + ' ' + i + 's'; // plural (2 days ago) + seconds -= intervals[i] * counter } } + return result; } return value; }