]>
Commit | Line | Data |
---|---|---|
1 | import { finalize } from 'rxjs/operators' | |
2 | import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core' | |
3 | import { AuthService, Notifier } from '@app/core' | |
4 | import { VideoSortField } from '@shared/models' | |
5 | import { Video, VideoService } from '../../shared-main' | |
6 | import { MiniatureDisplayOptions } from '../../shared-video-miniature' | |
7 | import { CustomMarkupComponent } from './shared' | |
8 | ||
9 | /* | |
10 | * Markup component list videos depending on criteria | |
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 | changeDetection: ChangeDetectionStrategy.OnPush | |
18 | }) | |
19 | export class VideosListMarkupComponent implements CustomMarkupComponent, OnInit { | |
20 | @Input() sort: string | |
21 | @Input() categoryOneOf: number[] | |
22 | @Input() languageOneOf: string[] | |
23 | @Input() count: number | |
24 | @Input() onlyDisplayTitle: boolean | |
25 | @Input() isLocal: boolean | |
26 | @Input() isLive: boolean | |
27 | @Input() maxRows: number | |
28 | @Input() channelHandle: string | |
29 | @Input() accountHandle: string | |
30 | ||
31 | @Output() loaded = new EventEmitter<boolean>() | |
32 | ||
33 | videos: Video[] | |
34 | ||
35 | displayOptions: MiniatureDisplayOptions = { | |
36 | date: false, | |
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, | |
48 | private videoService: VideoService, | |
49 | private notifier: Notifier, | |
50 | private cd: ChangeDetectorRef | |
51 | ) { } | |
52 | ||
53 | getUser () { | |
54 | return this.auth.getUser() | |
55 | } | |
56 | ||
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 | ||
67 | ngOnInit () { | |
68 | if (this.onlyDisplayTitle) { | |
69 | for (const key of Object.keys(this.displayOptions)) { | |
70 | this.displayOptions[key] = false | |
71 | } | |
72 | } | |
73 | ||
74 | return this.getVideosObservable() | |
75 | .pipe(finalize(() => this.loaded.emit(true))) | |
76 | .subscribe({ | |
77 | next: ({ data }) => { | |
78 | this.videos = data | |
79 | this.cd.markForCheck() | |
80 | }, | |
81 | ||
82 | error: err => this.notifier.error($localize`Error in videos list component: ${err.message}`) | |
83 | }) | |
84 | } | |
85 | ||
86 | getVideosObservable () { | |
87 | const options = { | |
88 | videoPagination: { | |
89 | currentPage: 1, | |
90 | itemsPerPage: this.count | |
91 | }, | |
92 | categoryOneOf: this.categoryOneOf, | |
93 | languageOneOf: this.languageOneOf, | |
94 | isLocal: this.isLocal, | |
95 | isLive: this.isLive, | |
96 | sort: this.sort as VideoSortField, | |
97 | account: { nameWithHost: this.accountHandle }, | |
98 | videoChannel: { nameWithHost: this.channelHandle } | |
99 | } | |
100 | ||
101 | if (this.channelHandle) return this.videoService.getVideoChannelVideos(options) | |
102 | if (this.accountHandle) return this.videoService.getAccountVideos(options) | |
103 | ||
104 | return this.videoService.getVideos(options) | |
105 | } | |
106 | } |