diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-10 10:26:20 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-10 10:26:20 +0200 |
commit | f228e9f064f27301e59533aac48fd6c2e533890d (patch) | |
tree | e6c650382f5663d41bdf8606224cd0029f19fa47 /client/src | |
parent | 2a491182e483b97afb1b65c908b23cb48d591807 (diff) | |
download | PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.tar.gz PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.tar.zst PeerTube-f228e9f064f27301e59533aac48fd6c2e533890d.zip |
More precise date for jobs
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/app/+admin/system/jobs/job.service.ts | 4 | ||||
-rw-r--r-- | client/src/app/+admin/system/jobs/jobs.component.html | 2 | ||||
-rw-r--r-- | client/src/app/core/rest/rest-extractor.service.ts | 23 | ||||
-rw-r--r-- | client/src/app/helpers/utils/date.ts | 29 |
4 files changed, 43 insertions, 15 deletions
diff --git a/client/src/app/+admin/system/jobs/job.service.ts b/client/src/app/+admin/system/jobs/job.service.ts index 6c4a07469..ef8ddd3b4 100644 --- a/client/src/app/+admin/system/jobs/job.service.ts +++ b/client/src/app/+admin/system/jobs/job.service.ts | |||
@@ -34,9 +34,7 @@ export class JobService { | |||
34 | 34 | ||
35 | return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params }) | 35 | return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL + `/${jobState || ''}`, { params }) |
36 | .pipe( | 36 | .pipe( |
37 | map(res => { | 37 | map(res => this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ], 'precise')), |
38 | return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ]) | ||
39 | }), | ||
40 | map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)), | 38 | map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)), |
41 | map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)), | 39 | map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)), |
42 | catchError(err => this.restExtractor.handleError(err)) | 40 | catchError(err => this.restExtractor.handleError(err)) |
diff --git a/client/src/app/+admin/system/jobs/jobs.component.html b/client/src/app/+admin/system/jobs/jobs.component.html index b53fafeba..a5266bde5 100644 --- a/client/src/app/+admin/system/jobs/jobs.component.html +++ b/client/src/app/+admin/system/jobs/jobs.component.html | |||
@@ -69,7 +69,7 @@ | |||
69 | <ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container> | 69 | <ng-container *ngIf="hasProgress(job)">{{ getProgress(job) }}</ng-container> |
70 | </td> | 70 | </td> |
71 | 71 | ||
72 | <td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt | date: 'short' }}</td> | 72 | <td class="job-date c-hand" [pRowToggler]="job">{{ job.createdAt }}</td> |
73 | </tr> | 73 | </tr> |
74 | </ng-template> | 74 | </ng-template> |
75 | 75 | ||
diff --git a/client/src/app/core/rest/rest-extractor.service.ts b/client/src/app/core/rest/rest-extractor.service.ts index 8a2974563..7eec2eca6 100644 --- a/client/src/app/core/rest/rest-extractor.service.ts +++ b/client/src/app/core/rest/rest-extractor.service.ts | |||
@@ -1,14 +1,17 @@ | |||
1 | import { throwError as observableThrowError } from 'rxjs' | 1 | import { throwError as observableThrowError } from 'rxjs' |
2 | import { Injectable } from '@angular/core' | 2 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' |
3 | import { Router } from '@angular/router' | 3 | import { Router } from '@angular/router' |
4 | import { dateToHuman } from '@app/helpers' | 4 | import { DateFormat, dateToHuman } from '@app/helpers' |
5 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
6 | import { logger } from '@root-helpers/logger' | 5 | import { logger } from '@root-helpers/logger' |
6 | import { HttpStatusCode, ResultList } from '@shared/models' | ||
7 | 7 | ||
8 | @Injectable() | 8 | @Injectable() |
9 | export class RestExtractor { | 9 | export class RestExtractor { |
10 | 10 | ||
11 | constructor (private router: Router) { } | 11 | constructor ( |
12 | @Inject(LOCALE_ID) private localeId: string, | ||
13 | private router: Router | ||
14 | ) { } | ||
12 | 15 | ||
13 | applyToResultListData <T, A, U> ( | 16 | applyToResultListData <T, A, U> ( |
14 | result: ResultList<T>, | 17 | result: ResultList<T>, |
@@ -23,13 +26,17 @@ export class RestExtractor { | |||
23 | } | 26 | } |
24 | } | 27 | } |
25 | 28 | ||
26 | convertResultListDateToHuman <T> (result: ResultList<T>, fieldsToConvert: string[] = [ 'createdAt' ]): ResultList<T> { | 29 | convertResultListDateToHuman <T> ( |
27 | return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert ]) | 30 | result: ResultList<T>, |
31 | fieldsToConvert: string[] = [ 'createdAt' ], | ||
32 | format?: DateFormat | ||
33 | ): ResultList<T> { | ||
34 | return this.applyToResultListData(result, this.convertDateToHuman, [ fieldsToConvert, format ]) | ||
28 | } | 35 | } |
29 | 36 | ||
30 | convertDateToHuman (target: any, fieldsToConvert: string[]) { | 37 | convertDateToHuman (target: any, fieldsToConvert: string[], format?: DateFormat) { |
31 | fieldsToConvert.forEach(field => { | 38 | fieldsToConvert.forEach(field => { |
32 | target[field] = dateToHuman(target[field]) | 39 | target[field] = dateToHuman(this.localeId, new Date(target[field]), format) |
33 | }) | 40 | }) |
34 | 41 | ||
35 | return target | 42 | return target |
diff --git a/client/src/app/helpers/utils/date.ts b/client/src/app/helpers/utils/date.ts index 012b959ea..75363cc81 100644 --- a/client/src/app/helpers/utils/date.ts +++ b/client/src/app/helpers/utils/date.ts | |||
@@ -1,8 +1,29 @@ | |||
1 | import { DatePipe } from '@angular/common' | 1 | import { DatePipe } from '@angular/common' |
2 | 2 | ||
3 | const datePipe = new DatePipe('en') | 3 | let datePipe: DatePipe |
4 | function dateToHuman (date: string) { | 4 | let intl: Intl.DateTimeFormat |
5 | return datePipe.transform(date, 'medium') | 5 | |
6 | type DateFormat = 'medium' | 'precise' | ||
7 | |||
8 | function dateToHuman (localeId: string, date: Date, format: 'medium' | 'precise' = 'medium') { | ||
9 | if (!datePipe) { | ||
10 | datePipe = new DatePipe(localeId) | ||
11 | } | ||
12 | |||
13 | if (!intl) { | ||
14 | intl = new Intl.DateTimeFormat(localeId, { | ||
15 | hour: 'numeric', | ||
16 | minute: 'numeric', | ||
17 | second: 'numeric', | ||
18 | year: '2-digit', | ||
19 | month: 'numeric', | ||
20 | day: 'numeric', | ||
21 | fractionalSecondDigits: 3 | ||
22 | }) | ||
23 | } | ||
24 | |||
25 | if (format === 'medium') return datePipe.transform(date, format) | ||
26 | if (format === 'precise') return intl.format(date) | ||
6 | } | 27 | } |
7 | 28 | ||
8 | function durationToString (duration: number) { | 29 | function durationToString (duration: number) { |
@@ -20,6 +41,8 @@ function durationToString (duration: number) { | |||
20 | } | 41 | } |
21 | 42 | ||
22 | export { | 43 | export { |
44 | DateFormat, | ||
45 | |||
23 | durationToString, | 46 | durationToString, |
24 | dateToHuman | 47 | dateToHuman |
25 | } | 48 | } |