]>
Commit | Line | Data |
---|---|---|
41b15c89 | 1 | import { SortMeta } from 'primeng/api' |
67ed6552 C |
2 | import { Component, OnInit } from '@angular/core' |
3 | import { Notifier, RestPagination, RestTable } from '@app/core' | |
4504f09f | 4 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
67ed6552 | 5 | import { Job, JobState, JobType } from '@shared/models' |
42712121 | 6 | import { JobStateClient } from '../../../../types/job-state-client.type' |
1061c73f | 7 | import { JobTypeClient } from '../../../../types/job-type-client.type' |
67ed6552 | 8 | import { JobService } from './job.service' |
5cd80545 C |
9 | |
10 | @Component({ | |
2c22613c C |
11 | selector: 'my-jobs', |
12 | templateUrl: './jobs.component.html', | |
13 | styleUrls: [ './jobs.component.scss' ] | |
5cd80545 | 14 | }) |
2c22613c | 15 | export class JobsComponent extends RestTable implements OnInit { |
b764380a C |
16 | private static LOCAL_STORAGE_STATE = 'jobs-list-state' |
17 | private static LOCAL_STORAGE_TYPE = 'jobs-list-type' | |
ab998f7b | 18 | |
42712121 JM |
19 | jobState: JobStateClient = 'waiting' |
20 | jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] | |
1061c73f C |
21 | |
22 | jobType: JobTypeClient = 'all' | |
23 | jobTypes: JobTypeClient[] = [ | |
24 | 'all', | |
25 | 'activitypub-follow', | |
26 | 'activitypub-http-broadcast', | |
27 | 'activitypub-http-fetcher', | |
28 | 'activitypub-http-unicast', | |
29 | 'email', | |
30 | 'video-transcoding', | |
31 | 'video-file-import', | |
32 | 'video-import', | |
33 | 'videos-views', | |
b764380a | 34 | 'activitypub-refresher', |
a5cf76af | 35 | 'video-live-ending', |
97969c4e C |
36 | 'video-redundancy', |
37 | 'video-live-ending' | |
1061c73f C |
38 | ] |
39 | ||
5cd80545 | 40 | jobs: Job[] = [] |
ab998f7b | 41 | totalRecords: number |
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, |
66357162 C |
47 | private jobsService: JobService |
48 | ) { | |
5cd80545 C |
49 | super() |
50 | } | |
51 | ||
cd83ea1b | 52 | ngOnInit () { |
1061c73f | 53 | this.loadJobStateAndType() |
24b9417c | 54 | this.initialize() |
cd83ea1b C |
55 | } |
56 | ||
8e11a1b3 C |
57 | getIdentifier () { |
58 | return 'JobsComponent' | |
59 | } | |
60 | ||
7f0d8561 RK |
61 | getJobStateClass (state: JobStateClient) { |
62 | switch (state) { | |
63 | case 'active': | |
64 | return 'badge-blue' | |
65 | case 'completed': | |
66 | return 'badge-green' | |
67 | case 'delayed': | |
68 | return 'badge-brown' | |
69 | case 'failed': | |
70 | return 'badge-red' | |
71 | case 'waiting': | |
72 | return 'badge-yellow' | |
73 | } | |
74 | } | |
75 | ||
1061c73f | 76 | onJobStateOrTypeChanged () { |
6d8c70aa C |
77 | this.pagination.start = 0 |
78 | ||
94a5ff8a | 79 | this.loadData() |
1061c73f | 80 | this.saveJobStateAndType() |
94a5ff8a C |
81 | } |
82 | ||
5cd80545 C |
83 | protected loadData () { |
84 | this.jobsService | |
1061c73f | 85 | .getJobs(this.jobState, this.jobType, this.pagination, this.sort) |
5cd80545 C |
86 | .subscribe( |
87 | resultList => { | |
88 | this.jobs = resultList.data | |
89 | this.totalRecords = resultList.total | |
90 | }, | |
91 | ||
f8b2c1b4 | 92 | err => this.notifier.error(err.message) |
5cd80545 C |
93 | ) |
94 | } | |
ab998f7b | 95 | |
1061c73f | 96 | private loadJobStateAndType () { |
b764380a | 97 | const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE) |
1061c73f | 98 | if (state) this.jobState = state as JobState |
ab998f7b | 99 | |
b764380a | 100 | const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE) |
1061c73f | 101 | if (type) this.jobType = type as JobType |
ab998f7b C |
102 | } |
103 | ||
1061c73f | 104 | private saveJobStateAndType () { |
b764380a C |
105 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState) |
106 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType) | |
ab998f7b | 107 | } |
5cd80545 | 108 | } |