Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add uptime to home screen #425

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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