]>
Commit | Line | Data |
---|---|---|
0ca454e3 | 1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' |
2539932e | 2 | import { AuthService } from '@app/core' |
9105634f | 3 | import { VideoFilter, VideoSortField } from '@shared/models' |
8ee25e17 C |
4 | import { Video, VideoService } from '../../shared-main' |
5 | import { MiniatureDisplayOptions } from '../../shared-video-miniature' | |
0ca454e3 | 6 | import { CustomMarkupComponent } from './shared' |
2539932e C |
7 | |
8 | /* | |
9 | * Markup component list videos depending on criterias | |
10 | */ | |
11 | ||
12 | @Component({ | |
13 | selector: 'my-videos-list-markup', | |
14 | templateUrl: 'videos-list-markup.component.html', | |
15 | styleUrls: [ 'videos-list-markup.component.scss' ] | |
16 | }) | |
0ca454e3 | 17 | export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit { |
9105634f | 18 | @Input() sort: string |
2539932e C |
19 | @Input() categoryOneOf: number[] |
20 | @Input() languageOneOf: string[] | |
9105634f C |
21 | @Input() count: number |
22 | @Input() onlyDisplayTitle: boolean | |
23 | @Input() filter: VideoFilter | |
5d6395af | 24 | @Input() maxRows: number |
2539932e | 25 | |
0ca454e3 C |
26 | @Output() loaded = new EventEmitter<boolean>() |
27 | ||
2539932e C |
28 | videos: Video[] |
29 | ||
30 | displayOptions: MiniatureDisplayOptions = { | |
9105634f | 31 | date: false, |
2539932e C |
32 | views: true, |
33 | by: true, | |
34 | avatar: false, | |
35 | privacyLabel: false, | |
36 | privacyText: false, | |
37 | state: false, | |
38 | blacklistInfo: false | |
39 | } | |
40 | ||
41 | constructor ( | |
42 | private auth: AuthService, | |
43 | private videoService: VideoService | |
44 | ) { } | |
45 | ||
46 | getUser () { | |
47 | return this.auth.getUser() | |
48 | } | |
49 | ||
5d6395af C |
50 | limitRowsStyle () { |
51 | if (this.maxRows <= 0) return {} | |
52 | ||
53 | return { | |
54 | 'grid-template-rows': `repeat(${this.maxRows}, 1fr)`, | |
55 | 'grid-auto-rows': '0', // Set height to 0 for autogenerated grid rows | |
56 | 'overflow-y': 'hidden' // Hide grid items that overflow | |
57 | } | |
58 | } | |
59 | ||
2539932e | 60 | ngOnInit () { |
9105634f C |
61 | if (this.onlyDisplayTitle) { |
62 | for (const key of Object.keys(this.displayOptions)) { | |
63 | this.displayOptions[key] = false | |
64 | } | |
65 | } | |
66 | ||
2539932e C |
67 | const options = { |
68 | videoPagination: { | |
69 | currentPage: 1, | |
70 | itemsPerPage: this.count | |
71 | }, | |
72 | categoryOneOf: this.categoryOneOf, | |
73 | languageOneOf: this.languageOneOf, | |
9105634f | 74 | filter: this.filter, |
2539932e C |
75 | sort: this.sort as VideoSortField |
76 | } | |
77 | ||
78 | this.videoService.getVideos(options) | |
0ca454e3 C |
79 | .subscribe({ |
80 | next: ({ data }) => this.videos = data, | |
81 | ||
82 | complete: () => this.loaded.emit(true) | |
83 | }) | |
2539932e C |
84 | } |
85 | } |