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