]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
provide specific engine boundaries for nodejs and yarn
[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 42 totalRecords: number
94a5ff8a 43 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
44 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
45
46 constructor (
f8b2c1b4 47 private notifier: Notifier,
b1d40cff
C
48 private jobsService: JobService,
49 private i18n: I18n
5cd80545
C
50 ) {
51 super()
52 }
53
cd83ea1b 54 ngOnInit () {
1061c73f 55 this.loadJobStateAndType()
24b9417c 56 this.initialize()
cd83ea1b
C
57 }
58
8e11a1b3
C
59 getIdentifier () {
60 return 'JobsComponent'
61 }
62
1061c73f 63 onJobStateOrTypeChanged () {
6d8c70aa
C
64 this.pagination.start = 0
65
94a5ff8a 66 this.loadData()
1061c73f 67 this.saveJobStateAndType()
94a5ff8a
C
68 }
69
5cd80545
C
70 protected loadData () {
71 this.jobsService
1061c73f 72 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
5cd80545
C
73 .subscribe(
74 resultList => {
75 this.jobs = resultList.data
76 this.totalRecords = resultList.total
77 },
78
f8b2c1b4 79 err => this.notifier.error(err.message)
5cd80545
C
80 )
81 }
ab998f7b 82
1061c73f 83 private loadJobStateAndType () {
b764380a 84 const state = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_STATE)
1061c73f 85 if (state) this.jobState = state as JobState
ab998f7b 86
b764380a 87 const type = peertubeLocalStorage.getItem(JobsComponent.LOCAL_STORAGE_TYPE)
1061c73f 88 if (type) this.jobType = type as JobType
ab998f7b
C
89 }
90
1061c73f 91 private saveJobStateAndType () {
b764380a
C
92 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_STATE, this.jobState)
93 peertubeLocalStorage.setItem(JobsComponent.LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 94 }
5cd80545 95}