]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/system/jobs/jobs.component.ts
Fix duplicate entry in job list page
[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 'activitypub-follow',
26 'activitypub-http-broadcast',
27 'activitypub-http-fetcher',
28 'activitypub-http-unicast',
29 'email',
30 'video-transcoding',
31 'video-file-import',
32 'video-import',
33 'videos-views',
34 'activitypub-refresher',
35 'video-redundancy',
36 'video-live-ending'
37 ]
38
39 jobs: Job[] = []
40 totalRecords: number
41 sort: SortMeta = { field: 'createdAt', order: -1 }
42 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
43
44 constructor (
45 private notifier: Notifier,
46 private jobsService: JobService
47 ) {
48 super()
49 }
50
51 ngOnInit () {
52 this.loadJobStateAndType()
53 this.initialize()
54 }
55
56 getIdentifier () {
57 return 'JobsComponent'
58 }
59
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
75 getColspan () {
76 return this.jobState === 'all' ? 5 : 4
77 }
78
79 onJobStateOrTypeChanged () {
80 this.pagination.start = 0
81
82 this.loadData()
83 this.saveJobStateAndType()
84 }
85
86 protected loadData () {
87 let jobState = this.jobState as JobState
88 if (this.jobState === 'all') jobState = null
89
90 this.jobsService
91 .getJobs({
92 jobState,
93 jobType: this.jobType,
94 pagination: this.pagination,
95 sort: this.sort
96 })
97 .subscribe(
98 resultList => {
99 this.jobs = resultList.data
100 this.totalRecords = resultList.total
101 },
102
103 err => this.notifier.error(err.message)
104 )
105 }
106
107 private loadJobStateAndType () {
108 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
109 if (state) this.jobState = state as JobState
110
111 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
112 if (type) this.jobType = type as JobType
113 }
114
115 private saveJobStateAndType () {
116 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
117 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
118 }
119 }