]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
Update client dependencies
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
CommitLineData
cd83ea1b 1import { Component, OnInit } from '@angular/core'
0bd78bf3 2import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
f8b2c1b4 3import { Notifier } from '@app/core'
41b15c89 4import { SortMeta } from 'primeng/api'
5cd80545 5import { Job } from '../../../../../../shared/index'
94a5ff8a 6import { JobState } from '../../../../../../shared/models'
5cd80545 7import { RestPagination, RestTable } from '../../../shared'
2c22613c 8import { JobService } from './job.service'
b1d40cff 9import { I18n } from '@ngx-translate/i18n-polyfill'
5cd80545
C
10
11@Component({
2c22613c
C
12 selector: 'my-jobs',
13 templateUrl: './jobs.component.html',
14 styleUrls: [ './jobs.component.scss' ]
5cd80545 15})
2c22613c 16export class JobsComponent extends RestTable implements OnInit {
ab998f7b
C
17 private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
18
94831479
C
19 jobState: JobState = 'waiting'
20 jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
5cd80545 21 jobs: Job[] = []
ab998f7b
C
22 totalRecords: number
23 rowsPerPage = 10
94a5ff8a 24 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
26
27 constructor (
f8b2c1b4 28 private notifier: Notifier,
b1d40cff
C
29 private jobsService: JobService,
30 private i18n: I18n
5cd80545
C
31 ) {
32 super()
33 }
34
cd83ea1b 35 ngOnInit () {
ab998f7b 36 this.loadJobState()
24b9417c 37 this.initialize()
cd83ea1b
C
38 }
39
94a5ff8a 40 onJobStateChanged () {
6d8c70aa
C
41 this.pagination.start = 0
42
94a5ff8a 43 this.loadData()
ab998f7b 44 this.saveJobState()
94a5ff8a
C
45 }
46
5cd80545
C
47 protected loadData () {
48 this.jobsService
94a5ff8a 49 .getJobs(this.jobState, this.pagination, this.sort)
5cd80545
C
50 .subscribe(
51 resultList => {
52 this.jobs = resultList.data
53 this.totalRecords = resultList.total
54 },
55
f8b2c1b4 56 err => this.notifier.error(err.message)
5cd80545
C
57 )
58 }
ab998f7b
C
59
60 private loadJobState () {
2c22613c 61 const result = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE)
ab998f7b
C
62
63 if (result) this.jobState = result as JobState
64 }
65
66 private saveJobState () {
2c22613c 67 peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
ab998f7b 68 }
5cd80545 69}