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'
12 templateUrl: './jobs.component.html',
13 styleUrls: [ './jobs.component.scss' ]
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'
19 jobState?: JobStateClient | 'all'
20 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
22 jobType: JobTypeClient = 'all'
23 jobTypes: JobTypeClient[] = [
27 'activitypub-http-broadcast',
28 'activitypub-http-broadcast-parallel',
29 'activitypub-http-fetcher',
30 'activitypub-http-unicast',
31 'activitypub-refresher',
32 'activitypub-cleaner',
41 'move-to-object-storage',
42 'video-channel-import'
47 sort: SortMeta = { field: 'createdAt', order: -1 }
48 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
51 private notifier: Notifier,
52 private jobsService: JobService
58 this.loadJobStateAndType()
63 return 'JobsComponent'
66 getJobStateClass (state: JobStateClient) {
82 if (this.jobState === 'all' && this.hasGlobalProgress()) return 7
84 if (this.jobState === 'all' || this.hasGlobalProgress()) return 6
89 onJobStateOrTypeChanged () {
90 this.pagination.start = 0
93 this.saveJobStateAndType()
96 hasGlobalProgress () {
97 return this.jobType === 'all' || this.jobType === 'video-transcoding'
100 hasProgress (job: Job) {
101 return job.type === 'video-transcoding'
104 getProgress (job: Job) {
105 if (job.state === 'active') return job.progress + '%'
112 this.totalRecords = 0
117 protected reloadData () {
118 let jobState = this.jobState as JobState
119 if (this.jobState === 'all') jobState = null
124 jobType: this.jobType,
125 pagination: this.pagination,
129 next: resultList => {
130 this.jobs = resultList.data
131 this.totalRecords = resultList.total
134 error: err => this.notifier.error(err.message)
138 private loadJobStateAndType () {
139 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
140 if (state) this.jobState = state as JobState
142 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
143 if (type) this.jobType = type as JobType
146 private saveJobStateAndType () {
147 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
148 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)