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 = 'waiting'
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',
42 sort: SortMeta = { field: 'createdAt', order: -1 }
43 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
46 private notifier: Notifier,
47 private jobsService: JobService
53 this.loadJobStateAndType()
58 return 'JobsComponent'
61 getJobStateClass (state: JobStateClient) {
76 onJobStateOrTypeChanged () {
77 this.pagination.start = 0
80 this.saveJobStateAndType()
83 protected loadData () {
85 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
88 this.jobs = resultList.data
89 this.totalRecords = resultList.total
92 err => this.notifier.error(err.message)
96 private loadJobStateAndType () {
97 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
98 if (state) this.jobState = state as JobState
100 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
101 if (type) this.jobType = type as JobType
104 private saveJobStateAndType () {
105 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
106 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)