1 import { Component, OnInit } from '@angular/core'
2 import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-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 { JobTypeClient } from '../../../../types/job-type-client.type'
14 templateUrl: './jobs.component.html',
15 styleUrls: [ './jobs.component.scss' ]
17 export class JobsComponent extends RestTable implements OnInit {
18 private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
19 private static JOB_STATE_LOCAL_STORAGE_TYPE = 'jobs-list-type'
21 jobState: JobState = 'waiting'
22 jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
24 jobType: JobTypeClient = 'all'
25 jobTypes: JobTypeClient[] = [
28 'activitypub-http-broadcast',
29 'activitypub-http-fetcher',
30 'activitypub-http-unicast',
36 '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,
54 this.loadJobStateAndType()
58 onJobStateOrTypeChanged () {
59 this.pagination.start = 0
62 this.saveJobStateAndType()
65 protected loadData () {
67 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
70 this.jobs = resultList.data
71 this.totalRecords = resultList.total
74 err => this.notifier.error(err.message)
78 private loadJobStateAndType () {
79 const state = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE)
80 if (state) this.jobState = state as JobState
82 const type = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE)
83 if (type) this.jobType = type as JobType
86 private saveJobStateAndType () {
87 peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
88 peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE, this.jobType)