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
27 @Output() loaded = new EventEmitter<boolean>()
31 displayOptions: MiniatureDisplayOptions = {
43 private auth: AuthService,
44 private videoService: VideoService,
45 private notifier: Notifier
49 return this.auth.getUser()
53 if (this.maxRows <= 0) return {}
56 'grid-template-rows': `repeat(${this.maxRows}, 1fr)`,
57 'grid-auto-rows': '0', // Set height to 0 for autogenerated grid rows
58 'overflow-y': 'hidden' // Hide grid items that overflow
63 if (this.onlyDisplayTitle) {
64 for (const key of Object.keys(this.displayOptions)) {
65 this.displayOptions[key] = false
72 itemsPerPage: this.count
74 categoryOneOf: this.categoryOneOf,
75 languageOneOf: this.languageOneOf,
77 sort: this.sort as VideoSortField
80 this.videoService.getVideos(options)
81 .pipe(finalize(() => this.loaded.emit(true)))
83 ({ data }) => this.videos = data,
85 err => this.notifier.error('Error in videos list component: ' + err.message)