]>
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' | |
8 | import { AbstractVideoList } 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 | ||
170726f5 | 25 | private videoChannel: VideoChannel |
734a5ceb | 26 | private videoChannelSub: Subscription |
0626e7af C |
27 | |
28 | constructor ( | |
29 | protected router: Router, | |
489290b8 | 30 | protected serverService: ServerService, |
0626e7af C |
31 | protected route: ActivatedRoute, |
32 | protected authService: AuthService, | |
d3217560 | 33 | protected userService: UserService, |
f8b2c1b4 | 34 | protected notifier: Notifier, |
0626e7af | 35 | protected confirmService: ConfirmService, |
bbe0f064 | 36 | protected screenService: ScreenService, |
d3217560 | 37 | protected storageService: LocalStorageService, |
5bcbcbe3 | 38 | protected cfr: ComponentFactoryResolver, |
170726f5 | 39 | private videoChannelService: VideoChannelService, |
0626e7af C |
40 | private videoService: VideoService |
41 | ) { | |
42 | super() | |
b1d40cff | 43 | |
66357162 | 44 | this.titlePage = $localize`Published videos` |
e66883b3 RK |
45 | this.displayOptions = { |
46 | ...this.displayOptions, | |
47 | avatar: false | |
48 | } | |
0626e7af C |
49 | } |
50 | ||
51 | ngOnInit () { | |
52 | super.ngOnInit() | |
53 | ||
0aa52e17 C |
54 | this.enableAllFilterIfPossible() |
55 | ||
170726f5 | 56 | // Parent get the video channel for us |
07f81d9d C |
57 | this.videoChannelSub = forkJoin([ |
58 | this.videoChannelService.videoChannelLoaded.pipe(first()), | |
59 | this.onUserLoadedSubject.pipe(first()) | |
60 | ]).subscribe(([ videoChannel ]) => { | |
61 | this.videoChannel = videoChannel | |
62 | ||
63 | this.reloadVideos() | |
64 | this.generateSyndicationList() | |
65 | }) | |
0626e7af C |
66 | } |
67 | ||
68 | ngOnDestroy () { | |
734a5ceb C |
69 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() |
70 | ||
0626e7af C |
71 | super.ngOnDestroy() |
72 | } | |
73 | ||
74 | getVideosObservable (page: number) { | |
75 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
0aa52e17 C |
76 | const options = { |
77 | videoChannel: this.videoChannel, | |
78 | videoPagination: newPagination, | |
79 | sort: this.sort, | |
80 | nsfwPolicy: this.nsfwPolicy, | |
81 | videoFilter: this.filter | |
82 | } | |
0626e7af | 83 | |
0bf1f265 | 84 | return this.videoService |
0aa52e17 | 85 | .getVideoChannelVideos(options) |
b1d40cff | 86 | .pipe( |
93cae479 | 87 | tap(({ total }) => { |
66357162 C |
88 | this.titlePage = total === 1 |
89 | ? $localize`Published 1 video` | |
90 | : $localize`Published ${total} videos` | |
b1d40cff C |
91 | }) |
92 | ) | |
0626e7af C |
93 | } |
94 | ||
95 | generateSyndicationList () { | |
170726f5 | 96 | this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) |
0626e7af | 97 | } |
0aa52e17 C |
98 | |
99 | toggleModerationDisplay () { | |
100 | this.filter = this.buildLocalFilter(this.filter, null) | |
101 | ||
102 | this.reloadVideos() | |
103 | } | |
0626e7af | 104 | } |