mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-06-23 18:30:56 +02:00
date-ago pipe for web ui
This commit is contained in:
parent
ef71810bba
commit
1cbc08c369
2
main/http_server/axe-os/.gitignore
vendored
2
main/http_server/axe-os/.gitignore
vendored
@ -22,7 +22,7 @@ yarn-error.log
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
# !.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
@ -13,6 +13,7 @@ import { HeaderComponent } from './components/header/header.component';
|
||||
import { HomeComponent } from './components/home/home.component';
|
||||
import { LoadingComponent } from './components/loading/loading.component';
|
||||
import { ANSIPipe } from './pipes/ansi.pipe';
|
||||
import { DateAgoPipe } from './pipes/date-ago.pipe';
|
||||
|
||||
const components = [
|
||||
AppComponent,
|
||||
@ -25,7 +26,8 @@ const components = [
|
||||
EditComponent,
|
||||
HomeComponent,
|
||||
LoadingComponent,
|
||||
ANSIPipe
|
||||
ANSIPipe,
|
||||
DateAgoPipe
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
</form>
|
||||
</ng-container>
|
||||
<div>You must restart this device after saving for changes to take effect.</div>
|
||||
<div class="mt-2">
|
||||
<button (click)="updateSystem()" class="btn btn-primary mr-2">Save</button>
|
||||
<button [routerLink]="['/']" class="btn btn-secondary">Cancel</button>
|
||||
|
@ -17,8 +17,8 @@
|
||||
<td>{{info.ASICModel}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Uptime (seconds):</td>
|
||||
<td>{{info.uptimeSeconds}}</td>
|
||||
<td>Uptime:</td>
|
||||
<td>{{info.uptimeSeconds | dateAgo}}</td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -0,0 +1,8 @@
|
||||
import { DateAgoPipe } from './date-ago.pipe';
|
||||
|
||||
describe('DateAgoPipe', () => {
|
||||
it('create an instance', () => {
|
||||
const pipe = new DateAgoPipe();
|
||||
expect(pipe).toBeTruthy();
|
||||
});
|
||||
});
|
37
main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts
Normal file
37
main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
@Pipe({
|
||||
name: 'dateAgo',
|
||||
pure: true
|
||||
})
|
||||
export class DateAgoPipe implements PipeTransform {
|
||||
|
||||
transform(value: any, args?: any): any {
|
||||
if (value) {
|
||||
const 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 } = {
|
||||
'year': 31536000,
|
||||
'month': 2592000,
|
||||
'week': 604800,
|
||||
'day': 86400,
|
||||
'hour': 3600,
|
||||
'minute': 60,
|
||||
'second': 1
|
||||
};
|
||||
let counter;
|
||||
for (const i in intervals) {
|
||||
counter = Math.floor(seconds / intervals[i]);
|
||||
if (counter > 0)
|
||||
if (counter === 1) {
|
||||
return counter + ' ' + i + ''; // singular (1 day ago)
|
||||
} else {
|
||||
return counter + ' ' + i + 's'; // plural (2 days ago)
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user