]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / system / jobs / jobs.component.ts
CommitLineData
cd83ea1b 1import { Component, OnInit } from '@angular/core'
88a7f93f 2import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
f8b2c1b4 3import { Notifier } from '@app/core'
41b15c89 4import { SortMeta } from 'primeng/api'
1061c73f 5import { Job, JobType } from '../../../../../../shared/index'
94a5ff8a 6import { JobState } from '../../../../../../shared/models'
5cd80545 7import { RestPagination, RestTable } from '../../../shared'
2c22613c 8import { JobService } from './job.service'
b1d40cff 9import { I18n } from '@ngx-translate/i18n-polyfill'
42712121 10import { JobStateClient } from '../../../../types/job-state-client.type'
1061c73f 11import { JobTypeClient } from '../../../../types/job-type-client.type'
5cd80545
C
12
13@Component({
2c22613c
C
14 selector: 'my-jobs',
15 templateUrl: './jobs.component.html',
16 styleUrls: [ './jobs.component.scss' ]
5cd80545 17})
2c22613c 18export class JobsComponent extends RestTable implements OnInit {
b764380a
C
19 private static LOCAL_STORAGE_STATE = 'jobs-list-state'
20 private static LOCAL_STORAGE_TYPE = 'jobs-list-type'
ab998f7b 21
42712121
JM
22 jobState: JobStateClient = 'waiting'
23 jobStates: JobStateClient[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
1061c73f
C
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',
b764380a
C
37 'activitypub-refresher',
38 'video-redundancy'
1061c73f
C
39 ]
40
5cd80545 41 jobs: Job[] = []
ab998f7b
C
42 totalRecords: number
43 rowsPerPage = 10
94a5ff8a 44 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
45 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
46
47 constructor (
f8b2c1b4 48 private notifier: Notifier,
b1d40cff
C
49 private jobsService: JobService,
50 private i18n: I18n
5cd80545
C
51 ) {
52 super()
53 }
54
cd83ea1b 55 ngOnInit () {
1061c73f 56 this.loadJobStateAndType()
24b9417c 57 this.initialize()
cd83ea1b
C
58 }
59
1061c73f 60 onJobStateOrTypeChanged () {
6d8c70aa
C
61 this.pagination.start = 0
62
94a5ff8a 63 this.loadData()
1061c73f 64 this.saveJobStateAndType()
94a5ff8a
C
65 }
66
5cd80545
C
67 protected loadData () {
68 this.jobsService
1061c73f 69 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
5cd80545
C
70 .subscribe(
71 resultList => {
72 this.jobs = resultList.data
73 this.totalRecords = resultList.total
74 },
75
f8b2c1b4 76 err => this.notifier.error(err.message)
5cd80545
C
77 )
78 }
ab998f7b 79
1061c73f 80 private loadJobStateAndType () {
b764380a 81 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
1061c73f 82 if (state) this.jobState = state as JobState
ab998f7b 83
b764380a 84 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
1061c73f 85 if (type) this.jobType = type as JobType
ab998f7b
C
86 }
87
1061c73f 88 private saveJobStateAndType () {
b764380a
C
89 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
90 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 91 }
5cd80545 92}