]>
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' |
2198bb5a | 5 | import { escapeHTML } from '@shared/core-utils/renderer' |
67ed6552 | 6 | import { Job, JobState, JobType } from '@shared/models' |
42712121 | 7 | import { JobStateClient } from '../../../../types/job-state-client.type' |
1061c73f | 8 | import { JobTypeClient } from '../../../../types/job-type-client.type' |
67ed6552 | 9 | import { JobService } from './job.service' |
5cd80545 C |
10 | |
11 | @Component({ | |
2c22613c C |
12 | selector: 'my-jobs', |
13 | templateUrl: './jobs.component.html', | |
14 | styleUrls: [ './jobs.component.scss' ] | |
5cd80545 | 15 | }) |
2c22613c | 16 | export class JobsComponent extends RestTable implements OnInit { |
b764380a C |
17 | private static LOCAL_STORAGE_STATE = 'jobs-list-state' |
18 | private static LOCAL_STORAGE_TYPE = 'jobs-list-type' | |
ab998f7b | 19 | |
040d6896 | 20 | jobState?: JobStateClient | 'all' |
42712121 | 21 | jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] |
1061c73f C |
22 | |
23 | jobType: JobTypeClient = 'all' | |
24 | jobTypes: JobTypeClient[] = [ | |
6d22ea00 | 25 | 'all', |
8795d6f2 | 26 | |
0567049a | 27 | 'activitypub-cleaner', |
1061c73f | 28 | 'activitypub-follow', |
f27b7a75 | 29 | 'activitypub-http-broadcast-parallel', |
0567049a | 30 | 'activitypub-http-broadcast', |
1061c73f C |
31 | 'activitypub-http-fetcher', |
32 | 'activitypub-http-unicast', | |
77d7e851 | 33 | 'activitypub-refresher', |
8795d6f2 | 34 | 'actor-keys', |
0567049a | 35 | 'after-video-channel-import', |
1061c73f | 36 | 'email', |
0567049a C |
37 | 'federate-video', |
38 | 'manage-video-torrent', | |
39 | 'move-to-object-storage', | |
40 | 'notify', | |
41 | 'video-channel-import', | |
1061c73f C |
42 | 'video-file-import', |
43 | 'video-import', | |
77d7e851 | 44 | 'video-live-ending', |
97969c4e | 45 | 'video-redundancy', |
0567049a | 46 | 'video-studio-edition', |
77d7e851 | 47 | 'video-transcoding', |
0567049a | 48 | 'videos-views-stats' |
1061c73f C |
49 | ] |
50 | ||
5cd80545 | 51 | jobs: Job[] = [] |
ab998f7b | 52 | totalRecords: number |
94a5ff8a | 53 | sort: SortMeta = { field: 'createdAt', order: -1 } |
5cd80545 C |
54 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
55 | ||
56 | constructor ( | |
f8b2c1b4 | 57 | private notifier: Notifier, |
66357162 | 58 | private jobsService: JobService |
83e74670 | 59 | ) { |
5cd80545 C |
60 | super() |
61 | } | |
62 | ||
cd83ea1b | 63 | ngOnInit () { |
1061c73f | 64 | this.loadJobStateAndType() |
24b9417c | 65 | this.initialize() |
cd83ea1b C |
66 | } |
67 | ||
8e11a1b3 C |
68 | getIdentifier () { |
69 | return 'JobsComponent' | |
70 | } | |
71 | ||
7f0d8561 RK |
72 | getJobStateClass (state: JobStateClient) { |
73 | switch (state) { | |
74 | case 'active': | |
75 | return 'badge-blue' | |
76 | case 'completed': | |
77 | return 'badge-green' | |
78 | case 'delayed': | |
79 | return 'badge-brown' | |
80 | case 'failed': | |
81 | return 'badge-red' | |
82 | case 'waiting': | |
83 | return 'badge-yellow' | |
84 | } | |
85 | } | |
86 | ||
040d6896 | 87 | getColspan () { |
e5830ac6 | 88 | if (this.jobState === 'all' && this.hasGlobalProgress()) return 7 |
ed4bc631 | 89 | |
e5830ac6 | 90 | if (this.jobState === 'all' || this.hasGlobalProgress()) return 6 |
ed4bc631 | 91 | |
6939cbac | 92 | return 5 |
040d6896 RK |
93 | } |
94 | ||
1061c73f | 95 | onJobStateOrTypeChanged () { |
6d8c70aa C |
96 | this.pagination.start = 0 |
97 | ||
2e46eb97 | 98 | this.reloadData() |
1061c73f | 99 | this.saveJobStateAndType() |
94a5ff8a C |
100 | } |
101 | ||
e5830ac6 | 102 | hasGlobalProgress () { |
3b01f4c0 C |
103 | return this.jobType === 'all' || this.jobType === 'video-transcoding' |
104 | } | |
105 | ||
e5830ac6 C |
106 | hasProgress (job: Job) { |
107 | return job.type === 'video-transcoding' | |
108 | } | |
109 | ||
3b01f4c0 C |
110 | getProgress (job: Job) { |
111 | if (job.state === 'active') return job.progress + '%' | |
112 | ||
113 | return '' | |
114 | } | |
115 | ||
83e74670 C |
116 | refresh () { |
117 | this.jobs = [] | |
118 | this.totalRecords = 0 | |
119 | ||
2e46eb97 | 120 | this.reloadData() |
83e74670 C |
121 | } |
122 | ||
e854d57b | 123 | protected reloadDataInternal () { |
040d6896 RK |
124 | let jobState = this.jobState as JobState |
125 | if (this.jobState === 'all') jobState = null | |
126 | ||
5cd80545 | 127 | this.jobsService |
9589907c | 128 | .listJobs({ |
040d6896 RK |
129 | jobState, |
130 | jobType: this.jobType, | |
131 | pagination: this.pagination, | |
132 | sort: this.sort | |
133 | }) | |
1378c0d3 C |
134 | .subscribe({ |
135 | next: resultList => { | |
5cd80545 C |
136 | this.jobs = resultList.data |
137 | this.totalRecords = resultList.total | |
138 | }, | |
139 | ||
1378c0d3 C |
140 | error: err => this.notifier.error(err.message) |
141 | }) | |
5cd80545 | 142 | } |
ab998f7b | 143 | |
1061c73f | 144 | private loadJobStateAndType () { |
b764380a | 145 | const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE) |
2198bb5a C |
146 | |
147 | // FIXME: We use <ng-option> that doesn't escape HTML | |
148 | // https://github.com/ng-select/ng-select/issues/1363 | |
149 | if (state) this.jobState = escapeHTML(state) as JobState | |
ab998f7b | 150 | |
b764380a | 151 | const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE) |
1061c73f | 152 | if (type) this.jobType = type as JobType |
ab998f7b C |
153 | } |
154 | ||
1061c73f | 155 | private saveJobStateAndType () { |
b764380a C |
156 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState) |
157 | peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType) | |
ab998f7b | 158 | } |
5cd80545 | 159 | } |