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