1 import { finalize } from 'rxjs/operators'
2 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
3 import { AuthService, Notifier } from '@app/core'
4 import { VideoFilter, VideoSortField } from '@shared/models'
5 import { Video, VideoService } from '../../shared-main'
6 import { MiniatureDisplayOptions } from '../../shared-video-miniature'
7 import { CustomMarkupComponent } from './shared'
10 * Markup component list videos depending on criterias
14 selector: 'my-videos-list-markup',
15 templateUrl: 'videos-list-markup.component.html',
16 styleUrls: [ 'videos-list-markup.component.scss' ]
18 export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit {
20 @Input() categoryOneOf: number[]
21 @Input() languageOneOf: string[]
22 @Input() count: number
23 @Input() onlyDisplayTitle: boolean
24 @Input() filter: VideoFilter
25 @Input() maxRows: number
26 @Input() channelHandle: string
27 @Input() accountHandle: string
29 @Output() loaded = new EventEmitter<boolean>()
33 displayOptions: MiniatureDisplayOptions = {
45 private auth: AuthService,
46 private videoService: VideoService,
47 private notifier: Notifier
51 return this.auth.getUser()
55 if (this.maxRows <= 0) return {}
58 'grid-template-rows': `repeat(${this.maxRows}, 1fr)`,
59 'grid-auto-rows': '0', // Set height to 0 for autogenerated grid rows
60 'overflow-y': 'hidden' // Hide grid items that overflow
65 if (this.onlyDisplayTitle) {
66 for (const key of Object.keys(this.displayOptions)) {
67 this.displayOptions[key] = false
71 return this.getVideosObservable()
72 .pipe(finalize(() => this.loaded.emit(true)))
74 ({ data }) => this.videos = data,
76 err => this.notifier.error('Error in videos list component: ' + err.message)
80 getVideosObservable () {
84 itemsPerPage: this.count
86 categoryOneOf: this.categoryOneOf,
87 languageOneOf: this.languageOneOf,
89 sort: this.sort as VideoSortField,
90 account: { nameWithHost: this.accountHandle },
91 videoChannel: { nameWithHost: this.channelHandle }
94 if (this.channelHandle) return this.videoService.getVideoChannelVideos(options)
95 if (this.accountHandle) return this.videoService.getAccountVideos(options)
97 return this.videoService.getVideos(options)