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 { escapeHTML } from '@shared/core-utils/renderer'
6 import { Job, JobState, JobType } from '@shared/models'
7 import { JobStateClient } from '../../../../types/job-state-client.type'
8 import { JobTypeClient } from '../../../../types/job-type-client.type'
9 import { JobService } from './job.service'
13 templateUrl: './jobs.component.html',
14 styleUrls: [ './jobs.component.scss' ]
16 export class JobsComponent extends RestTable implements OnInit {
17 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
18 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
20 jobState?: JobStateClient | 'all'
21 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
23 jobType: JobTypeClient = 'all'
24 jobTypes: JobTypeClient[] = [
27 'activitypub-cleaner',
29 'activitypub-http-broadcast-parallel',
30 'activitypub-http-broadcast',
31 'activitypub-http-fetcher',
32 'activitypub-http-unicast',
33 'activitypub-refresher',
35 'after-video-channel-import',
38 'manage-video-torrent',
39 'move-to-object-storage',
41 'video-channel-import',
46 'video-studio-edition',
53 sort: SortMeta = { field: 'createdAt', order: -1 }
54 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
57 private notifier: Notifier,
58 private jobsService: JobService
64 this.loadJobStateAndType()
69 return 'JobsComponent'
72 getJobStateClass (state: JobStateClient) {
88 if (this.jobState === 'all' && this.hasGlobalProgress()) return 7
90 if (this.jobState === 'all' || this.hasGlobalProgress()) return 6
95 onJobStateOrTypeChanged () {
96 this.pagination.start = 0
99 this.saveJobStateAndType()
102 hasGlobalProgress () {
103 return this.jobType === 'all' || this.jobType === 'video-transcoding'
106 hasProgress (job: Job) {
107 return job.type === 'video-transcoding'
110 getProgress (job: Job) {
111 if (job.state === 'active') return job.progress + '%'
118 this.totalRecords = 0
123 protected reloadDataInternal () {
124 let jobState = this.jobState as JobState
125 if (this.jobState === 'all') jobState = null
130 jobType: this.jobType,
131 pagination: this.pagination,
135 next: resultList => {
136 this.jobs = resultList.data
137 this.totalRecords = resultList.total
140 error: err => this.notifier.error(err.message)
144 private loadJobStateAndType () {
145 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
147 // FIXME: We use <ng-option> that doesn't escape HTML
148 // https://github.com/ng-select/ng-select/issues/1363
149 if (state) this.jobState = escapeHTML(state) as JobState
151 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
152 if (type) this.jobType = type as JobType
155 private saveJobStateAndType () {
156 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
157 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)