]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/system/jobs/jobs.component.ts
add display of logs matching any state
[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-live-ending',
36 'video-redundancy',
37 'video-live-ending'
38 ]
39
40 jobs: Job[] = []
41 totalRecords: number
42 sort: SortMeta = { field: 'createdAt', order: -1 }
43 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
44
45 constructor (
46 private notifier: Notifier,
47 private jobsService: JobService
48 ) {
49 super()
50 }
51
52 ngOnInit () {
53 this.loadJobStateAndType()
54 this.initialize()
55 }
56
57 getIdentifier () {
58 return 'JobsComponent'
59 }
60
61 getJobStateClass (state: JobStateClient) {
62 switch (state) {
63 case 'active':
64 return 'badge-blue'
65 case 'completed':
66 return 'badge-green'
67 case 'delayed':
68 return 'badge-brown'
69 case 'failed':
70 return 'badge-red'
71 case 'waiting':
72 return 'badge-yellow'
73 }
74 }
75
76 getColspan () {
77 return this.jobState === 'all' ? 5 : 4
78 }
79
80 onJobStateOrTypeChanged () {
81 this.pagination.start = 0
82
83 this.loadData()
84 this.saveJobStateAndType()
85 }
86
87 protected loadData () {
88 let jobState = this.jobState as JobState
89 if (this.jobState === 'all') jobState = null
90
91 this.jobsService
92 .getJobs({
93 jobState,
94 jobType: this.jobType,
95 pagination: this.pagination,
96 sort: this.sort
97 })
98 .subscribe(
99 resultList => {
100 this.jobs = resultList.data
101 this.totalRecords = resultList.total
102 },
103
104 err => this.notifier.error(err.message)
105 )
106 }
107
108 private loadJobStateAndType () {
109 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
110 if (state) this.jobState = state as JobState
111
112 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
113 if (type) this.jobType = type as JobType
114 }
115
116 private saveJobStateAndType () {
117 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
118 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
119 }
120 }