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

70 lines
1.9 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-local-storage'
import { Notifier } from '@app/core'
2017-11-30 10:51:13 +01:00
import { SortMeta } from 'primeng/primeng'
import { Job } 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'
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 {
2018-02-23 14:36:16 +01:00
private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
2018-07-10 17:02:20 +02:00
jobState: JobState = 'waiting'
jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
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 () {
2018-02-23 14:36:16 +01:00
this.loadJobState()
2018-10-08 15:51:38 +02:00
this.initialize()
2017-12-08 14:34:17 +01:00
}
onJobStateChanged () {
2018-07-24 15:33:18 +02:00
this.pagination.start = 0
this.loadData()
2018-02-23 14:36:16 +01:00
this.saveJobState()
}
2017-11-30 10:51:13 +01:00
protected loadData () {
this.jobsService
.getJobs(this.jobState, 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
private loadJobState () {
2019-04-11 10:05:43 +02:00
const result = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE)
2018-02-23 14:36:16 +01:00
if (result) this.jobState = result as JobState
}
private saveJobState () {
2019-04-11 10:05:43 +02:00
peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
2018-02-23 14:36:16 +01:00
}
2017-11-30 10:51:13 +01:00
}