]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/system/jobs/jobs.component.ts
Add ability to cleanup remote AP interactions
[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 'activitypub-cleaner',
32 'actor-keys',
33 'email',
34 'video-file-import',
35 'video-import',
36 'video-live-ending',
37 'video-redundancy',
38 'video-transcoding',
39 'videos-views'
40 ]
41
42 jobs: Job[] = []
43 totalRecords: number
44 sort: SortMeta = { field: 'createdAt', order: -1 }
45 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
46
47 constructor (
48 private notifier: Notifier,
49 private jobsService: JobService
50 ) {
51 super()
52 }
53
54 ngOnInit () {
55 this.loadJobStateAndType()
56 this.initialize()
57 }
58
59 getIdentifier () {
60 return 'JobsComponent'
61 }
62
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
78 getColspan () {
79 if (this.jobState === 'all' && this.hasProgress()) return 7
80
81 if (this.jobState === 'all' || this.hasProgress()) return 6
82
83 return 5
84 }
85
86 onJobStateOrTypeChanged () {
87 this.pagination.start = 0
88
89 this.loadData()
90 this.saveJobStateAndType()
91 }
92
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
103 refresh () {
104 this.jobs = []
105 this.totalRecords = 0
106
107 this.loadData()
108 }
109
110 protected loadData () {
111 let jobState = this.jobState as JobState
112 if (this.jobState === 'all') jobState = null
113
114 this.jobsService
115 .getJobs({
116 jobState,
117 jobType: this.jobType,
118 pagination: this.pagination,
119 sort: this.sort
120 })
121 .subscribe(
122 resultList => {
123 this.jobs = resultList.data
124 this.totalRecords = resultList.total
125 },
126
127 err => this.notifier.error(err.message)
128 )
129 }
130
131 private loadJobStateAndType () {
132 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
133 if (state) this.jobState = state as JobState
134
135 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
136 if (type) this.jobType = type as JobType
137 }
138
139 private saveJobStateAndType () {
140 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
141 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
142 }
143 }