]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/system/jobs/jobs.component.ts
add loop setting for playlists, and use sessionStorage
[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'
1061c73f 10import { JobTypeClient } from '../../../../types/job-type-client.type'
5cd80545
C
11
12@Component({
2c22613c
C
13 selector: 'my-jobs',
14 templateUrl: './jobs.component.html',
15 styleUrls: [ './jobs.component.scss' ]
5cd80545 16})
2c22613c 17export class JobsComponent extends RestTable implements OnInit {
ab998f7b 18 private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state'
1061c73f 19 private static JOB_STATE_LOCAL_STORAGE_TYPE = 'jobs-list-type'
ab998f7b 20
94831479
C
21 jobState: JobState = 'waiting'
22 jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ]
1061c73f
C
23
24 jobType: JobTypeClient = 'all'
25 jobTypes: JobTypeClient[] = [
26 'all',
27 'activitypub-follow',
28 'activitypub-http-broadcast',
29 'activitypub-http-fetcher',
30 'activitypub-http-unicast',
31 'email',
32 'video-transcoding',
33 'video-file-import',
34 'video-import',
35 'videos-views',
36 'activitypub-refresher'
37 ]
38
5cd80545 39 jobs: Job[] = []
ab998f7b
C
40 totalRecords: number
41 rowsPerPage = 10
94a5ff8a 42 sort: SortMeta = { field: 'createdAt', order: -1 }
5cd80545
C
43 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
44
45 constructor (
f8b2c1b4 46 private notifier: Notifier,
b1d40cff
C
47 private jobsService: JobService,
48 private i18n: I18n
5cd80545
C
49 ) {
50 super()
51 }
52
cd83ea1b 53 ngOnInit () {
1061c73f 54 this.loadJobStateAndType()
24b9417c 55 this.initialize()
cd83ea1b
C
56 }
57
1061c73f 58 onJobStateOrTypeChanged () {
6d8c70aa
C
59 this.pagination.start = 0
60
94a5ff8a 61 this.loadData()
1061c73f 62 this.saveJobStateAndType()
94a5ff8a
C
63 }
64
5cd80545
C
65 protected loadData () {
66 this.jobsService
1061c73f 67 .getJobs(this.jobState, this.jobType, this.pagination, this.sort)
5cd80545
C
68 .subscribe(
69 resultList => {
70 this.jobs = resultList.data
71 this.totalRecords = resultList.total
72 },
73
f8b2c1b4 74 err => this.notifier.error(err.message)
5cd80545
C
75 )
76 }
ab998f7b 77
1061c73f
C
78 private loadJobStateAndType () {
79 const state = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE)
80 if (state) this.jobState = state as JobState
ab998f7b 81
1061c73f
C
82 const type = peertubeLocalStorage.getItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE)
83 if (type) this.jobType = type as JobType
ab998f7b
C
84 }
85
1061c73f 86 private saveJobStateAndType () {
2c22613c 87 peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState)
1061c73f 88 peertubeLocalStorage.setItem(JobsComponent.JOB_STATE_LOCAL_STORAGE_TYPE, this.jobType)
ab998f7b 89 }
5cd80545 90}