]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/system/jobs/jobs.component.ts
Reorganize client shared modules
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { Notifier, RestPagination, RestTable } from '@app/core'
4 import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { Job, JobState, JobType } from '@shared/models'
7 import { JobStateClient } from '../../../../types/job-state-client.type'
8 import { JobTypeClient } from '../../../../types/job-type-client.type'
9 import { JobService } from './job.service'
10
11 @Component({
12 selector: 'my-jobs',
13 templateUrl: './jobs.component.html',
14 styleUrls: [ './jobs.component.scss' ]
15 })
16 export class JobsComponent extends RestTable implements OnInit {
17 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
18 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
19
20 jobState: JobStateClient = 'waiting'
21 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
22
23 jobType: JobTypeClient = 'all'
24 jobTypes: JobTypeClient[] = [
25 'all',
26 'activitypub-follow',
27 'activitypub-http-broadcast',
28 'activitypub-http-fetcher',
29 'activitypub-http-unicast',
30 'email',
31 'video-transcoding',
32 'video-file-import',
33 'video-import',
34 'videos-views',
35 'activitypub-refresher',
36 'video-redundancy'
37 ]
38
39 jobs: Job[] = []
40 totalRecords: number
41 sort: SortMeta = { field: 'createdAt', order: -1 }
42 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
43
44 constructor (
45 private notifier: Notifier,
46 private jobsService: JobService,
47 private i18n: I18n
48 ) {
49 super()
50 }
51
52 ngOnInit () {
53 this.loadJobStateAndType()
54 this.initialize()
55 }
56
57 getIdentifier () {
58 return 'JobsComponent'
59 }
60
61 onJobStateOrTypeChanged () {
62 this.pagination.start = 0
63
64 this.loadData()
65 this.saveJobStateAndType()
66 }
67
68 protected loadData () {
69 this.jobsService
70 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
71 .subscribe(
72 resultList => {
73 this.jobs = resultList.data
74 this.totalRecords = resultList.total
75 },
76
77 err => this.notifier.error(err.message)
78 )
79 }
80
81 private loadJobStateAndType () {
82 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
83 if (state) this.jobState = state as JobState
84
85 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
86 if (type) this.jobType = type as JobType
87 }
88
89 private saveJobStateAndType () {
90 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
91 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
92 }
93 }