]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' | |
3 | import { Notifier } from '@app/core' | |
4 | import { SortMeta } from 'primeng/api' | |
5 | import { Job, JobType } from '../../../../../../shared/index' | |
6 | import { JobState } from '../../../../../../shared/models' | |
7 | import { RestPagination, RestTable } from '../../../shared' | |
8 | import { JobService } from './job.service' | |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
10 | import { JobTypeClient } from '../../../../types/job-type-client.type' | |
11 | ||
12 | @Component({ | |
13 | selector: 'my-jobs', | |
14 | templateUrl: './jobs.component.html', | |
15 | styleUrls: [ './jobs.component.scss' ] | |
16 | }) | |
17 | export class JobsComponent extends RestTable implements OnInit { | |
18 | private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state' | |
19 | private static JOB_STATE_LOCAL_STORAGE_TYPE = 'jobs-list-type' | |
20 | ||
21 | jobState: JobState = 'waiting' | |
22 | jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] | |
23 | ||
24 | jobType: JobTypeClient = 'all' | |
25 | jobTypes: JobTypeClient[] = [ | |
26 | 'all', | |
27 | 'activitypub-follow', | |
28 | 'activitypub-http-broadcast', | |
29 | 'activitypub-http-fetcher', | |
30 | 'activitypub-http-unicast', | |
31 | 'email', | |
32 | 'video-transcoding', | |
33 | 'video-file-import', | |
34 | 'video-import', | |
35 | 'videos-views', | |
36 | 'activitypub-refresher' | |
37 | ] | |
38 | ||
39 | jobs: Job[] = [] | |
40 | totalRecords: number | |
41 | rowsPerPage = 10 | |
42 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
43 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
44 | ||
45 | constructor ( | |
46 | private notifier: Notifier, | |
47 | private jobsService: JobService, | |
48 | private i18n: I18n | |
49 | ) { | |
50 | super() | |
51 | } | |
52 | ||
53 | ngOnInit () { | |
54 | this.loadJobStateAndType() | |
55 | this.initialize() | |
56 | } | |
57 | ||
58 | onJobStateOrTypeChanged () { | |
59 | this.pagination.start = 0 | |
60 | ||
61 | this.loadData() | |
62 | this.saveJobStateAndType() | |
63 | } | |
64 | ||
65 | protected loadData () { | |
66 | this.jobsService | |
67 | .getJobs(this.jobState, this.jobType, this.pagination, this.sort) | |
68 | .subscribe( | |
69 | resultList => { | |
70 | this.jobs = resultList.data | |
71 | this.totalRecords = resultList.total | |
72 | }, | |
73 | ||
74 | err => this.notifier.error(err.message) | |
75 | ) | |
76 | } | |
77 | ||
78 | private loadJobStateAndType () { | |
79 | const state = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE) | |
80 | if (state) this.jobState = state as JobState | |
81 | ||
82 | const type = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE) | |
83 | if (type) this.jobType = type as JobType | |
84 | } | |
85 | ||
86 | private saveJobStateAndType () { | |
87 | peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState) | |
88 | peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE, this.jobType) | |
89 | } | |
90 | } |