aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/jobs
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-30 10:51:13 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-30 10:55:06 +0100
commit5cd80545422bba855cc9a730a2e13cc9d982c34b (patch)
tree9a60cd7c9218c296a1460938d11e3bce784f7cc0 /client/src/app/+admin/jobs
parent1f3e9feca2caf68024168b0ea9ed39d8438fa235 (diff)
downloadPeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.tar.gz
PeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.tar.zst
PeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.zip
Add ability to list jobs
Diffstat (limited to 'client/src/app/+admin/jobs')
-rw-r--r--client/src/app/+admin/jobs/index.ts1
-rw-r--r--client/src/app/+admin/jobs/job.component.ts6
-rw-r--r--client/src/app/+admin/jobs/job.routes.ts35
-rw-r--r--client/src/app/+admin/jobs/jobs-list/index.ts1
-rw-r--r--client/src/app/+admin/jobs/jobs-list/jobs-list.component.html18
-rw-r--r--client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts50
-rw-r--r--client/src/app/+admin/jobs/shared/index.ts1
-rw-r--r--client/src/app/+admin/jobs/shared/job.service.ts30
8 files changed, 142 insertions, 0 deletions
diff --git a/client/src/app/+admin/jobs/index.ts b/client/src/app/+admin/jobs/index.ts
new file mode 100644
index 000000000..7b5271956
--- /dev/null
+++ b/client/src/app/+admin/jobs/index.ts
@@ -0,0 +1 @@
export * from './'
diff --git a/client/src/app/+admin/jobs/job.component.ts b/client/src/app/+admin/jobs/job.component.ts
new file mode 100644
index 000000000..bc80c9a6a
--- /dev/null
+++ b/client/src/app/+admin/jobs/job.component.ts
@@ -0,0 +1,6 @@
1import { Component } from '@angular/core'
2
3@Component({
4 template: '<router-outlet></router-outlet>'
5})
6export class JobsComponent {}
diff --git a/client/src/app/+admin/jobs/job.routes.ts b/client/src/app/+admin/jobs/job.routes.ts
new file mode 100644
index 000000000..a7bf2b221
--- /dev/null
+++ b/client/src/app/+admin/jobs/job.routes.ts
@@ -0,0 +1,35 @@
1import { Routes } from '@angular/router'
2
3import { UserRightGuard } from '../../core'
4import { FollowingAddComponent } from './following-add'
5import { UserRight } from '../../../../../shared'
6import { FollowingListComponent } from './following-list/following-list.component'
7import { JobsComponent } from './job.component'
8import { JobsListComponent } from './jobs-list/jobs-list.component'
9
10export const JobsRoutes: Routes = [
11 {
12 path: 'jobs',
13 component: JobsComponent,
14 canActivate: [ UserRightGuard ],
15 data: {
16 userRight: UserRight.MANAGE_JOBS
17 },
18 children: [
19 {
20 path: '',
21 redirectTo: 'list',
22 pathMatch: 'full'
23 },
24 {
25 path: 'list',
26 component: JobsListComponent,
27 data: {
28 meta: {
29 title: 'Jobs list'
30 }
31 }
32 }
33 ]
34 }
35]
diff --git a/client/src/app/+admin/jobs/jobs-list/index.ts b/client/src/app/+admin/jobs/jobs-list/index.ts
new file mode 100644
index 000000000..cf590a6f8
--- /dev/null
+++ b/client/src/app/+admin/jobs/jobs-list/index.ts
@@ -0,0 +1 @@
export * from './jobs-list.component'
diff --git a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.html b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.html
new file mode 100644
index 000000000..a90267172
--- /dev/null
+++ b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.html
@@ -0,0 +1,18 @@
1<div class="row">
2 <div class="content-padding">
3 <h3>Jobs list</h3>
4
5 <p-dataTable
6 [value]="jobs" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
7 sortField="createdAt" (onLazyLoad)="loadLazy($event)"
8 >
9 <p-column field="id" header="ID"></p-column>
10 <p-column field="category" header="Category"></p-column>
11 <p-column field="handlerName" header="Handler name"></p-column>
12 <p-column field="handlerInputData" header="Input data"></p-column>
13 <p-column field="state" header="State"></p-column>
14 <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
15 <p-column field="updatedAt" header="Updated date"></p-column>
16 </p-dataTable>
17 </div>
18</div>
diff --git a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
new file mode 100644
index 000000000..88fe259fb
--- /dev/null
+++ b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts
@@ -0,0 +1,50 @@
1import { Component } from '@angular/core'
2import { NotificationsService } from 'angular2-notifications'
3import { SortMeta } from 'primeng/primeng'
4import { Job } from '../../../../../../shared/index'
5import { RestPagination, RestTable } from '../../../shared'
6import { JobService } from '../shared'
7import { RestExtractor } from '../../../shared/rest/rest-extractor.service'
8
9@Component({
10 selector: 'my-jobs-list',
11 templateUrl: './jobs-list.component.html',
12 styleUrls: [ ]
13})
14export 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}
diff --git a/client/src/app/+admin/jobs/shared/index.ts b/client/src/app/+admin/jobs/shared/index.ts
new file mode 100644
index 000000000..609439e5c
--- /dev/null
+++ b/client/src/app/+admin/jobs/shared/index.ts
@@ -0,0 +1 @@
export * from './job.service'
diff --git a/client/src/app/+admin/jobs/shared/job.service.ts b/client/src/app/+admin/jobs/shared/job.service.ts
new file mode 100644
index 000000000..49f1ab6f5
--- /dev/null
+++ b/client/src/app/+admin/jobs/shared/job.service.ts
@@ -0,0 +1,30 @@
1import { HttpClient, HttpParams } from '@angular/common/http'
2import { Injectable } from '@angular/core'
3import { SortMeta } from 'primeng/primeng'
4import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map'
6import { Observable } from 'rxjs/Observable'
7import { ResultList } from '../../../../../../shared'
8import { Job } from '../../../../../../shared/models/job.model'
9
10import { RestExtractor, RestPagination, RestService } from '../../../shared'
11
12@Injectable()
13export class JobService {
14 private static BASE_JOB_URL = API_URL + '/api/v1/jobs'
15
16 constructor (
17 private authHttp: HttpClient,
18 private restService: RestService,
19 private restExtractor: RestExtractor
20 ) {}
21
22 getJobs (pagination: RestPagination, sort: SortMeta): Observable<ResultList<Job>> {
23 let params = new HttpParams()
24 params = this.restService.addRestGetParams(params, pagination, sort)
25
26 return this.authHttp.get<ResultList<Job>>(JobService.BASE_JOB_URL, { params })
27 .map(res => this.restExtractor.convertResultListDateToHuman(res))
28 .catch(err => this.restExtractor.handleError(err))
29 }
30}