From ed31c059851a30bd5ba9999f8ecb3822d576b9f4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 2 Aug 2018 17:48:50 +0200 Subject: Add ability to list video imports --- .../app/+my-account/my-account-routing.module.ts | 10 ++++ .../my-account-video-imports.component.html | 37 ++++++++++++ .../my-account-video-imports.component.scss | 2 + .../my-account-video-imports.component.ts | 66 ++++++++++++++++++++++ .../my-account-videos.component.ts | 2 + .../src/app/+my-account/my-account.component.html | 2 + client/src/app/+my-account/my-account.module.ts | 8 ++- .../shared/video-import/video-import.service.ts | 38 ++++++++++++- 8 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.html create mode 100644 client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.scss create mode 100644 client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts (limited to 'client') diff --git a/client/src/app/+my-account/my-account-routing.module.ts b/client/src/app/+my-account/my-account-routing.module.ts index 91b464f75..6f0806e8a 100644 --- a/client/src/app/+my-account/my-account-routing.module.ts +++ b/client/src/app/+my-account/my-account-routing.module.ts @@ -8,6 +8,7 @@ import { MyAccountVideosComponent } from './my-account-videos/my-account-videos. import { MyAccountVideoChannelsComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channels.component' import { MyAccountVideoChannelCreateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-create.component' import { MyAccountVideoChannelUpdateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-update.component' +import { MyAccountVideoImportsComponent } from '@app/+my-account/my-account-video-imports/my-account-video-imports.component' const myAccountRoutes: Routes = [ { @@ -64,6 +65,15 @@ const myAccountRoutes: Routes = [ title: 'Account videos' } } + }, + { + path: 'video-imports', + component: MyAccountVideoImportsComponent, + data: { + meta: { + title: 'Account video imports' + } + } } ] } diff --git a/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.html b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.html new file mode 100644 index 000000000..74ca33fa3 --- /dev/null +++ b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.html @@ -0,0 +1,37 @@ + + + + URL + Video + State + Created + + + + + + + + {{ videoImport.targetUrl }} + + + + {{ videoImport.video.name }} + + + {{ videoImport.video.name }} + + + + {{ videoImport.state.label }} + {{ videoImport.createdAt }} + + + + + + + diff --git a/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.scss b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.scss new file mode 100644 index 000000000..5e6774739 --- /dev/null +++ b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.scss @@ -0,0 +1,2 @@ +@import '_variables'; +@import '_mixins'; diff --git a/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts new file mode 100644 index 000000000..31ccb0bc8 --- /dev/null +++ b/client/src/app/+my-account/my-account-video-imports/my-account-video-imports.component.ts @@ -0,0 +1,66 @@ +import { Component, OnInit } from '@angular/core' +import { RestPagination, RestTable } from '@app/shared' +import { SortMeta } from 'primeng/components/common/sortmeta' +import { NotificationsService } from 'angular2-notifications' +import { ConfirmService } from '@app/core' +import { I18n } from '@ngx-translate/i18n-polyfill' +import { VideoImport, VideoImportState } from '../../../../../shared/models/videos' +import { VideoImportService } from '@app/shared/video-import' + +@Component({ + selector: 'my-account-video-imports', + templateUrl: './my-account-video-imports.component.html', + styleUrls: [ './my-account-video-imports.component.scss' ] +}) +export class MyAccountVideoImportsComponent extends RestTable implements OnInit { + videoImports: VideoImport[] = [] + totalRecords = 0 + rowsPerPage = 10 + sort: SortMeta = { field: 'createdAt', order: 1 } + pagination: RestPagination = { count: this.rowsPerPage, start: 0 } + + constructor ( + private notificationsService: NotificationsService, + private confirmService: ConfirmService, + private videoImportService: VideoImportService, + private i18n: I18n + ) { + super() + } + + ngOnInit () { + this.loadSort() + } + + isVideoImportSuccess (videoImport: VideoImport) { + return videoImport.state.id === VideoImportState.SUCCESS + } + + isVideoImportPending (videoImport: VideoImport) { + return videoImport.state.id === VideoImportState.PENDING + } + + isVideoImportFailed (videoImport: VideoImport) { + return videoImport.state.id === VideoImportState.FAILED + } + + getVideoUrl (video: { uuid: string }) { + return '/videos/watch/' + video.uuid + } + + getEditVideoUrl (video: { uuid: string }) { + return '/videos/update/' + video.uuid + } + + protected loadData () { + this.videoImportService.getMyVideoImports(this.pagination, this.sort) + .subscribe( + resultList => { + this.videoImports = resultList.data + this.totalRecords = resultList.total + }, + + err => this.notificationsService.error(this.i18n('Error'), err.message) + ) + } +} diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts index 54830c75e..01e1ef1da 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts @@ -145,6 +145,8 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni suffix = this.i18n('Waiting transcoding') } else if (video.state.id === VideoState.TO_TRANSCODE) { suffix = this.i18n('To transcode') + } else if (video.state.id === VideoState.TO_IMPORT) { + suffix = this.i18n('To import') } else { return '' } diff --git a/client/src/app/+my-account/my-account.component.html b/client/src/app/+my-account/my-account.component.html index 48db55ad3..f67245d85 100644 --- a/client/src/app/+my-account/my-account.component.html +++ b/client/src/app/+my-account/my-account.component.html @@ -5,6 +5,8 @@ My video channels My videos + + My video imports
diff --git a/client/src/app/+my-account/my-account.module.ts b/client/src/app/+my-account/my-account.module.ts index 2088273e6..5403ab649 100644 --- a/client/src/app/+my-account/my-account.module.ts +++ b/client/src/app/+my-account/my-account.module.ts @@ -1,3 +1,4 @@ +import { TableModule } from 'primeng/table' import { NgModule } from '@angular/core' import { SharedModule } from '../shared' import { MyAccountRoutingModule } from './my-account-routing.module' @@ -11,11 +12,13 @@ import { MyAccountVideoChannelsComponent } from '@app/+my-account/my-account-vid import { MyAccountVideoChannelCreateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-create.component' import { MyAccountVideoChannelUpdateComponent } from '@app/+my-account/my-account-video-channels/my-account-video-channel-update.component' import { ActorAvatarInfoComponent } from '@app/+my-account/shared/actor-avatar-info.component' +import { MyAccountVideoImportsComponent } from '@app/+my-account/my-account-video-imports/my-account-video-imports.component' @NgModule({ imports: [ MyAccountRoutingModule, - SharedModule + SharedModule, + TableModule ], declarations: [ @@ -28,7 +31,8 @@ import { ActorAvatarInfoComponent } from '@app/+my-account/shared/actor-avatar-i MyAccountVideoChannelsComponent, MyAccountVideoChannelCreateComponent, MyAccountVideoChannelUpdateComponent, - ActorAvatarInfoComponent + ActorAvatarInfoComponent, + MyAccountVideoImportsComponent ], exports: [ diff --git a/client/src/app/shared/video-import/video-import.service.ts b/client/src/app/shared/video-import/video-import.service.ts index b4709866a..59b58ab38 100644 --- a/client/src/app/shared/video-import/video-import.service.ts +++ b/client/src/app/shared/video-import/video-import.service.ts @@ -1,5 +1,5 @@ -import { catchError } from 'rxjs/operators' -import { HttpClient } from '@angular/common/http' +import { catchError, map, switchMap } from 'rxjs/operators' +import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { Observable } from 'rxjs' import { VideoImport } from '../../../../../shared' @@ -8,6 +8,12 @@ import { RestExtractor, RestService } from '../rest' import { VideoImportCreate } from '../../../../../shared/models/videos/video-import-create.model' import { objectToFormData } from '@app/shared/misc/utils' import { VideoUpdate } from '../../../../../shared/models/videos' +import { ResultList } from '../../../../../shared/models/result-list.model' +import { UserService } from '@app/shared/users/user.service' +import { SortMeta } from 'primeng/components/common/sortmeta' +import { RestPagination } from '@app/shared/rest' +import { ServerService } from '@app/core' +import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' @Injectable() export class VideoImportService { @@ -16,7 +22,8 @@ export class VideoImportService { constructor ( private authHttp: HttpClient, private restService: RestService, - private restExtractor: RestExtractor + private restExtractor: RestExtractor, + private serverService: ServerService ) {} importVideo (targetUrl: string, video: VideoUpdate): Observable { @@ -53,4 +60,29 @@ export class VideoImportService { .pipe(catchError(res => this.restExtractor.handleError(res))) } + getMyVideoImports (pagination: RestPagination, sort: SortMeta): Observable> { + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + return this.authHttp + .get>(UserService.BASE_USERS_URL + '/me/videos/imports', { params }) + .pipe( + switchMap(res => this.extractVideoImports(res)), + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + private extractVideoImports (result: ResultList): Observable> { + return this.serverService.localeObservable + .pipe( + map(translations => { + result.data.forEach(d => + d.state.label = peertubeTranslate(d.state.label, translations) + ) + + return result + }) + ) + } } -- cgit v1.2.3