]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
advertise live streaming as a feature in readme
[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 75 getColspan () {
ed4bc631
C
76 if (this.jobState === 'all' && this.hasProgress()) return 6
77
78 if (this.jobState === 'all') return 5
79
80 return 4
040d6896
RK
81 }
82
1061c73f 83 onJobStateOrTypeChanged () {
6d8c70aa
C
84 this.pagination.start = 0
85
94a5ff8a 86 this.loadData()
1061c73f 87 this.saveJobStateAndType()
94a5ff8a
C
88 }
89
3b01f4c0
C
90 hasProgress () {
91 return this.jobType === 'all' || this.jobType === 'video-transcoding'
92 }
93
94 getProgress (job: Job) {
95 if (job.state === 'active') return job.progress + '%'
96
97 return ''
98 }
99
5cd80545 100 protected loadData () {
040d6896
RK
101 let jobState = this.jobState as JobState
102 if (this.jobState === 'all') jobState = null
103
5cd80545 104 this.jobsService
040d6896
RK
105 .getJobs({
106 jobState,
107 jobType: this.jobType,
108 pagination: this.pagination,
109 sort: this.sort
110 })
5cd80545
C
111 .subscribe(
112 resultList => {
113 this.jobs = resultList.data
114 this.totalRecords = resultList.total
115 },
116
f8b2c1b4 117 err => this.notifier.error(err.message)
5cd80545
C
118 )
119 }
ab998f7b 120
1061c73f 121 private loadJobStateAndType () {
b764380a 122 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
1061c73f 123 if (state) this.jobState = state as JobState
ab998f7b 124
b764380a 125 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
1061c73f 126 if (type) this.jobType = type as JobType
ab998f7b
C
127 }
128
1061c73f 129 private saveJobStateAndType () {
b764380a
C
130 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
131 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 132 }
5cd80545 133}