]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
Fix pagination on rest table
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / jobs / jobs-list / jobs-list.component.ts
... / ...
CommitLineData
1import { Component, OnInit } from '@angular/core'
2import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage'
3import { NotificationsService } from 'angular2-notifications'
4import { SortMeta } from 'primeng/primeng'
5import { Job } from '../../../../../../shared/index'
6import { JobState } from '../../../../../../shared/models'
7import { RestPagination, RestTable } from '../../../shared'
8import { RestExtractor } from '../../../shared/rest/rest-extractor.service'
9import { JobService } from '../shared'
10import { 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})
17export 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.pagination.start = 0
44
45 this.loadData()
46 this.saveJobState()
47 }
48
49 protected loadData () {
50 this.jobsService
51 .getJobs(this.jobState, this.pagination, this.sort)
52 .subscribe(
53 resultList => {
54 this.jobs = resultList.data
55 this.totalRecords = resultList.total
56 },
57
58 err => this.notificationsService.error(this.i18n('Error'), err.message)
59 )
60 }
61
62 private loadJobState () {
63 const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE)
64
65 if (result) this.jobState = result as JobState
66 }
67
68 private saveJobState () {
69 peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
70 }
71}