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