]>
Commit | Line | Data |
---|---|---|
0626e7af C |
1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
0626e7af | 3 | import { immutableAssign } from '@app/shared/misc/utils' |
0626e7af C |
4 | import { AuthService } from '../../core/auth' |
5 | import { ConfirmService } from '../../core/confirm' | |
6 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | |
7 | import { VideoService } from '../../shared/video/video.service' | |
170726f5 C |
8 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
9 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
722bca90 | 10 | import { first, tap } from 'rxjs/operators' |
b1d40cff | 11 | import { I18n } from '@ngx-translate/i18n-polyfill' |
734a5ceb | 12 | import { Subscription } from 'rxjs' |
bbe0f064 | 13 | import { ScreenService } from '@app/shared/misc/screen.service' |
489290b8 | 14 | import { Notifier, ServerService } from '@app/core' |
d3217560 RK |
15 | import { UserService } from '@app/shared' |
16 | import { LocalStorageService } from '@app/shared/misc/storage.service' | |
0626e7af C |
17 | |
18 | @Component({ | |
170726f5 | 19 | selector: 'my-video-channel-videos', |
0626e7af C |
20 | templateUrl: '../../shared/video/abstract-video-list.html', |
21 | styleUrls: [ | |
22 | '../../shared/video/abstract-video-list.scss', | |
170726f5 | 23 | './video-channel-videos.component.scss' |
0626e7af C |
24 | ] |
25 | }) | |
170726f5 | 26 | export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { |
b1d40cff | 27 | titlePage: string |
0626e7af C |
28 | loadOnInit = false |
29 | ||
170726f5 | 30 | private videoChannel: VideoChannel |
734a5ceb | 31 | private videoChannelSub: Subscription |
0626e7af C |
32 | |
33 | constructor ( | |
34c7f429 | 34 | protected i18n: I18n, |
0626e7af | 35 | protected router: Router, |
489290b8 | 36 | protected serverService: ServerService, |
0626e7af C |
37 | protected route: ActivatedRoute, |
38 | protected authService: AuthService, | |
d3217560 | 39 | protected userService: UserService, |
f8b2c1b4 | 40 | protected notifier: Notifier, |
0626e7af | 41 | protected confirmService: ConfirmService, |
bbe0f064 | 42 | protected screenService: ScreenService, |
d3217560 | 43 | protected storageService: LocalStorageService, |
170726f5 | 44 | private videoChannelService: VideoChannelService, |
0626e7af C |
45 | private videoService: VideoService |
46 | ) { | |
47 | super() | |
b1d40cff C |
48 | |
49 | this.titlePage = this.i18n('Published videos') | |
0626e7af C |
50 | } |
51 | ||
52 | ngOnInit () { | |
53 | super.ngOnInit() | |
54 | ||
170726f5 | 55 | // Parent get the video channel for us |
734a5ceb | 56 | this.videoChannelSub = this.videoChannelService.videoChannelLoaded |
722bca90 C |
57 | .pipe(first()) |
58 | .subscribe(videoChannel => { | |
59 | this.videoChannel = videoChannel | |
0626e7af | 60 | |
722bca90 C |
61 | this.reloadVideos() |
62 | this.generateSyndicationList() | |
63 | }) | |
0626e7af C |
64 | } |
65 | ||
66 | ngOnDestroy () { | |
734a5ceb C |
67 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() |
68 | ||
0626e7af C |
69 | super.ngOnDestroy() |
70 | } | |
71 | ||
72 | getVideosObservable (page: number) { | |
73 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
74 | ||
0bf1f265 C |
75 | return this.videoService |
76 | .getVideoChannelVideos(this.videoChannel, newPagination, this.sort) | |
b1d40cff | 77 | .pipe( |
93cae479 | 78 | tap(({ total }) => { |
0b1de586 | 79 | this.titlePage = this.i18n(`{total, plural, =1 {Published 1 video} other {Published {{total}} videos}}`, { total }) |
b1d40cff C |
80 | }) |
81 | ) | |
0626e7af C |
82 | } |
83 | ||
84 | generateSyndicationList () { | |
170726f5 | 85 | this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) |
0626e7af C |
86 | } |
87 | } |