1 import { Component, OnInit } from '@angular/core'
2 import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
3 import { Notifier } from '@app/core'
4 import { SortMeta } from 'primeng/api'
5 import { Job, JobType } from '../../../../../../shared/index'
6 import { JobState } from '../../../../../../shared/models'
7 import { RestPagination, RestTable } from '../../../shared'
8 import { JobService } from './job.service'
9 import { I18n } from '@ngx-translate/i18n-polyfill'
10 import { JobStateClient } from '../../../../types/job-state-client.type'
11 import { JobTypeClient } from '../../../../types/job-type-client.type'
15 templateUrl: './jobs.component.html',
16 styleUrls: [ './jobs.component.scss' ]
18 export class JobsComponent extends RestTable implements OnInit {
19 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
20 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
22 jobState: JobStateClient = 'waiting'
23 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
25 jobType: JobTypeClient = 'all'
26 jobTypes: JobTypeClient[] = [
29 'activitypub-http-broadcast',
30 'activitypub-http-fetcher',
31 'activitypub-http-unicast',
37 'activitypub-refresher',
44 sort: SortMeta = { field: 'createdAt', order: -1 }
45 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
48 private notifier: Notifier,
49 private jobsService: JobService,
56 this.loadJobStateAndType()
60 onJobStateOrTypeChanged () {
61 this.pagination.start = 0
64 this.saveJobStateAndType()
67 protected loadData () {
69 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
72 this.jobs = resultList.data
73 this.totalRecords = resultList.total
76 err => this.notifier.error(err.message)
80 private loadJobStateAndType () {
81 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
82 if (state) this.jobState = state as JobState
84 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
85 if (type) this.jobType = type as JobType
88 private saveJobStateAndType () {
89 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
90 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)