]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
Fix progress display
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
CommitLineData
41b15c89 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit } from '@angular/core'
3import { Notifier, RestPagination, RestTable } from '@app/core'
4504f09f 4import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
67ed6552 5import { Job, JobState, JobType } from '@shared/models'
42712121 6import { JobStateClient } from '../../../../types/job-state-client.type'
1061c73f 7import { JobTypeClient } from '../../../../types/job-type-client.type'
67ed6552 8import { 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 15export 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',
51353d9a 39 'videos-views-stats',
0305db28 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 () {
e5830ac6 80 if (this.jobState === 'all' && this.hasGlobalProgress()) return 7
ed4bc631 81
e5830ac6 82 if (this.jobState === 'all' || this.hasGlobalProgress()) 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
e5830ac6 94 hasGlobalProgress () {
3b01f4c0
C
95 return this.jobType === 'all' || this.jobType === 'video-transcoding'
96 }
97
e5830ac6
C
98 hasProgress (job: Job) {
99 return job.type === 'video-transcoding'
100 }
101
3b01f4c0
C
102 getProgress (job: Job) {
103 if (job.state === 'active') return job.progress + '%'
104
105 return ''
106 }
107
83e74670
C
108 refresh () {
109 this.jobs = []
110 this.totalRecords = 0
111
2e46eb97 112 this.reloadData()
83e74670
C
113 }
114
2e46eb97 115 protected reloadData () {
040d6896
RK
116 let jobState = this.jobState as JobState
117 if (this.jobState === 'all') jobState = null
118
5cd80545 119 this.jobsService
040d6896
RK
120 .getJobs({
121 jobState,
122 jobType: this.jobType,
123 pagination: this.pagination,
124 sort: this.sort
125 })
1378c0d3
C
126 .subscribe({
127 next: resultList => {
5cd80545
C
128 this.jobs = resultList.data
129 this.totalRecords = resultList.total
130 },
131
1378c0d3
C
132 error: err => this.notifier.error(err.message)
133 })
5cd80545 134 }
ab998f7b 135
1061c73f 136 private loadJobStateAndType () {
b764380a 137 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
1061c73f 138 if (state) this.jobState = state as JobState
ab998f7b 139
b764380a 140 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
1061c73f 141 if (type) this.jobType = type as JobType
ab998f7b
C
142 }
143
1061c73f 144 private saveJobStateAndType () {
b764380a
C
145 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
146 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 147 }
5cd80545 148}