]>
Commit | Line | Data |
---|---|---|
1 | import { forkJoin, Subscription } from 'rxjs' | |
2 | import { first, tap } from 'rxjs/operators' | |
3 | import { Component, ComponentFactoryResolver, OnDestroy, OnInit } from '@angular/core' | |
4 | import { ActivatedRoute, Router } from '@angular/router' | |
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' | |
9 | import { VideoFilter } from '@shared/models' | |
10 | ||
11 | @Component({ | |
12 | selector: 'my-video-channel-videos', | |
13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', | |
14 | styleUrls: [ | |
15 | '../../shared/shared-video-miniature/abstract-video-list.scss' | |
16 | ] | |
17 | }) | |
18 | export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
19 | titlePage: string | |
20 | loadOnInit = false | |
21 | loadUserVideoPreferences = true | |
22 | ||
23 | filter: VideoFilter = null | |
24 | ||
25 | private videoChannel: VideoChannel | |
26 | private videoChannelSub: Subscription | |
27 | ||
28 | constructor ( | |
29 | protected router: Router, | |
30 | protected serverService: ServerService, | |
31 | protected route: ActivatedRoute, | |
32 | protected authService: AuthService, | |
33 | protected userService: UserService, | |
34 | protected notifier: Notifier, | |
35 | protected confirmService: ConfirmService, | |
36 | protected screenService: ScreenService, | |
37 | protected storageService: LocalStorageService, | |
38 | protected cfr: ComponentFactoryResolver, | |
39 | private videoChannelService: VideoChannelService, | |
40 | private videoService: VideoService | |
41 | ) { | |
42 | super() | |
43 | ||
44 | this.titlePage = $localize`Published videos` | |
45 | this.displayOptions = { | |
46 | ...this.displayOptions, | |
47 | avatar: false | |
48 | } | |
49 | } | |
50 | ||
51 | ngOnInit () { | |
52 | super.ngOnInit() | |
53 | ||
54 | this.enableAllFilterIfPossible() | |
55 | ||
56 | // Parent get the video channel for us | |
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 | }) | |
66 | } | |
67 | ||
68 | ngOnDestroy () { | |
69 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
70 | ||
71 | super.ngOnDestroy() | |
72 | } | |
73 | ||
74 | getVideosObservable (page: number) { | |
75 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
76 | const options = { | |
77 | videoChannel: this.videoChannel, | |
78 | videoPagination: newPagination, | |
79 | sort: this.sort, | |
80 | nsfwPolicy: this.nsfwPolicy, | |
81 | videoFilter: this.filter | |
82 | } | |
83 | ||
84 | return this.videoService | |
85 | .getVideoChannelVideos(options) | |
86 | .pipe( | |
87 | tap(({ total }) => { | |
88 | this.titlePage = total === 1 | |
89 | ? $localize`Published 1 video` | |
90 | : $localize`Published ${total} videos` | |
91 | }) | |
92 | ) | |
93 | } | |
94 | ||
95 | generateSyndicationList () { | |
96 | this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) | |
97 | } | |
98 | ||
99 | toggleModerationDisplay () { | |
100 | this.filter = this.buildLocalFilter(this.filter, null) | |
101 | ||
102 | this.reloadVideos() | |
103 | } | |
104 | } |