]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
a49fd0d5ddf79d6d5a87d6bb45c9046e0423a063
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
1 import { 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
22 filter: VideoFilter = null
23
24 private videoChannel: VideoChannel
25 private videoChannelSub: Subscription
26
27 constructor (
28 protected router: Router,
29 protected serverService: ServerService,
30 protected route: ActivatedRoute,
31 protected authService: AuthService,
32 protected userService: UserService,
33 protected notifier: Notifier,
34 protected confirmService: ConfirmService,
35 protected screenService: ScreenService,
36 protected storageService: LocalStorageService,
37 protected cfr: ComponentFactoryResolver,
38 private videoChannelService: VideoChannelService,
39 private videoService: VideoService
40 ) {
41 super()
42
43 this.titlePage = $localize`Published videos`
44 this.displayOptions = {
45 ...this.displayOptions,
46 avatar: false
47 }
48 }
49
50 ngOnInit () {
51 super.ngOnInit()
52
53 this.enableAllFilterIfPossible()
54
55 // Parent get the video channel for us
56 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
57 .pipe(first())
58 .subscribe(videoChannel => {
59 this.videoChannel = videoChannel
60
61 this.reloadVideos()
62 this.generateSyndicationList()
63 })
64 }
65
66 ngOnDestroy () {
67 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
68
69 super.ngOnDestroy()
70 }
71
72 getVideosObservable (page: number) {
73 const newPagination = immutableAssign(this.pagination, { currentPage: page })
74 const options = {
75 videoChannel: this.videoChannel,
76 videoPagination: newPagination,
77 sort: this.sort,
78 nsfwPolicy: this.nsfwPolicy,
79 videoFilter: this.filter
80 }
81
82 return this.videoService
83 .getVideoChannelVideos(options)
84 .pipe(
85 tap(({ total }) => {
86 this.titlePage = total === 1
87 ? $localize`Published 1 video`
88 : $localize`Published ${total} videos`
89 })
90 )
91 }
92
93 generateSyndicationList () {
94 this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
95 }
96
97 toggleModerationDisplay () {
98 this.filter = this.buildLocalFilter(this.filter, null)
99
100 this.reloadVideos()
101 }
102 }