aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-main
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-10-27 11:42:05 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-10-29 11:48:21 +0200
commit33f6dce136ca6e969fe374efa099bee3f2a3599d (patch)
tree7a0d6228bab085944015a01267ad31aa1ec6082e /client/src/app/shared/shared-main
parent00004f7f6b966a975498612117212b5373f4103c (diff)
downloadPeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.tar.gz
PeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.tar.zst
PeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.zip
Add videos list admin component
Diffstat (limited to 'client/src/app/shared/shared-main')
-rw-r--r--client/src/app/shared/shared-main/shared-main.module.ts13
-rw-r--r--client/src/app/shared/shared-main/video/embed.component.html3
-rw-r--r--client/src/app/shared/shared-main/video/embed.component.scss10
-rw-r--r--client/src/app/shared/shared-main/video/embed.component.ts35
-rw-r--r--client/src/app/shared/shared-main/video/index.ts1
-rw-r--r--client/src/app/shared/shared-main/video/video.service.ts85
6 files changed, 126 insertions, 21 deletions
diff --git a/client/src/app/shared/shared-main/shared-main.module.ts b/client/src/app/shared/shared-main/shared-main.module.ts
index 93989780d..a90b59e41 100644
--- a/client/src/app/shared/shared-main/shared-main.module.ts
+++ b/client/src/app/shared/shared-main/shared-main.module.ts
@@ -43,13 +43,8 @@ import {
43} from './misc' 43} from './misc'
44import { PluginPlaceholderComponent } from './plugins' 44import { PluginPlaceholderComponent } from './plugins'
45import { ActorRedirectGuard } from './router' 45import { ActorRedirectGuard } from './router'
46import { 46import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users'
47 UserHistoryService, 47import { EmbedComponent, RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video'
48 UserNotificationsComponent,
49 UserNotificationService,
50 UserQuotaComponent
51} from './users'
52import { RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video'
53import { VideoCaptionService } from './video-caption' 48import { VideoCaptionService } from './video-caption'
54import { VideoChannelService } from './video-channel' 49import { VideoChannelService } from './video-channel'
55 50
@@ -111,6 +106,8 @@ import { VideoChannelService } from './video-channel'
111 UserQuotaComponent, 106 UserQuotaComponent,
112 UserNotificationsComponent, 107 UserNotificationsComponent,
113 108
109 EmbedComponent,
110
114 PluginPlaceholderComponent 111 PluginPlaceholderComponent
115 ], 112 ],
116 113
@@ -167,6 +164,8 @@ import { VideoChannelService } from './video-channel'
167 UserQuotaComponent, 164 UserQuotaComponent,
168 UserNotificationsComponent, 165 UserNotificationsComponent,
169 166
167 EmbedComponent,
168
170 PluginPlaceholderComponent 169 PluginPlaceholderComponent
171 ], 170 ],
172 171
diff --git a/client/src/app/shared/shared-main/video/embed.component.html b/client/src/app/shared/shared-main/video/embed.component.html
new file mode 100644
index 000000000..3b088d058
--- /dev/null
+++ b/client/src/app/shared/shared-main/video/embed.component.html
@@ -0,0 +1,3 @@
1<div class="screenratio">
2 <div [innerHTML]="embedHTML"></div>
3</div>
diff --git a/client/src/app/shared/shared-main/video/embed.component.scss b/client/src/app/shared/shared-main/video/embed.component.scss
new file mode 100644
index 000000000..420ba6f23
--- /dev/null
+++ b/client/src/app/shared/shared-main/video/embed.component.scss
@@ -0,0 +1,10 @@
1@use '_mixins' as *;
2@use '_variables' as *;
3
4.screenratio {
5 @include block-ratio($selector: 'div, ::ng-deep iframe') {
6 width: 100% !important;
7 height: 100% !important;
8 left: 0;
9 };
10}
diff --git a/client/src/app/shared/shared-main/video/embed.component.ts b/client/src/app/shared/shared-main/video/embed.component.ts
new file mode 100644
index 000000000..4732efa44
--- /dev/null
+++ b/client/src/app/shared/shared-main/video/embed.component.ts
@@ -0,0 +1,35 @@
1import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils'
2import { environment } from 'src/environments/environment'
3import { Component, Input, OnInit } from '@angular/core'
4import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
5import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils'
6import { Video } from '@shared/models'
7
8@Component({
9 selector: 'my-embed',
10 styleUrls: [ './embed.component.scss' ],
11 templateUrl: './embed.component.html'
12})
13export class EmbedComponent implements OnInit {
14 @Input() video: Pick<Video, 'name' | 'uuid'>
15
16 embedHTML: SafeHtml
17
18 constructor (private sanitizer: DomSanitizer) {
19
20 }
21
22 ngOnInit () {
23 const html = buildVideoOrPlaylistEmbed(
24 decorateVideoLink({
25 url: buildVideoEmbedLink(this.video, environment.originServerUrl),
26
27 title: false,
28 warningTitle: false
29 }),
30 this.video.name
31 )
32
33 this.embedHTML = this.sanitizer.bypassSecurityTrustHtml(html)
34 }
35}
diff --git a/client/src/app/shared/shared-main/video/index.ts b/client/src/app/shared/shared-main/video/index.ts
index 3053df4ef..e72c0c3d6 100644
--- a/client/src/app/shared/shared-main/video/index.ts
+++ b/client/src/app/shared/shared-main/video/index.ts
@@ -1,3 +1,4 @@
1export * from './embed.component'
1export * from './redundancy.service' 2export * from './redundancy.service'
2export * from './video-details.model' 3export * from './video-details.model'
3export * from './video-edit.model' 4export * from './video-edit.model'
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 7935569e7..9e3aa1e6a 100644
--- a/client/src/app/shared/shared-main/video/video.service.ts
+++ b/client/src/app/shared/shared-main/video/video.service.ts
@@ -1,8 +1,9 @@
1import { Observable } from 'rxjs' 1import { SortMeta } from 'primeng/api'
2import { catchError, map, switchMap } from 'rxjs/operators' 2import { from, Observable } from 'rxjs'
3import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators'
3import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' 4import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http'
4import { Injectable } from '@angular/core' 5import { Injectable } from '@angular/core'
5import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' 6import { ComponentPaginationLight, RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core'
6import { objectToFormData } from '@app/helpers' 7import { objectToFormData } from '@app/helpers'
7import { 8import {
8 BooleanBothQuery, 9 BooleanBothQuery,
@@ -31,8 +32,8 @@ import { VideoEdit } from './video-edit.model'
31import { Video } from './video.model' 32import { Video } from './video.model'
32 33
33export type CommonVideoParams = { 34export type CommonVideoParams = {
34 videoPagination: ComponentPaginationLight 35 videoPagination?: ComponentPaginationLight
35 sort: VideoSortField 36 sort: VideoSortField | SortMeta
36 filter?: VideoFilter 37 filter?: VideoFilter
37 categoryOneOf?: number[] 38 categoryOneOf?: number[]
38 languageOneOf?: string[] 39 languageOneOf?: string[]
@@ -200,6 +201,31 @@ export class VideoService {
200 ) 201 )
201 } 202 }
202 203
204 getAdminVideos (
205 parameters: Omit<CommonVideoParams, 'filter'> & { pagination: RestPagination, search?: string }
206 ): Observable<ResultList<Video>> {
207 const { pagination, search } = parameters
208
209 let params = new HttpParams()
210 params = this.buildCommonVideosParams({ params, ...parameters })
211
212 params = params.set('start', pagination.start.toString())
213 .set('count', pagination.count.toString())
214
215 if (search) {
216 params = this.buildAdminParamsFromSearch(search, params)
217 }
218
219 if (!params.has('filter')) params = params.set('filter', 'all')
220
221 return this.authHttp
222 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
223 .pipe(
224 switchMap(res => this.extractVideos(res)),
225 catchError(err => this.restExtractor.handleError(err))
226 )
227 }
228
203 getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> { 229 getVideos (parameters: CommonVideoParams): Observable<ResultList<Video>> {
204 let params = new HttpParams() 230 let params = new HttpParams()
205 params = this.buildCommonVideosParams({ params, ...parameters }) 231 params = this.buildCommonVideosParams({ params, ...parameters })
@@ -284,13 +310,15 @@ export class VideoService {
284 ) 310 )
285 } 311 }
286 312
287 removeVideo (id: number) { 313 removeVideo (idArg: number | number[]) {
288 return this.authHttp 314 const ids = Array.isArray(idArg) ? idArg : [ idArg ]
289 .delete(VideoService.BASE_VIDEO_URL + id) 315
290 .pipe( 316 return from(ids)
291 map(this.restExtractor.extractDataBool), 317 .pipe(
292 catchError(err => this.restExtractor.handleError(err)) 318 concatMap(id => this.authHttp.delete(VideoService.BASE_VIDEO_URL + id)),
293 ) 319 toArray(),
320 catchError(err => this.restExtractor.handleError(err))
321 )
294 } 322 }
295 323
296 loadCompleteDescription (descriptionPath: string) { 324 loadCompleteDescription (descriptionPath: string) {
@@ -393,9 +421,23 @@ export class VideoService {
393 } 421 }
394 422
395 private buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) { 423 private buildCommonVideosParams (options: CommonVideoParams & { params: HttpParams }) {
396 const { params, videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount, nsfwPolicy, isLive, nsfw } = options 424 const {
425 params,
426 videoPagination,
427 sort,
428 filter,
429 categoryOneOf,
430 languageOneOf,
431 skipCount,
432 nsfwPolicy,
433 isLive,
434 nsfw
435 } = options
436
437 const pagination = videoPagination
438 ? this.restService.componentToRestPagination(videoPagination)
439 : undefined
397 440
398 const pagination = this.restService.componentToRestPagination(videoPagination)
399 let newParams = this.restService.addRestGetParams(params, pagination, sort) 441 let newParams = this.restService.addRestGetParams(params, pagination, sort)
400 442
401 if (filter) newParams = newParams.set('filter', filter) 443 if (filter) newParams = newParams.set('filter', filter)
@@ -409,4 +451,19 @@ export class VideoService {
409 451
410 return newParams 452 return newParams
411 } 453 }
454
455 private buildAdminParamsFromSearch (search: string, params: HttpParams) {
456 const filters = this.restService.parseQueryStringFilter(search, {
457 filter: {
458 prefix: 'local:',
459 handler: v => {
460 if (v === 'true') return 'all-local'
461
462 return 'all'
463 }
464 }
465 })
466
467 return this.restService.addObjectParams(params, filters)
468 }
412} 469}