From fd8710b897a67518d3a61c319e54b6a65ba443ef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 10 Apr 2019 15:26:33 +0200 Subject: Add logs endpoint --- client/src/app/+admin/jobs/index.ts | 4 -- client/src/app/+admin/jobs/job.component.ts | 6 -- client/src/app/+admin/jobs/job.routes.ts | 32 ---------- client/src/app/+admin/jobs/jobs-list/index.ts | 1 - .../+admin/jobs/jobs-list/jobs-list.component.html | 56 ------------------ .../+admin/jobs/jobs-list/jobs-list.component.scss | 14 ----- .../+admin/jobs/jobs-list/jobs-list.component.ts | 69 ---------------------- client/src/app/+admin/jobs/shared/index.ts | 1 - client/src/app/+admin/jobs/shared/job.service.ts | 46 --------------- client/src/app/+admin/system/jobs/index.ts | 4 ++ client/src/app/+admin/system/jobs/job.service.ts | 46 +++++++++++++++ .../src/app/+admin/system/jobs/jobs.component.html | 56 ++++++++++++++++++ .../src/app/+admin/system/jobs/jobs.component.scss | 14 +++++ .../src/app/+admin/system/jobs/jobs.component.ts | 69 ++++++++++++++++++++++ 14 files changed, 189 insertions(+), 229 deletions(-) delete mode 100644 client/src/app/+admin/jobs/index.ts delete mode 100644 client/src/app/+admin/jobs/job.component.ts delete mode 100644 client/src/app/+admin/jobs/job.routes.ts delete mode 100644 client/src/app/+admin/jobs/jobs-list/index.ts delete mode 100644 client/src/app/+admin/jobs/jobs-list/jobs-list.component.html delete mode 100644 client/src/app/+admin/jobs/jobs-list/jobs-list.component.scss delete mode 100644 client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts delete mode 100644 client/src/app/+admin/jobs/shared/index.ts delete mode 100644 client/src/app/+admin/jobs/shared/job.service.ts create mode 100644 client/src/app/+admin/system/jobs/index.ts create mode 100644 client/src/app/+admin/system/jobs/job.service.ts create mode 100644 client/src/app/+admin/system/jobs/jobs.component.html create mode 100644 client/src/app/+admin/system/jobs/jobs.component.scss create mode 100644 client/src/app/+admin/system/jobs/jobs.component.ts (limited to 'client') diff --git a/client/src/app/+admin/jobs/index.ts b/client/src/app/+admin/jobs/index.ts deleted file mode 100644 index c0e0cc95d..000000000 --- a/client/src/app/+admin/jobs/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './shared' -export * from './jobs-list' -export * from './job.routes' -export * from './job.component' diff --git a/client/src/app/+admin/jobs/job.component.ts b/client/src/app/+admin/jobs/job.component.ts deleted file mode 100644 index bc80c9a6a..000000000 --- a/client/src/app/+admin/jobs/job.component.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Component } from '@angular/core' - -@Component({ - template: '' -}) -export class JobsComponent {} diff --git a/client/src/app/+admin/jobs/job.routes.ts b/client/src/app/+admin/jobs/job.routes.ts deleted file mode 100644 index 331dc2af2..000000000 --- a/client/src/app/+admin/jobs/job.routes.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Routes } from '@angular/router' -import { UserRight } from '../../../../../shared' -import { UserRightGuard } from '../../core' -import { JobsComponent } from './job.component' -import { JobsListComponent } from './jobs-list/jobs-list.component' - -export const JobsRoutes: Routes = [ - { - path: 'jobs', - component: JobsComponent, - canActivate: [ UserRightGuard ], - data: { - userRight: UserRight.MANAGE_JOBS - }, - children: [ - { - path: '', - redirectTo: 'list', - pathMatch: 'full' - }, - { - path: 'list', - component: JobsListComponent, - data: { - meta: { - title: 'Jobs list' - } - } - } - ] - } -] diff --git a/client/src/app/+admin/jobs/jobs-list/index.ts b/client/src/app/+admin/jobs/jobs-list/index.ts deleted file mode 100644 index cf590a6f8..000000000 --- a/client/src/app/+admin/jobs/jobs-list/index.ts +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index 7ed1888e2..000000000 --- a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.html +++ /dev/null @@ -1,56 +0,0 @@ -
-
Jobs list
- -
- -
-
- - - - - - ID - Type - State - Created - Processed on - Finished on - - - - - - - - - - - {{ job.id }} - {{ job.type }} - {{ job.state }} - {{ job.createdAt }} - {{ job.processedOn }} - {{ job.finishedOn }} - - - - - - -
{{ job.data }}
- - - - -
{{ job.error }}
- - -
-
- diff --git a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.scss b/client/src/app/+admin/jobs/jobs-list/jobs-list.component.scss deleted file mode 100644 index ab05f1982..000000000 --- a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.scss +++ /dev/null @@ -1,14 +0,0 @@ -@import '_variables'; -@import '_mixins'; - -.peertube-select-container { - @include peertube-select-container(auto); -} - -pre { - font-size: 11px; -} - -.job-error { - color: red; -} 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 deleted file mode 100644 index b265e1dd6..000000000 --- a/client/src/app/+admin/jobs/jobs-list/jobs-list.component.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Component, OnInit } from '@angular/core' -import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' -import { Notifier } from '@app/core' -import { SortMeta } from 'primeng/primeng' -import { Job } from '../../../../../../shared/index' -import { JobState } from '../../../../../../shared/models' -import { RestPagination, RestTable } from '../../../shared' -import { JobService } from '../shared' -import { I18n } from '@ngx-translate/i18n-polyfill' - -@Component({ - selector: 'my-jobs-list', - templateUrl: './jobs-list.component.html', - styleUrls: [ './jobs-list.component.scss' ] -}) -export class JobsListComponent extends RestTable implements OnInit { - private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state' - - jobState: JobState = 'waiting' - jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] - jobs: Job[] = [] - totalRecords: number - rowsPerPage = 10 - sort: SortMeta = { field: 'createdAt', order: -1 } - pagination: RestPagination = { count: this.rowsPerPage, start: 0 } - - constructor ( - private notifier: Notifier, - private jobsService: JobService, - private i18n: I18n - ) { - super() - } - - ngOnInit () { - this.loadJobState() - this.initialize() - } - - onJobStateChanged () { - this.pagination.start = 0 - - this.loadData() - this.saveJobState() - } - - protected loadData () { - this.jobsService - .getJobs(this.jobState, this.pagination, this.sort) - .subscribe( - resultList => { - this.jobs = resultList.data - this.totalRecords = resultList.total - }, - - err => this.notifier.error(err.message) - ) - } - - private loadJobState () { - const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE) - - if (result) this.jobState = result as JobState - } - - private saveJobState () { - peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState) - } -} diff --git a/client/src/app/+admin/jobs/shared/index.ts b/client/src/app/+admin/jobs/shared/index.ts deleted file mode 100644 index 609439e5c..000000000 --- a/client/src/app/+admin/jobs/shared/index.ts +++ /dev/null @@ -1 +0,0 @@ -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 deleted file mode 100644 index b96dc3359..000000000 --- a/client/src/app/+admin/jobs/shared/job.service.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { catchError, map } from 'rxjs/operators' -import { HttpClient, HttpParams } from '@angular/common/http' -import { Injectable } from '@angular/core' -import { SortMeta } from 'primeng/primeng' -import { Observable } from 'rxjs' -import { ResultList } from '../../../../../../shared' -import { JobState } from '../../../../../../shared/models' -import { Job } from '../../../../../../shared/models/server/job.model' -import { environment } from '../../../../environments/environment' -import { RestExtractor, RestPagination, RestService } from '../../../shared' - -@Injectable() -export class JobService { - private static BASE_JOB_URL = environment.apiUrl + '/api/v1/jobs' - - constructor ( - private authHttp: HttpClient, - private restService: RestService, - private restExtractor: RestExtractor - ) {} - - getJobs (state: JobState, pagination: RestPagination, sort: SortMeta): Observable> { - let params = new HttpParams() - params = this.restService.addRestGetParams(params, pagination, sort) - - return this.authHttp.get>(JobService.BASE_JOB_URL + '/' + state, { params }) - .pipe( - map(res => { - return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ]) - }), - map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)), - map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)), - catchError(err => this.restExtractor.handleError(err)) - ) - } - - private prettyPrintData (obj: Job) { - const data = JSON.stringify(obj.data, null, 2) - - return Object.assign(obj, { data }) - } - - private buildUniqId (obj: Job) { - return Object.assign(obj, { uniqId: `${obj.id}-${obj.type}` }) - } -} diff --git a/client/src/app/+admin/system/jobs/index.ts b/client/src/app/+admin/system/jobs/index.ts new file mode 100644 index 000000000..c0e0cc95d --- /dev/null +++ b/client/src/app/+admin/system/jobs/index.ts @@ -0,0 +1,4 @@ +export * from './shared' +export * from './jobs-list' +export * from './job.routes' +export * from './job.component' diff --git a/client/src/app/+admin/system/jobs/job.service.ts b/client/src/app/+admin/system/jobs/job.service.ts new file mode 100644 index 000000000..b96dc3359 --- /dev/null +++ b/client/src/app/+admin/system/jobs/job.service.ts @@ -0,0 +1,46 @@ +import { catchError, map } from 'rxjs/operators' +import { HttpClient, HttpParams } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { SortMeta } from 'primeng/primeng' +import { Observable } from 'rxjs' +import { ResultList } from '../../../../../../shared' +import { JobState } from '../../../../../../shared/models' +import { Job } from '../../../../../../shared/models/server/job.model' +import { environment } from '../../../../environments/environment' +import { RestExtractor, RestPagination, RestService } from '../../../shared' + +@Injectable() +export class JobService { + private static BASE_JOB_URL = environment.apiUrl + '/api/v1/jobs' + + constructor ( + private authHttp: HttpClient, + private restService: RestService, + private restExtractor: RestExtractor + ) {} + + getJobs (state: JobState, pagination: RestPagination, sort: SortMeta): Observable> { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp.get>(JobService.BASE_JOB_URL + '/' + state, { params }) + .pipe( + map(res => { + return this.restExtractor.convertResultListDateToHuman(res, [ 'createdAt', 'processedOn', 'finishedOn' ]) + }), + map(res => this.restExtractor.applyToResultListData(res, this.prettyPrintData)), + map(res => this.restExtractor.applyToResultListData(res, this.buildUniqId)), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + private prettyPrintData (obj: Job) { + const data = JSON.stringify(obj.data, null, 2) + + return Object.assign(obj, { data }) + } + + private buildUniqId (obj: Job) { + return Object.assign(obj, { uniqId: `${obj.id}-${obj.type}` }) + } +} diff --git a/client/src/app/+admin/system/jobs/jobs.component.html b/client/src/app/+admin/system/jobs/jobs.component.html new file mode 100644 index 000000000..7ed1888e2 --- /dev/null +++ b/client/src/app/+admin/system/jobs/jobs.component.html @@ -0,0 +1,56 @@ +
+
Jobs list
+ +
+ +
+
+ + + + + + ID + Type + State + Created + Processed on + Finished on + + + + + + + + + + + {{ job.id }} + {{ job.type }} + {{ job.state }} + {{ job.createdAt }} + {{ job.processedOn }} + {{ job.finishedOn }} + + + + + + +
{{ job.data }}
+ + + + +
{{ job.error }}
+ + +
+
+ diff --git a/client/src/app/+admin/system/jobs/jobs.component.scss b/client/src/app/+admin/system/jobs/jobs.component.scss new file mode 100644 index 000000000..ab05f1982 --- /dev/null +++ b/client/src/app/+admin/system/jobs/jobs.component.scss @@ -0,0 +1,14 @@ +@import '_variables'; +@import '_mixins'; + +.peertube-select-container { + @include peertube-select-container(auto); +} + +pre { + font-size: 11px; +} + +.job-error { + color: red; +} diff --git a/client/src/app/+admin/system/jobs/jobs.component.ts b/client/src/app/+admin/system/jobs/jobs.component.ts new file mode 100644 index 000000000..b265e1dd6 --- /dev/null +++ b/client/src/app/+admin/system/jobs/jobs.component.ts @@ -0,0 +1,69 @@ +import { Component, OnInit } from '@angular/core' +import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' +import { Notifier } from '@app/core' +import { SortMeta } from 'primeng/primeng' +import { Job } from '../../../../../../shared/index' +import { JobState } from '../../../../../../shared/models' +import { RestPagination, RestTable } from '../../../shared' +import { JobService } from '../shared' +import { I18n } from '@ngx-translate/i18n-polyfill' + +@Component({ + selector: 'my-jobs-list', + templateUrl: './jobs-list.component.html', + styleUrls: [ './jobs-list.component.scss' ] +}) +export class JobsListComponent extends RestTable implements OnInit { + private static JOB_STATE_LOCAL_STORAGE_STATE = 'jobs-list-state' + + jobState: JobState = 'waiting' + jobStates: JobState[] = [ 'active', 'completed', 'failed', 'waiting', 'delayed' ] + jobs: Job[] = [] + totalRecords: number + rowsPerPage = 10 + sort: SortMeta = { field: 'createdAt', order: -1 } + pagination: RestPagination = { count: this.rowsPerPage, start: 0 } + + constructor ( + private notifier: Notifier, + private jobsService: JobService, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.loadJobState() + this.initialize() + } + + onJobStateChanged () { + this.pagination.start = 0 + + this.loadData() + this.saveJobState() + } + + protected loadData () { + this.jobsService + .getJobs(this.jobState, this.pagination, this.sort) + .subscribe( + resultList => { + this.jobs = resultList.data + this.totalRecords = resultList.total + }, + + err => this.notifier.error(err.message) + ) + } + + private loadJobState () { + const result = peertubeLocalStorage.getItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE) + + if (result) this.jobState = result as JobState + } + + private saveJobState () { + peertubeLocalStorage.setItem(JobsListComponent.JOB_STATE_LOCAL_STORAGE_STATE, this.jobState) + } +} -- cgit v1.2.3