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