]>
Commit | Line | Data |
---|---|---|
07f81d9d | 1 | import { forkJoin, Subscription } from 'rxjs' |
67ed6552 | 2 | import { first, tap } from 'rxjs/operators' |
5bcbcbe3 | 3 | import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' |
0626e7af | 4 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 C |
5 | import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
6 | import { immutableAssign } from '@app/helpers' | |
7 | import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | |
900f7820 | 8 | import { AbstractVideoList, MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' |
0aa52e17 | 9 | import { VideoFilter } from '@shared/models' |
0626e7af C |
10 | |
11 | @Component({ | |
170726f5 | 12 | selector: 'my-video-channel-videos', |
67ed6552 | 13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', |
0626e7af | 14 | styleUrls: [ |
ae2dd046 | 15 | '../../shared/shared-video-miniature/abstract-video-list.scss' |
0626e7af C |
16 | ] |
17 | }) | |
170726f5 | 18 | export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { |
b1d40cff | 19 | titlePage: string |
0626e7af | 20 | loadOnInit = false |
07f81d9d | 21 | loadUserVideoPreferences = true |
0626e7af | 22 | |
0aa52e17 C |
23 | filter: VideoFilter = null |
24 | ||
900f7820 C |
25 | displayOptions: MiniatureDisplayOptions = { |
26 | date: true, | |
27 | views: true, | |
28 | by: false, | |
29 | avatar: false, | |
30 | privacyLabel: true, | |
31 | privacyText: false, | |
32 | state: false, | |
33 | blacklistInfo: false | |
34 | } | |
35 | ||
170726f5 | 36 | private videoChannel: VideoChannel |
734a5ceb | 37 | private videoChannelSub: Subscription |
0626e7af C |
38 | |
39 | constructor ( | |
40 | protected router: Router, | |
489290b8 | 41 | protected serverService: ServerService, |
0626e7af C |
42 | protected route: ActivatedRoute, |
43 | protected authService: AuthService, | |
d3217560 | 44 | protected userService: UserService, |
f8b2c1b4 | 45 | protected notifier: Notifier, |
0626e7af | 46 | protected confirmService: ConfirmService, |
bbe0f064 | 47 | protected screenService: ScreenService, |
d3217560 | 48 | protected storageService: LocalStorageService, |
5bcbcbe3 | 49 | protected cfr: ComponentFactoryResolver, |
170726f5 | 50 | private videoChannelService: VideoChannelService, |
0626e7af C |
51 | private videoService: VideoService |
52 | ) { | |
53 | super() | |
b1d40cff | 54 | |
66357162 | 55 | this.titlePage = $localize`Published videos` |
e66883b3 RK |
56 | this.displayOptions = { |
57 | ...this.displayOptions, | |
58 | avatar: false | |
59 | } | |
0626e7af C |
60 | } |
61 | ||
62 | ngOnInit () { | |
63 | super.ngOnInit() | |
64 | ||
0aa52e17 C |
65 | this.enableAllFilterIfPossible() |
66 | ||
170726f5 | 67 | // Parent get the video channel for us |
07f81d9d C |
68 | this.videoChannelSub = forkJoin([ |
69 | this.videoChannelService.videoChannelLoaded.pipe(first()), | |
70 | this.onUserLoadedSubject.pipe(first()) | |
71 | ]).subscribe(([ videoChannel ]) => { | |
72 | this.videoChannel = videoChannel | |
73 | ||
74 | this.reloadVideos() | |
75 | this.generateSyndicationList() | |
76 | }) | |
0626e7af C |
77 | } |
78 | ||
79 | ngOnDestroy () { | |
734a5ceb C |
80 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() |
81 | ||
0626e7af C |
82 | super.ngOnDestroy() |
83 | } | |
84 | ||
85 | getVideosObservable (page: number) { | |
86 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
0aa52e17 C |
87 | const options = { |
88 | videoChannel: this.videoChannel, | |
89 | videoPagination: newPagination, | |
90 | sort: this.sort, | |
91 | nsfwPolicy: this.nsfwPolicy, | |
92 | videoFilter: this.filter | |
93 | } | |
0626e7af | 94 | |
0bf1f265 | 95 | return this.videoService |
0aa52e17 | 96 | .getVideoChannelVideos(options) |
b1d40cff | 97 | .pipe( |
93cae479 | 98 | tap(({ total }) => { |
66357162 C |
99 | this.titlePage = total === 1 |
100 | ? $localize`Published 1 video` | |
101 | : $localize`Published ${total} videos` | |
b1d40cff C |
102 | }) |
103 | ) | |
0626e7af C |
104 | } |
105 | ||
106 | generateSyndicationList () { | |
170726f5 | 107 | this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) |
0626e7af | 108 | } |
0aa52e17 C |
109 | |
110 | toggleModerationDisplay () { | |
111 | this.filter = this.buildLocalFilter(this.filter, null) | |
112 | ||
113 | this.reloadVideos() | |
114 | } | |
0626e7af | 115 | } |