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