diff --git a/main/http_server/axe-os/.gitignore b/main/http_server/axe-os/.gitignore index 0711527e..8b8553c7 100644 --- a/main/http_server/axe-os/.gitignore +++ b/main/http_server/axe-os/.gitignore @@ -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 diff --git a/main/http_server/axe-os/src/app/app.module.ts b/main/http_server/axe-os/src/app/app.module.ts index 9795227f..62be3087 100644 --- a/main/http_server/axe-os/src/app/app.module.ts +++ b/main/http_server/axe-os/src/app/app.module.ts @@ -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, diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.html b/main/http_server/axe-os/src/app/components/edit/edit.component.html index 0b6f2596..813172e6 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.html +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.html @@ -25,6 +25,7 @@ +
You must restart this device after saving for changes to take effect.
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 e9adb65b..0a07c351 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 @@ -17,8 +17,8 @@ {{info.ASICModel}} - Uptime (seconds): - {{info.uptimeSeconds}} + Uptime: + {{info.uptimeSeconds | dateAgo}} diff --git a/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts new file mode 100644 index 00000000..47ac2978 --- /dev/null +++ b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.spec.ts @@ -0,0 +1,8 @@ +import { DateAgoPipe } from './date-ago.pipe'; + +describe('DateAgoPipe', () => { + it('create an instance', () => { + const pipe = new DateAgoPipe(); + expect(pipe).toBeTruthy(); + }); +}); 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 new file mode 100644 index 00000000..40d79902 --- /dev/null +++ b/main/http_server/axe-os/src/app/pipes/date-ago.pipe.ts @@ -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; + } + +} \ No newline at end of file