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