]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
Switch to bull
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / jobs / jobs-list / jobs-list.component.ts
CommitLineData
cd83ea1b 1import { Component, OnInit } from '@angular/core'
0bd78bf3 2import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
5cd80545
C
3import { NotificationsService } from 'angular2-notifications'
4import { SortMeta } from 'primeng/primeng'
5import { Job } from '../../../../../../shared/index'
94a5ff8a 6import { JobState } from '../../../../../../shared/models'
5cd80545 7import { RestPagination, RestTable } from '../../../shared'
5cd80545 8import { RestExtractor } from '../../../shared/rest/rest-extractor.service'
0bd78bf3 9import { JobService } from '../shared'
b1d40cff 10import { I18n } from '@ngx-translate/i18n-polyfill'
5cd80545
C
11
12@Component({
13 selector: 'my-jobs-list',
14 templateUrl: './jobs-list.component.html',
cd83ea1b 15 styleUrls: [ './jobs-list.component.scss' ]
5cd80545 16})
cd83ea1b 17export class JobsListComponent extends RestTable implements OnInit {
ab998f7b
C
18 private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
19
94a5ff8a
C
20 jobState: JobState = 'inactive'
21 jobStates: JobState[] = [ 'active', 'complete', 'failed', 'inactive', 'delayed' ]
5cd80545 22 jobs: Job[] = []
ab998f7b
C
23 totalRecords: number
24 rowsPerPage = 10
94a5ff8a 25 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
26 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
27
28 constructor (
29 private notificationsService: NotificationsService,
30 private restExtractor: RestExtractor,
b1d40cff
C
31 private jobsService: JobService,
32 private i18n: I18n
5cd80545
C
33 ) {
34 super()
35 }
36
cd83ea1b 37 ngOnInit () {
ab998f7b
C
38 this.loadJobState()
39 this.loadSort()
cd83ea1b
C
40 }
41
94a5ff8a
C
42 onJobStateChanged () {
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
b1d40cff 56 err => this.notificationsService.error(this.i18n('Error'), err.message)
5cd80545
C
57 )
58 }
ab998f7b
C
59
60 private loadJobState () {
0bd78bf3 61 const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE)
ab998f7b
C
62
63 if (result) this.jobState = result as JobState
64 }
65
66 private saveJobState () {
0bd78bf3 67 peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
ab998f7b 68 }
5cd80545 69}