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