]>
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 | |
040d6896 | 19 | jobState?: JobStateClient | 'all' |
42712121 | 20 | jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] |
1061c73f C |
21 | |
22 | jobType: JobTypeClient = 'all' | |
23 | jobTypes: JobTypeClient[] = [ | |
6d22ea00 | 24 | 'all', |
8795d6f2 | 25 | |
1061c73f C |
26 | 'activitypub-follow', |
27 | 'activitypub-http-broadcast', | |
28 | 'activitypub-http-fetcher', | |
29 | 'activitypub-http-unicast', | |
77d7e851 | 30 | 'activitypub-refresher', |
74d249bc | 31 | 'activitypub-cleaner', |
8795d6f2 | 32 | 'actor-keys', |
1061c73f | 33 | 'email', |
1061c73f C |
34 | 'video-file-import', |
35 | 'video-import', | |
77d7e851 | 36 | 'video-live-ending', |
97969c4e | 37 | 'video-redundancy', |
77d7e851 | 38 | 'video-transcoding', |
0305db28 JB |
39 | 'videos-views', |
40 | 'move-to-object-storage' | |
1061c73f C |
41 | ] |
42 | ||
5cd80545 | 43 | jobs: Job[] = [] |
ab998f7b | 44 | totalRecords: number |
94a5ff8a | 45 | sort: SortMeta = { field: 'createdAt', order: -1 } |
5cd80545 C |
46 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
47 | ||
48 | constructor ( | |
f8b2c1b4 | 49 | private notifier: Notifier, |
66357162 | 50 | private jobsService: JobService |
83e74670 | 51 | ) { |
5cd80545 C |
52 | super() |
53 | } | |
54 | ||
cd83ea1b | 55 | ngOnInit () { |
1061c73f | 56 | this.loadJobStateAndType() |
24b9417c | 57 | this.initialize() |
cd83ea1b C |
58 | } |
59 | ||
8e11a1b3 C |
60 | getIdentifier () { |
61 | return 'JobsComponent' | |
62 | } | |
63 | ||
7f0d8561 RK |
64 | getJobStateClass (state: JobStateClient) { |
65 | switch (state) { | |
66 | case 'active': | |
67 | return 'badge-blue' | |
68 | case 'completed': | |
69 | return 'badge-green' | |
70 | case 'delayed': | |
71 | return 'badge-brown' | |
72 | case 'failed': | |
73 | return 'badge-red' | |
74 | case 'waiting': | |
75 | return 'badge-yellow' | |
76 | } | |
77 | } | |
78 | ||
040d6896 | 79 | getColspan () { |
6939cbac | 80 | if (this.jobState === 'all' && this.hasProgress()) return 7 |
ed4bc631 | 81 | |
6939cbac | 82 | if (this.jobState === 'all' || this.hasProgress()) return 6 |
ed4bc631 | 83 | |
6939cbac | 84 | return 5 |
040d6896 RK |
85 | } |
86 | ||
1061c73f | 87 | onJobStateOrTypeChanged () { |
6d8c70aa C |
88 | this.pagination.start = 0 |
89 | ||
2e46eb97 | 90 | this.reloadData() |
1061c73f | 91 | this.saveJobStateAndType() |
94a5ff8a C |
92 | } |
93 | ||
3b01f4c0 C |
94 | hasProgress () { |
95 | return this.jobType === 'all' || this.jobType === 'video-transcoding' | |
96 | } | |
97 | ||
98 | getProgress (job: Job) { | |
99 | if (job.state === 'active') return job.progress + '%' | |
100 | ||
101 | return '' | |
102 | } | |
103 | ||
83e74670 C |
104 | refresh () { |
105 | this.jobs = [] | |
106 | this.totalRecords = 0 | |
107 | ||
2e46eb97 | 108 | this.reloadData() |
83e74670 C |
109 | } |
110 | ||
2e46eb97 | 111 | protected reloadData () { |
040d6896 RK |
112 | let jobState = this.jobState as JobState |
113 | if (this.jobState === 'all') jobState = null | |
114 | ||
5cd80545 | 115 | this.jobsService |
040d6896 RK |
116 | .getJobs({ |
117 | jobState, | |
118 | jobType: this.jobType, | |
119 | pagination: this.pagination, | |
120 | sort: this.sort | |
121 | }) | |
1378c0d3 C |
122 | .subscribe({ |
123 | next: resultList => { | |
5cd80545 C |
124 | this.jobs = resultList.data |
125 | this.totalRecords = resultList.total | |
126 | }, | |
127 | ||
1378c0d3 C |
128 | error: err => this.notifier.error(err.message) |
129 | }) | |
5cd80545 | 130 | } |
ab998f7b | 131 | |
1061c73f | 132 | private loadJobStateAndType () { |
b764380a | 133 | const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE) |
1061c73f | 134 | if (state) this.jobState = state as JobState |
ab998f7b | 135 | |
b764380a | 136 | const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE) |
1061c73f | 137 | if (type) this.jobType = type as JobType |
ab998f7b C |
138 | } |
139 | ||
1061c73f | 140 | private saveJobStateAndType () { |
b764380a C |
141 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState) |
142 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType) | |
ab998f7b | 143 | } |
5cd80545 | 144 | } |