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[] = [
26 'activitypub-http-broadcast',
27 'activitypub-http-fetcher',
28 'activitypub-http-unicast',
34 'activitypub-refresher',
41 sort: SortMeta = { field: 'createdAt', order: -1 }
42 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
45 private notifier: Notifier,
46 private jobsService: JobService
52 this.loadJobStateAndType()
57 return 'JobsComponent'
60 getJobStateClass (state: JobStateClient) {
76 return this.jobState === 'all' ? 5 : 4
79 onJobStateOrTypeChanged () {
80 this.pagination.start = 0
83 this.saveJobStateAndType()
87 return this.jobType === 'all' || this.jobType === 'video-transcoding'
90 getProgress (job: Job) {
91 if (job.state === 'active') return job.progress + '%'
96 protected loadData () {
97 let jobState = this.jobState as JobState
98 if (this.jobState === 'all') jobState = null
103 jobType: this.jobType,
104 pagination: this.pagination,
109 this.jobs = resultList.data
110 this.totalRecords = resultList.total
113 err => this.notifier.error(err.message)
117 private loadJobStateAndType () {
118 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
119 if (state) this.jobState = state as JobState
121 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
122 if (type) this.jobType = type as JobType
125 private saveJobStateAndType () {
126 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
127 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)