]>
Commit | Line | Data |
---|---|---|
8b61dcaf | 1 | import { finalize } from 'rxjs/operators' |
647c2b7d | 2 | import { ChangeDetectionStrategy, ChangeDetectorRef, 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', | |
bc48e33b C |
16 | styleUrls: [ 'videos-list-markup.component.scss' ], |
17 | changeDetection: ChangeDetectionStrategy.OnPush | |
2539932e | 18 | }) |
0ca454e3 | 19 | export 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 | } |