]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
Add ability to list jobs
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / jobs / jobs-list / jobs-list.component.ts
1 import { Component } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { SortMeta } from 'primeng/primeng'
4 import { Job } from '../../../../../../shared/index'
5 import { RestPagination, RestTable } from '../../../shared'
6 import { JobService } from '../shared'
7 import { RestExtractor } from '../../../shared/rest/rest-extractor.service'
8
9 @Component({
10 selector: 'my-jobs-list',
11 templateUrl: './jobs-list.component.html',
12 styleUrls: [ ]
13 })
14 export class JobsListComponent extends RestTable {
15 jobs: Job[] = []
16 totalRecords = 0
17 rowsPerPage = 10
18 sort: SortMeta = { field: 'createdAt', order: 1 }
19 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
20
21 constructor (
22 private notificationsService: NotificationsService,
23 private restExtractor: RestExtractor,
24 private jobsService: JobService
25 ) {
26 super()
27 }
28
29 protected loadData () {
30 this.jobsService
31 .getJobs(this.pagination, this.sort)
32 .map(res => this.restExtractor.applyToResultListData(res, this.formatJob.bind(this)))
33 .subscribe(
34 resultList => {
35 this.jobs = resultList.data
36 this.totalRecords = resultList.total
37 },
38
39 err => this.notificationsService.error('Error', err.message)
40 )
41 }
42
43 private formatJob (job: Job) {
44 const handlerInputData = JSON.stringify(job.handlerInputData)
45
46 return Object.assign(job, {
47 handlerInputData
48 })
49 }
50 }