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