]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
Translated using Weblate (Swedish)
[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, 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 private videoChannelService: VideoChannelService,
38 private videoService: VideoService
39 ) {
40 super()
41
42 this.titlePage = $localize`Published videos`
43 this.displayOptions = {
44 ...this.displayOptions,
45 avatar: false
46 }
47 }
48
49 ngOnInit () {
50 super.ngOnInit()
51
52 this.enableAllFilterIfPossible()
53
54 // Parent get the video channel for us
55 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
56 .pipe(first())
57 .subscribe(videoChannel => {
58 this.videoChannel = videoChannel
59
60 this.reloadVideos()
61 this.generateSyndicationList()
62 })
63 }
64
65 ngOnDestroy () {
66 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
67
68 super.ngOnDestroy()
69 }
70
71 getVideosObservable (page: number) {
72 const newPagination = immutableAssign(this.pagination, { currentPage: page })
73 const options = {
74 videoChannel: this.videoChannel,
75 videoPagination: newPagination,
76 sort: this.sort,
77 nsfwPolicy: this.nsfwPolicy,
78 videoFilter: this.filter
79 }
80
81 return this.videoService
82 .getVideoChannelVideos(options)
83 .pipe(
84 tap(({ total }) => {
85 this.titlePage = total === 1
86 ? $localize`Published 1 video`
87 : $localize`Published ${total} videos`
88 })
89 )
90 }
91
92 generateSyndicationList () {
93 this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
94 }
95
96 toggleModerationDisplay () {
97 this.filter = this.buildLocalFilter(this.filter, null)
98
99 this.reloadVideos()
100 }
101 }