diff options
author | Chocobozzz <me@florianbigard.com> | 2021-10-27 11:42:05 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-10-29 11:48:21 +0200 |
commit | 33f6dce136ca6e969fe374efa099bee3f2a3599d (patch) | |
tree | 7a0d6228bab085944015a01267ad31aa1ec6082e /client/src/app/shared/shared-main | |
parent | 00004f7f6b966a975498612117212b5373f4103c (diff) | |
download | PeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.tar.gz PeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.tar.zst PeerTube-33f6dce136ca6e969fe374efa099bee3f2a3599d.zip |
Add videos list admin component
Diffstat (limited to 'client/src/app/shared/shared-main')
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' |
44 | import { PluginPlaceholderComponent } from './plugins' | 44 | import { PluginPlaceholderComponent } from './plugins' |
45 | import { ActorRedirectGuard } from './router' | 45 | import { ActorRedirectGuard } from './router' |
46 | import { | 46 | import { UserHistoryService, UserNotificationsComponent, UserNotificationService, UserQuotaComponent } from './users' |
47 | UserHistoryService, | 47 | import { EmbedComponent, RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video' |
48 | UserNotificationsComponent, | ||
49 | UserNotificationService, | ||
50 | UserQuotaComponent | ||
51 | } from './users' | ||
52 | import { RedundancyService, VideoImportService, VideoOwnershipService, VideoService } from './video' | ||
53 | import { VideoCaptionService } from './video-caption' | 48 | import { VideoCaptionService } from './video-caption' |
54 | import { VideoChannelService } from './video-channel' | 49 | import { 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 @@ | |||
1 | import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' | ||
2 | import { environment } from 'src/environments/environment' | ||
3 | import { Component, Input, OnInit } from '@angular/core' | ||
4 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' | ||
5 | import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' | ||
6 | import { Video } from '@shared/models' | ||
7 | |||
8 | @Component({ | ||
9 | selector: 'my-embed', | ||
10 | styleUrls: [ './embed.component.scss' ], | ||
11 | templateUrl: './embed.component.html' | ||
12 | }) | ||
13 | export 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 @@ | |||
1 | export * from './embed.component' | ||
1 | export * from './redundancy.service' | 2 | export * from './redundancy.service' |
2 | export * from './video-details.model' | 3 | export * from './video-details.model' |
3 | export * from './video-edit.model' | 4 | export * 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 @@ | |||
1 | import { Observable } from 'rxjs' | 1 | import { SortMeta } from 'primeng/api' |
2 | import { catchError, map, switchMap } from 'rxjs/operators' | 2 | import { from, Observable } from 'rxjs' |
3 | import { catchError, concatMap, map, switchMap, toArray } from 'rxjs/operators' | ||
3 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' | 4 | import { HttpClient, HttpParams, HttpRequest } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
5 | import { ComponentPaginationLight, RestExtractor, RestService, ServerService, UserService } from '@app/core' | 6 | import { ComponentPaginationLight, RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core' |
6 | import { objectToFormData } from '@app/helpers' | 7 | import { objectToFormData } from '@app/helpers' |
7 | import { | 8 | import { |
8 | BooleanBothQuery, | 9 | BooleanBothQuery, |
@@ -31,8 +32,8 @@ import { VideoEdit } from './video-edit.model' | |||
31 | import { Video } from './video.model' | 32 | import { Video } from './video.model' |
32 | 33 | ||
33 | export type CommonVideoParams = { | 34 | export 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 | } |