From 0aa52e170727ac6bdf441bcaa2353ae0b8a354ed Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Nov 2020 15:29:38 +0100 Subject: Add ability to display all channel/account videos --- .../account-video-channels.component.ts | 18 ++++++++++-- .../account-videos/account-videos.component.ts | 20 +++++++++++++- .../video-channel-videos.component.ts | 20 +++++++++++++- .../+videos/video-list/video-local.component.ts | 8 ++---- .../app/shared/shared-main/video/video.service.ts | 27 +++++++++++++++--- .../abstract-video-list.html | 2 +- .../abstract-video-list.scss | 12 ++++++-- .../shared-video-miniature/abstract-video-list.ts | 32 ++++++++++++++++++---- 8 files changed, 116 insertions(+), 23 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts index 205245675..f2beb6689 100644 --- a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts +++ b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts @@ -3,7 +3,7 @@ import { concatMap, map, switchMap, tap } from 'rxjs/operators' import { Component, OnDestroy, OnInit } from '@angular/core' import { ComponentPagination, hasMoreItems, ScreenService, User, UserService } from '@app/core' import { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' -import { VideoSortField } from '@shared/models' +import { NSFWPolicyType, VideoSortField } from '@shared/models' @Component({ selector: 'my-account-video-channels', @@ -31,6 +31,7 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy { onChannelDataSubject = new Subject() userMiniature: User + nsfwPolicy: NSFWPolicyType private accountSub: Subscription @@ -52,7 +53,11 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy { }) this.userService.getAnonymousOrLoggedUser() - .subscribe(user => this.userMiniature = user) + .subscribe(user => { + this.userMiniature = user + + this.nsfwPolicy = user.nsfwPolicy + }) } ngOnDestroy () { @@ -65,7 +70,14 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy { tap(res => this.channelPagination.totalItems = res.total), switchMap(res => from(res.data)), concatMap(videoChannel => { - return this.videoService.getVideoChannelVideos(videoChannel, this.videosPagination, this.videosSort) + const options = { + videoChannel, + videoPagination: this.videosPagination, + sort: this.videosSort, + nsfwPolicy: this.nsfwPolicy + } + + return this.videoService.getVideoChannelVideos(options) .pipe(map(data => ({ videoChannel, videos: data.data }))) }) ) diff --git a/client/src/app/+accounts/account-videos/account-videos.component.ts b/client/src/app/+accounts/account-videos/account-videos.component.ts index 3134a8ee2..58d0719fd 100644 --- a/client/src/app/+accounts/account-videos/account-videos.component.ts +++ b/client/src/app/+accounts/account-videos/account-videos.component.ts @@ -6,6 +6,7 @@ import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenServi import { immutableAssign } from '@app/helpers' import { Account, AccountService, VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' +import { VideoFilter } from '@shared/models' @Component({ selector: 'my-account-videos', @@ -18,6 +19,8 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, titlePage: string loadOnInit = false + filter: VideoFilter = null + private account: Account private accountSub: Subscription @@ -40,6 +43,8 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, ngOnInit () { super.ngOnInit() + this.enableAllFilterIfPossible() + // Parent get the account for us this.accountSub = this.accountService.accountLoaded .pipe(first()) @@ -59,9 +64,16 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) + const options = { + account: this.account, + videoPagination: newPagination, + sort: this.sort, + nsfwPolicy: this.nsfwPolicy, + videoFilter: this.filter + } return this.videoService - .getAccountVideos(this.account, newPagination, this.sort) + .getAccountVideos(options) .pipe( tap(({ total }) => { this.titlePage = $localize`Published ${total} videos` @@ -69,6 +81,12 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, ) } + toggleModerationDisplay () { + this.filter = this.buildLocalFilter(this.filter, null) + + this.reloadVideos() + } + generateSyndicationList () { this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) } diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts index e1ec6bbcb..645696f48 100644 --- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts +++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts @@ -6,6 +6,7 @@ import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenServi import { immutableAssign } from '@app/helpers' import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' import { AbstractVideoList } from '@app/shared/shared-video-miniature' +import { VideoFilter } from '@shared/models' @Component({ selector: 'my-video-channel-videos', @@ -18,6 +19,8 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On titlePage: string loadOnInit = false + filter: VideoFilter = null + private videoChannel: VideoChannel private videoChannelSub: Subscription @@ -46,6 +49,8 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On ngOnInit () { super.ngOnInit() + this.enableAllFilterIfPossible() + // Parent get the video channel for us this.videoChannelSub = this.videoChannelService.videoChannelLoaded .pipe(first()) @@ -65,9 +70,16 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On getVideosObservable (page: number) { const newPagination = immutableAssign(this.pagination, { currentPage: page }) + const options = { + videoChannel: this.videoChannel, + videoPagination: newPagination, + sort: this.sort, + nsfwPolicy: this.nsfwPolicy, + videoFilter: this.filter + } return this.videoService - .getVideoChannelVideos(this.videoChannel, newPagination, this.sort, this.nsfwPolicy) + .getVideoChannelVideos(options) .pipe( tap(({ total }) => { this.titlePage = total === 1 @@ -80,4 +92,10 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On generateSyndicationList () { this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) } + + toggleModerationDisplay () { + this.filter = this.buildLocalFilter(this.filter, null) + + this.reloadVideos() + } } diff --git a/client/src/app/+videos/video-list/video-local.component.ts b/client/src/app/+videos/video-list/video-local.component.ts index 07063d4d4..20dd61db9 100644 --- a/client/src/app/+videos/video-list/video-local.component.ts +++ b/client/src/app/+videos/video-list/video-local.component.ts @@ -39,11 +39,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On ngOnInit () { super.ngOnInit() - if (this.authService.isLoggedIn()) { - const user = this.authService.getUser() - this.displayModerationBlock = user.hasRight(UserRight.SEE_ALL_VIDEOS) - } - + this.enableAllFilterIfPossible() this.generateSyndicationList() } @@ -77,7 +73,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On } toggleModerationDisplay () { - this.filter = this.filter === 'local' ? 'all-local' as 'all-local' : 'local' as 'local' + this.filter = this.buildLocalFilter(this.filter, 'local') this.reloadVideos() } diff --git a/client/src/app/shared/shared-main/video/video.service.ts b/client/src/app/shared/shared-main/video/video.service.ts index 0e2d36081..c8a3ec043 100644 --- a/client/src/app/shared/shared-main/video/video.service.ts +++ b/client/src/app/shared/shared-main/video/video.service.ts @@ -134,16 +134,28 @@ export class VideoService implements VideosProvider { ) } - getAccountVideos ( + getAccountVideos (parameters: { account: Account, videoPagination: ComponentPaginationLight, sort: VideoSortField - ): Observable> { + nsfwPolicy?: NSFWPolicyType + videoFilter?: VideoFilter + }): Observable> { + const { account, videoPagination, sort, videoFilter, nsfwPolicy } = parameters + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) + if (nsfwPolicy) { + params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) + } + + if (videoFilter) { + params = params.set('filter', videoFilter) + } + return this.authHttp .get>(AccountService.BASE_ACCOUNT_URL + account.nameWithHost + '/videos', { params }) .pipe( @@ -152,12 +164,15 @@ export class VideoService implements VideosProvider { ) } - getVideoChannelVideos ( + getVideoChannelVideos (parameters: { videoChannel: VideoChannel, videoPagination: ComponentPaginationLight, sort: VideoSortField, nsfwPolicy?: NSFWPolicyType - ): Observable> { + videoFilter?: VideoFilter + }): Observable> { + const { videoChannel, videoPagination, sort, nsfwPolicy, videoFilter } = parameters + const pagination = this.restService.componentPaginationToRestPagination(videoPagination) let params = new HttpParams() @@ -167,6 +182,10 @@ export class VideoService implements VideosProvider { params = params.set('nsfw', this.nsfwPolicyToParam(nsfwPolicy)) } + if (videoFilter) { + params = params.set('filter', videoFilter) + } + return this.authHttp .get>(VideoChannelService.BASE_VIDEO_CHANNEL_URL + videoChannel.nameWithHost + '/videos', { params }) .pipe( diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.html b/client/src/app/shared/shared-video-miniature/abstract-video-list.html index 08962dff8..b1ac757db 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.html +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.html @@ -21,7 +21,7 @@ diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.scss b/client/src/app/shared/shared-video-miniature/abstract-video-list.scss index 7841b60f7..9077e2f75 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.scss +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.scss @@ -31,13 +31,21 @@ $iconSize: 16px; .moderation-block { div { - @include button-with-icon($iconSize, 3px, -1px); + @include button-with-icon($iconSize, 3px, -2px); } - margin-left: .2rem; + margin-left: .4rem; display: flex; justify-content: flex-end; align-items: center; + + .dropdown-item { + padding: 0; + + ::ng-deep my-peertube-checkbox label { + padding: 3px 15px; + } + } } } diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts index da05e15fb..2219ced30 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts @@ -15,7 +15,7 @@ import { import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' import { GlobalIconName } from '@app/shared/shared-icons' import { isLastMonth, isLastWeek, isThisMonth, isToday, isYesterday } from '@shared/core-utils/miscs/date' -import { ServerConfig, VideoSortField } from '@shared/models' +import { ServerConfig, UserRight, VideoFilter, VideoSortField } from '@shared/models' import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' import { Syndication, Video } from '../shared-main' import { MiniatureDisplayOptions, OwnerDisplayType } from './video-miniature.component' @@ -205,10 +205,6 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor this.loadMoreVideos(true) } - toggleModerationDisplay () { - throw new Error('toggleModerationDisplay is not implemented') - } - removeVideoFromArray (video: Video) { this.videos = this.videos.filter(v => v.id !== video.id) } @@ -268,6 +264,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor return this.groupedDateLabels[this.groupedDates[video.id]] } + toggleModerationDisplay () { + throw new Error('toggleModerationDisplay is not implemented') + } + // On videos hook for children that want to do something protected onMoreVideos () { /* empty */ } @@ -277,6 +277,28 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor this.angularState = routeParams[ 'a-state' ] } + protected buildLocalFilter (existing: VideoFilter, base: VideoFilter) { + if (base === 'local') { + return existing === 'local' + ? 'all-local' as 'all-local' + : 'local' as 'local' + } + + return existing === 'all' + ? null + : 'all' + } + + protected enableAllFilterIfPossible () { + if (!this.authService.isLoggedIn()) return + + this.authService.userInformationLoaded + .subscribe(() => { + const user = this.authService.getUser() + this.displayModerationBlock = user.hasRight(UserRight.SEE_ALL_VIDEOS) + }) + } + private calcPageSizes () { if (this.screenService.isInMobileView()) { this.pagination.itemsPerPage = 5 -- cgit v1.2.3