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