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