diff options
Diffstat (limited to 'client/src/app/+admin/system/jobs/jobs.component.ts')
-rw-r--r-- | client/src/app/+admin/system/jobs/jobs.component.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/client/src/app/+admin/system/jobs/jobs.component.ts b/client/src/app/+admin/system/jobs/jobs.component.ts new file mode 100644 index 000000000..b265e1dd6 --- /dev/null +++ b/client/src/app/+admin/system/jobs/jobs.component.ts | |||
@@ -0,0 +1,69 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | ||
2 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' | ||
3 | import { Notifier } from '@app/core' | ||
4 | import { SortMeta } from 'primeng/primeng' | ||
5 | import { Job } from '../../../../../../shared/index' | ||
6 | import { JobState } from '../../../../../../shared/models' | ||
7 | import { RestPagination, RestTable } from '../../../shared' | ||
8 | import { JobService } from '../shared' | ||
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-jobs-list', | ||
13 | templateUrl: './jobs-list.component.html', | ||
14 | styleUrls: [ './jobs-list.component.scss' ] | ||
15 | }) | ||
16 | export class JobsListComponent extends RestTable implements OnInit { | ||
17 | private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state' | ||
18 | |||
19 | jobState: JobState = 'waiting' | ||
20 | jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] | ||
21 | jobs: Job[] = [] | ||
22 | totalRecords: number | ||
23 | rowsPerPage = 10 | ||
24 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
25 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
26 | |||
27 | constructor ( | ||
28 | private notifier: Notifier, | ||
29 | private jobsService: JobService, | ||
30 | private i18n: I18n | ||
31 | ) { | ||
32 | super() | ||
33 | } | ||
34 | |||
35 | ngOnInit () { | ||
36 | this.loadJobState() | ||
37 | this.initialize() | ||
38 | } | ||
39 | |||
40 | onJobStateChanged () { | ||
41 | this.pagination.start = 0 | ||
42 | |||
43 | this.loadData() | ||
44 | this.saveJobState() | ||
45 | } | ||
46 | |||
47 | protected loadData () { | ||
48 | this.jobsService | ||
49 | .getJobs(this.jobState, this.pagination, this.sort) | ||
50 | .subscribe( | ||
51 | resultList => { | ||
52 | this.jobs = resultList.data | ||
53 | this.totalRecords = resultList.total | ||
54 | }, | ||
55 | |||
56 | err => this.notifier.error(err.message) | ||
57 | ) | ||
58 | } | ||
59 | |||
60 | private loadJobState () { | ||
61 | const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE) | ||
62 | |||
63 | if (result) this.jobState = result as JobState | ||
64 | } | ||
65 | |||
66 | private saveJobState () { | ||
67 | peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState) | ||
68 | } | ||
69 | } | ||