]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
Update FAQ
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
CommitLineData
41b15c89 1import { SortMeta } from 'primeng/api'
67ed6552
C
2import { Component, OnInit } from '@angular/core'
3import { Notifier, RestPagination, RestTable } from '@app/core'
4504f09f 4import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
67ed6552 5import { Job, JobState, JobType } from '@shared/models'
42712121 6import { JobStateClient } from '../../../../types/job-state-client.type'
1061c73f 7import { JobTypeClient } from '../../../../types/job-type-client.type'
67ed6552 8import { JobService } from './job.service'
5cd80545
C
9
10@Component({
2c22613c
C
11 selector: 'my-jobs',
12 templateUrl: './jobs.component.html',
13 styleUrls: [ './jobs.component.scss' ]
5cd80545 14})
2c22613c 15export class JobsComponent extends RestTable implements OnInit {
b764380a
C
16 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
17 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
ab998f7b 18
040d6896 19 jobState?: JobStateClient | 'all'
42712121 20 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
1061c73f
C
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',
b764380a 34 'activitypub-refresher',
97969c4e
C
35 'video-redundancy',
36 'video-live-ending'
1061c73f
C
37 ]
38
5cd80545 39 jobs: Job[] = []
ab998f7b 40 totalRecords: number
94a5ff8a 41 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
42 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
43
44 constructor (
f8b2c1b4 45 private notifier: Notifier,
66357162
C
46 private jobsService: JobService
47 ) {
5cd80545
C
48 super()
49 }
50
cd83ea1b 51 ngOnInit () {
1061c73f 52 this.loadJobStateAndType()
24b9417c 53 this.initialize()
cd83ea1b
C
54 }
55
8e11a1b3
C
56 getIdentifier () {
57 return 'JobsComponent'
58 }
59
7f0d8561
RK
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
040d6896
RK
75 getColspan () {
76 return this.jobState === 'all' ? 5 : 4
77 }
78
1061c73f 79 onJobStateOrTypeChanged () {
6d8c70aa
C
80 this.pagination.start = 0
81
94a5ff8a 82 this.loadData()
1061c73f 83 this.saveJobStateAndType()
94a5ff8a
C
84 }
85
5cd80545 86 protected loadData () {
040d6896
RK
87 let jobState = this.jobState as JobState
88 if (this.jobState === 'all') jobState = null
89
5cd80545 90 this.jobsService
040d6896
RK
91 .getJobs({
92 jobState,
93 jobType: this.jobType,
94 pagination: this.pagination,
95 sort: this.sort
96 })
5cd80545
C
97 .subscribe(
98 resultList => {
99 this.jobs = resultList.data
100 this.totalRecords = resultList.total
101 },
102
f8b2c1b4 103 err => this.notifier.error(err.message)
5cd80545
C
104 )
105 }
ab998f7b 106
1061c73f 107 private loadJobStateAndType () {
b764380a 108 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
1061c73f 109 if (state) this.jobState = state as JobState
ab998f7b 110
b764380a 111 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
1061c73f 112 if (type) this.jobType = type as JobType
ab998f7b
C
113 }
114
1061c73f 115 private saveJobStateAndType () {
b764380a
C
116 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
117 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 118 }
5cd80545 119}