From 62e62f118d5da57acd3494fece2e8ed357564ffe Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 9 May 2018 09:26:41 +0200 Subject: Load my-account module lazily --- .../my-account-videos.component.html | 45 +++++++ .../my-account-videos.component.scss | 114 ++++++++++++++++++ .../my-account-videos.component.ts | 131 +++++++++++++++++++++ 3 files changed, 290 insertions(+) create mode 100644 client/src/app/+my-account/my-account-videos/my-account-videos.component.html create mode 100644 client/src/app/+my-account/my-account-videos/my-account-videos.component.scss create mode 100644 client/src/app/+my-account/my-account-videos/my-account-videos.component.ts (limited to 'client/src/app/+my-account/my-account-videos') diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.html b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html new file mode 100644 index 000000000..66ce3a77b --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.html @@ -0,0 +1,45 @@ +
No results.
+ +
+
+
+
+ + +
+ + + +
+ {{ video.name }} + {{ video.createdAt | myFromNow }} - {{ video.views | myNumberFormatter }} views +
{{ video.privacy.label }}
+
+ + +
+
+ + Cancel + + + + + Delete + +
+
+ +
+ + + +
+
+
+
diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss b/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss new file mode 100644 index 000000000..f276ea389 --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.scss @@ -0,0 +1,114 @@ +@import '_variables'; +@import '_mixins'; + +.action-selection-mode { + width: 174px; + display: flex; + justify-content: flex-end; + + .action-selection-mode-child { + position: fixed; + + .action-button { + display: inline-block; + } + + .action-button-cancel-selection { + @include peertube-button; + @include grey-button; + + margin-right: 10px; + } + + .action-button-delete-selection { + @include peertube-button; + @include orange-button; + } + + .icon.icon-delete-white { + @include icon(21px); + + position: relative; + top: -2px; + background-image: url('../../../assets/images/global/delete-white.svg'); + } + } +} + +/deep/ .action-button { + &.action-button-delete { + margin-right: 10px; + } +} + +.video { + display: flex; + min-height: 130px; + padding-bottom: 20px; + margin-bottom: 20px; + border-bottom: 1px solid #C6C6C6; + + &:first-child { + margin-top: 47px; + } + + .checkbox-container { + display: flex; + align-items: center; + margin-right: 20px; + margin-left: 12px; + + input[type=checkbox] { + @include peertube-checkbox(2px); + } + } + + my-video-thumbnail { + margin-right: 10px; + } + + .video-info { + flex-grow: 1; + + .video-info-name { + @include disable-default-a-behaviour; + + color: #000; + display: block; + font-size: 16px; + font-weight: $font-semibold; + } + + .video-info-date-views, .video-info-private { + font-size: 13px; + + &.video-info-private { + font-weight: $font-semibold; + } + } + } + + .video-buttons { + min-width: 190px; + } +} + +@media screen and (max-width: 800px) { + .video { + flex-direction: column; + height: auto; + text-align: center; + + input[type=checkbox] { + display: none; + } + + my-video-thumbnail { + margin-right: 0; + } + + .video-buttons { + margin-top: 10px; + } + } +} 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 new file mode 100644 index 000000000..c1b53bcd5 --- /dev/null +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts @@ -0,0 +1,131 @@ +import { Component, OnInit, OnDestroy } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' +import { Location } from '@angular/common' +import { immutableAssign } from '@app/shared/misc/utils' +import { ComponentPagination } from '@app/shared/rest/component-pagination.model' +import { NotificationsService } from 'angular2-notifications' +import 'rxjs/add/observable/from' +import 'rxjs/add/operator/concatAll' +import { Observable } from 'rxjs/Observable' +import { AuthService } from '../../core/auth' +import { ConfirmService } from '../../core/confirm' +import { AbstractVideoList } from '../../shared/video/abstract-video-list' +import { Video } from '../../shared/video/video.model' +import { VideoService } from '../../shared/video/video.service' + +@Component({ + selector: 'my-account-videos', + templateUrl: './my-account-videos.component.html', + styleUrls: [ './my-account-videos.component.scss' ] +}) +export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { + titlePage = 'My videos' + currentRoute = '/my-account/videos' + checkedVideos: { [ id: number ]: boolean } = {} + pagination: ComponentPagination = { + currentPage: 1, + itemsPerPage: 5, + totalItems: null + } + + protected baseVideoWidth = -1 + protected baseVideoHeight = 155 + + constructor (protected router: Router, + protected route: ActivatedRoute, + protected authService: AuthService, + protected notificationsService: NotificationsService, + protected confirmService: ConfirmService, + protected location: Location, + private videoService: VideoService) { + super() + } + + ngOnInit () { + super.ngOnInit() + } + + ngOnDestroy () { + super.ngOnDestroy() + } + + abortSelectionMode () { + this.checkedVideos = {} + } + + isInSelectionMode () { + return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true) + } + + getVideosObservable (page: number) { + const newPagination = immutableAssign(this.pagination, { currentPage: page }) + + return this.videoService.getMyVideos(newPagination, this.sort) + } + + generateSyndicationList () { + throw new Error('Method not implemented.') + } + + async deleteSelectedVideos () { + const toDeleteVideosIds = Object.keys(this.checkedVideos) + .filter(k => this.checkedVideos[k] === true) + .map(k => parseInt(k, 10)) + + const res = await this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete') + if (res === false) return + + const observables: Observable[] = [] + for (const videoId of toDeleteVideosIds) { + const o = this.videoService + .removeVideo(videoId) + .do(() => this.spliceVideosById(videoId)) + + observables.push(o) + } + + Observable.from(observables) + .concatAll() + .subscribe( + res => { + this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`) + this.buildVideoPages() + }, + + err => this.notificationsService.error('Error', err.message) + ) + } + + async deleteVideo (video: Video) { + const res = await this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete') + if (res === false) return + + this.videoService.removeVideo(video.id) + .subscribe( + status => { + this.notificationsService.success('Success', `Video ${video.name} deleted.`) + this.spliceVideosById(video.id) + this.buildVideoPages() + }, + + error => this.notificationsService.error('Error', error.message) + ) + } + + protected buildVideoHeight () { + // In account videos, the video height is fixed + return this.baseVideoHeight + } + + private spliceVideosById (id: number) { + for (const key of Object.keys(this.loadedPages)) { + const videos = this.loadedPages[key] + const index = videos.findIndex(v => v.id === id) + + if (index !== -1) { + videos.splice(index, 1) + return + } + } + } +} -- cgit v1.2.3