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