PeerTube/client/src/app/+admin/system/jobs/jobs.component.ts

93 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-12-08 14:34:17 +01:00
import { Component, OnInit } from '@angular/core'
import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
import { Notifier } from '@app/core'
2019-07-25 10:44:21 +02:00
import { SortMeta } from 'primeng/api'
2019-12-04 14:49:59 +01:00
import { Job, JobType } from '../../../../../../shared/index'
import { JobState } from '../../../../../../shared/models'
2017-11-30 10:51:13 +01:00
import { RestPagination, RestTable } from '../../../shared'
2019-04-11 10:05:43 +02:00
import { JobService } from './job.service'
2018-06-04 16:21:17 +02:00
import { I18n } from '@ngx-translate/i18n-polyfill'
import { JobStateClient } from '../../../../types/job-state-client.type'
2019-12-04 14:49:59 +01:00
import { JobTypeClient } from '../../../../types/job-type-client.type'
2017-11-30 10:51:13 +01:00
@Component({
2019-04-11 10:05:43 +02:00
selector: 'my-jobs',
templateUrl: './jobs.component.html',
styleUrls: [ './jobs.component.scss' ]
2017-11-30 10:51:13 +01:00
})
2019-04-11 10:05:43 +02:00
export class JobsComponent extends RestTable implements OnInit {
2020-01-10 10:11:28 +01:00
private static LOCAL_STORAGE_STATE = 'jobs-list-state'
private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
2018-02-23 14:36:16 +01:00
jobState: JobStateClient = 'waiting'
jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
2019-12-04 14:49:59 +01:00
jobType: JobTypeClient = 'all'
jobTypes: JobTypeClient[] = [
'all',
'activitypub-follow',
'activitypub-http-broadcast',
'activitypub-http-fetcher',
'activitypub-http-unicast',
'email',
'video-transcoding',
'video-file-import',
'video-import',
'videos-views',
2020-01-10 10:11:28 +01:00
'activitypub-refresher',
'video-redundancy'
2019-12-04 14:49:59 +01:00
]
2017-11-30 10:51:13 +01:00
jobs: Job[] = []
2018-02-23 14:36:16 +01:00
totalRecords: number
rowsPerPage = 10
sort: SortMeta = { field: 'createdAt', order: -1 }
2017-11-30 10:51:13 +01:00
pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
constructor (
private notifier: Notifier,
2018-06-04 16:21:17 +02:00
private jobsService: JobService,
private i18n: I18n
2017-11-30 10:51:13 +01:00
) {
super()
}
2017-12-08 14:34:17 +01:00
ngOnInit () {
2019-12-04 14:49:59 +01:00
this.loadJobStateAndType()
2018-10-08 15:51:38 +02:00
this.initialize()
2017-12-08 14:34:17 +01:00
}
2019-12-04 14:49:59 +01:00
onJobStateOrTypeChanged () {
2018-07-24 15:33:18 +02:00
this.pagination.start = 0
this.loadData()
2019-12-04 14:49:59 +01:00
this.saveJobStateAndType()
}
2017-11-30 10:51:13 +01:00
protected loadData () {
this.jobsService
2019-12-04 14:49:59 +01:00
.getJobs(this.jobState, this.jobType, this.pagination, this.sort)
2017-11-30 10:51:13 +01:00
.subscribe(
resultList => {
this.jobs = resultList.data
this.totalRecords = resultList.total
},
err => this.notifier.error(err.message)
2017-11-30 10:51:13 +01:00
)
}
2018-02-23 14:36:16 +01:00
2019-12-04 14:49:59 +01:00
private loadJobStateAndType () {
2020-01-10 10:11:28 +01:00
const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
2019-12-04 14:49:59 +01:00
if (state) this.jobState = state as JobState
2018-02-23 14:36:16 +01:00
2020-01-10 10:11:28 +01:00
const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
2019-12-04 14:49:59 +01:00
if (type) this.jobType = type as JobType
2018-02-23 14:36:16 +01:00
}
2019-12-04 14:49:59 +01:00
private saveJobStateAndType () {
2020-01-10 10:11:28 +01:00
peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
2018-02-23 14:36:16 +01:00
}
2017-11-30 10:51:13 +01:00
}