]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/system/jobs/jobs.component.ts
Fix broken local actors
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
5 import { Job, JobState, JobType } from '@shared/models'
6 import { JobStateClient } from '../../../../types/job-state-client.type'
7 import { JobTypeClient } from '../../../../types/job-type-client.type'
8 import { JobService } from './job.service'
9
10 @Component({
11 selector: 'my-jobs',
12 templateUrl: './jobs.component.html',
13 styleUrls: [ './jobs.component.scss' ]
14 })
15 export class JobsComponent extends RestTable implements OnInit {
16 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
17 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
18
19 jobState?: JobStateClient | 'all'
20 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
21
22 jobType: JobTypeClient = 'all'
23 jobTypes: JobTypeClient[] = [
24 'all',
25
26 'activitypub-follow',
27 'activitypub-http-broadcast',
28 'activitypub-http-fetcher',
29 'activitypub-http-unicast',
30 'activitypub-refresher',
31 'actor-keys',
32 'email',
33 'video-file-import',
34 'video-import',
35 'video-live-ending',
36 'video-redundancy',
37 'video-transcoding',
38 'videos-views'
39 ]
40
41 jobs: Job[] = []
42 totalRecords: number
43 sort: SortMeta = { field: 'createdAt', order: -1 }
44 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
45
46 constructor (
47 private notifier: Notifier,
48 private jobsService: JobService
49 ) {
50 super()
51 }
52
53 ngOnInit () {
54 this.loadJobStateAndType()
55 this.initialize()
56 }
57
58 getIdentifier () {
59 return 'JobsComponent'
60 }
61
62 getJobStateClass (state: JobStateClient) {
63 switch (state) {
64 case 'active':
65 return 'badge-blue'
66 case 'completed':
67 return 'badge-green'
68 case 'delayed':
69 return 'badge-brown'
70 case 'failed':
71 return 'badge-red'
72 case 'waiting':
73 return 'badge-yellow'
74 }
75 }
76
77 getColspan () {
78 if (this.jobState === 'all' && this.hasProgress()) return 7
79
80 if (this.jobState === 'all' || this.hasProgress()) return 6
81
82 return 5
83 }
84
85 onJobStateOrTypeChanged () {
86 this.pagination.start = 0
87
88 this.loadData()
89 this.saveJobStateAndType()
90 }
91
92 hasProgress () {
93 return this.jobType === 'all' || this.jobType === 'video-transcoding'
94 }
95
96 getProgress (job: Job) {
97 if (job.state === 'active') return job.progress + '%'
98
99 return ''
100 }
101
102 refresh () {
103 this.jobs = []
104 this.totalRecords = 0
105
106 this.loadData()
107 }
108
109 protected loadData () {
110 let jobState = this.jobState as JobState
111 if (this.jobState === 'all') jobState = null
112
113 this.jobsService
114 .getJobs({
115 jobState,
116 jobType: this.jobType,
117 pagination: this.pagination,
118 sort: this.sort
119 })
120 .subscribe(
121 resultList => {
122 this.jobs = resultList.data
123 this.totalRecords = resultList.total
124 },
125
126 err => this.notifier.error(err.message)
127 )
128 }
129
130 private loadJobStateAndType () {
131 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
132 if (state) this.jobState = state as JobState
133
134 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
135 if (type) this.jobType = type as JobType
136 }
137
138 private saveJobStateAndType () {
139 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
140 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
141 }
142 }