]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-custom-markup/peertube-custom-tags/videos-list-markup.component.ts
Fix custom markup
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / videos-list-markup.component.ts
CommitLineData
8b61dcaf 1import { finalize } from 'rxjs/operators'
647c2b7d 2import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
8b61dcaf 3import { AuthService, Notifier } from '@app/core'
2760b454 4import { VideoSortField } from '@shared/models'
8ee25e17
C
5import { Video, VideoService } from '../../shared-main'
6import { MiniatureDisplayOptions } from '../../shared-video-miniature'
0ca454e3 7import { CustomMarkupComponent } from './shared'
2539932e
C
8
9/*
7a4fd56c 10 * Markup component list videos depending on criteria
2539932e
C
11*/
12
13@Component({
14 selector: 'my-videos-list-markup',
15 templateUrl: 'videos-list-markup.component.html',
bc48e33b
C
16 styleUrls: [ 'videos-list-markup.component.scss' ],
17 changeDetection: ChangeDetectionStrategy.OnPush
2539932e 18})
0ca454e3 19export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit {
9105634f 20 @Input() sort: string
2539932e
C
21 @Input() categoryOneOf: number[]
22 @Input() languageOneOf: string[]
9105634f
C
23 @Input() count: number
24 @Input() onlyDisplayTitle: boolean
2760b454 25 @Input() isLocal: boolean
ff4de383 26 @Input() isLive: boolean
5d6395af 27 @Input() maxRows: number
674d903b
C
28 @Input() channelHandle: string
29 @Input() accountHandle: string
2539932e 30
0ca454e3
C
31 @Output() loaded = new EventEmitter<boolean>()
32
2539932e
C
33 videos: Video[]
34
35 displayOptions: MiniatureDisplayOptions = {
9105634f 36 date: false,
2539932e
C
37 views: true,
38 by: true,
39 avatar: false,
40 privacyLabel: false,
41 privacyText: false,
42 state: false,
43 blacklistInfo: false
44 }
45
46 constructor (
47 private auth: AuthService,
8b61dcaf 48 private videoService: VideoService,
647c2b7d
C
49 private notifier: Notifier,
50 private cd: ChangeDetectorRef
2539932e
C
51 ) { }
52
53 getUser () {
54 return this.auth.getUser()
55 }
56
5d6395af
C
57 limitRowsStyle () {
58 if (this.maxRows <= 0) return {}
59
60 return {
61 'grid-template-rows': `repeat(${this.maxRows}, 1fr)`,
62 'grid-auto-rows': '0', // Set height to 0 for autogenerated grid rows
63 'overflow-y': 'hidden' // Hide grid items that overflow
64 }
65 }
66
2539932e 67 ngOnInit () {
9105634f
C
68 if (this.onlyDisplayTitle) {
69 for (const key of Object.keys(this.displayOptions)) {
70 this.displayOptions[key] = false
71 }
72 }
73
674d903b
C
74 return this.getVideosObservable()
75 .pipe(finalize(() => this.loaded.emit(true)))
1378c0d3 76 .subscribe({
647c2b7d
C
77 next: ({ data }) => {
78 this.videos = data
79 this.cd.markForCheck()
80 },
674d903b 81
1378c0d3
C
82 error: err => this.notifier.error($localize`Error in videos list component: ${err.message}`)
83 })
674d903b
C
84 }
85
86 getVideosObservable () {
2539932e
C
87 const options = {
88 videoPagination: {
89 currentPage: 1,
90 itemsPerPage: this.count
91 },
92 categoryOneOf: this.categoryOneOf,
93 languageOneOf: this.languageOneOf,
2760b454 94 isLocal: this.isLocal,
ff4de383 95 isLive: this.isLive,
674d903b
C
96 sort: this.sort as VideoSortField,
97 account: { nameWithHost: this.accountHandle },
98 videoChannel: { nameWithHost: this.channelHandle }
2539932e
C
99 }
100
674d903b
C
101 if (this.channelHandle) return this.videoService.getVideoChannelVideos(options)
102 if (this.accountHandle) return this.videoService.getAccountVideos(options)
0ca454e3 103
674d903b 104 return this.videoService.getVideos(options)
2539932e
C
105 }
106}