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-fetcher',
29 'activitypub-http-unicast',
30 'activitypub-refresher',
43 sort: SortMeta = { field: 'createdAt', order: -1 }
44 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
47 private notifier: Notifier,
48 private jobsService: JobService
54 this.loadJobStateAndType()
59 return 'JobsComponent'
62 getJobStateClass (state: JobStateClient) {
78 if (this.jobState === 'all' && this.hasProgress()) return 7
80 if (this.jobState === 'all' || this.hasProgress()) return 6
85 onJobStateOrTypeChanged () {
86 this.pagination.start = 0
89 this.saveJobStateAndType()
93 return this.jobType === 'all' || this.jobType === 'video-transcoding'
96 getProgress (job: Job) {
97 if (job.state === 'active') return job.progress + '%'
104 this.totalRecords = 0
109 protected loadData () {
110 let jobState = this.jobState as JobState
111 if (this.jobState === 'all') jobState = null
116 jobType: this.jobType,
117 pagination: this.pagination,
122 this.jobs = resultList.data
123 this.totalRecords = resultList.total
126 err => this.notifier.error(err.message)
130 private loadJobStateAndType () {
131 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
132 if (state) this.jobState = state as JobState
134 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
135 if (type) this.jobType = type as JobType
138 private saveJobStateAndType () {
139 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
140 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)