Skip to content

Commit

Permalink
Add uptime to home screen (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
mutatrum authored Dec 2, 2024
1 parent fe4ac7e commit 468718a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ <h5>Pool Information ({{info.isUsingFallbackStratum ? 'Fallback' : 'Primary' }})
</div>
</div>

<div class="col-12 lg:col-6">
<div class="card" *ngIf="info$ | async as info; else loading">
<h5>Uptime</h5>
{{info.uptimeSeconds | dateAgo}}
</div>
</div>

</div>

Expand Down
15 changes: 10 additions & 5 deletions main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {
Expand All @@ -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;
}
Expand Down

0 comments on commit 468718a

Please sign in to comment.