]>
Commit | Line | Data |
---|---|---|
cd83ea1b | 1 | import { Component, OnInit } from '@angular/core' |
0bd78bf3 | 2 | import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' |
f8b2c1b4 | 3 | import { Notifier } from '@app/core' |
41b15c89 | 4 | import { SortMeta } from 'primeng/api' |
1061c73f | 5 | import { Job, JobType } from '../../../../../../shared/index' |
94a5ff8a | 6 | import { JobState } from '../../../../../../shared/models' |
5cd80545 | 7 | import { RestPagination, RestTable } from '../../../shared' |
2c22613c | 8 | import { JobService } from './job.service' |
b1d40cff | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
1061c73f | 10 | import { JobTypeClient } from '../../../../types/job-type-client.type' |
5cd80545 C |
11 | |
12 | @Component({ | |
2c22613c C |
13 | selector: 'my-jobs', |
14 | templateUrl: './jobs.component.html', | |
15 | styleUrls: [ './jobs.component.scss' ] | |
5cd80545 | 16 | }) |
2c22613c | 17 | export class JobsComponent extends RestTable implements OnInit { |
ab998f7b | 18 | private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state' |
1061c73f | 19 | private static JOB_STATE_LOCAL_STORAGE_TYPE = 'jobs-list-type' |
ab998f7b | 20 | |
94831479 C |
21 | jobState: JobState = 'waiting' |
22 | jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] | |
1061c73f C |
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 | ||
5cd80545 | 39 | jobs: Job[] = [] |
ab998f7b C |
40 | totalRecords: number |
41 | rowsPerPage = 10 | |
94a5ff8a | 42 | sort: SortMeta = { field: 'createdAt', order: -1 } |
5cd80545 C |
43 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
44 | ||
45 | constructor ( | |
f8b2c1b4 | 46 | private notifier: Notifier, |
b1d40cff C |
47 | private jobsService: JobService, |
48 | private i18n: I18n | |
5cd80545 C |
49 | ) { |
50 | super() | |
51 | } | |
52 | ||
cd83ea1b | 53 | ngOnInit () { |
1061c73f | 54 | this.loadJobStateAndType() |
24b9417c | 55 | this.initialize() |
cd83ea1b C |
56 | } |
57 | ||
1061c73f | 58 | onJobStateOrTypeChanged () { |
6d8c70aa C |
59 | this.pagination.start = 0 |
60 | ||
94a5ff8a | 61 | this.loadData() |
1061c73f | 62 | this.saveJobStateAndType() |
94a5ff8a C |
63 | } |
64 | ||
5cd80545 C |
65 | protected loadData () { |
66 | this.jobsService | |
1061c73f | 67 | .getJobs(this.jobState, this.jobType, this.pagination, this.sort) |
5cd80545 C |
68 | .subscribe( |
69 | resultList => { | |
70 | this.jobs = resultList.data | |
71 | this.totalRecords = resultList.total | |
72 | }, | |
73 | ||
f8b2c1b4 | 74 | err => this.notifier.error(err.message) |
5cd80545 C |
75 | ) |
76 | } | |
ab998f7b | 77 | |
1061c73f C |
78 | private loadJobStateAndType () { |
79 | const state = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE) | |
80 | if (state) this.jobState = state as JobState | |
ab998f7b | 81 | |
1061c73f C |
82 | const type = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE) |
83 | if (type) this.jobType = type as JobType | |
ab998f7b C |
84 | } |
85 | ||
1061c73f | 86 | private saveJobStateAndType () { |
2c22613c | 87 | peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState) |
1061c73f | 88 | peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE, this.jobType) |
ab998f7b | 89 | } |
5cd80545 | 90 | } |