]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
Proxify local storage and handle if it is unavailable
[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'
5cd80545
C
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
C
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
26
27 constructor (
28 private notificationsService: NotificationsService,
29 private restExtractor: RestExtractor,
30 private jobsService: JobService
31 ) {
32 super()
33 }
34
cd83ea1b 35 ngOnInit () {
ab998f7b
C
36 this.loadJobState()
37 this.loadSort()
cd83ea1b
C
38 }
39
94a5ff8a
C
40 onJobStateChanged () {
41 this.loadData()
ab998f7b 42 this.saveJobState()
94a5ff8a
C
43 }
44
5cd80545
C
45 protected loadData () {
46 this.jobsService
94a5ff8a 47 .getJobs(this.jobState, this.pagination, this.sort)
5cd80545
C
48 .subscribe(
49 resultList => {
50 this.jobs = resultList.data
51 this.totalRecords = resultList.total
52 },
53
54 err => this.notificationsService.error('Error', err.message)
55 )
56 }
ab998f7b
C
57
58 private loadJobState () {
0bd78bf3 59 const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE)
ab998f7b
C
60
61 if (result) this.jobState = result as JobState
62 }
63
64 private saveJobState () {
0bd78bf3 65 peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
ab998f7b 66 }
5cd80545 67}