]>
Commit | Line | Data |
---|---|---|
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 { FindInBulkService } from '@app/shared/shared-search' | |
5 | import { Video } from '../../shared-main' | |
6 | import { MiniatureDisplayOptions } from '../../shared-video-miniature' | |
7 | import { CustomMarkupComponent } from './shared' | |
8 | ||
9 | /* | |
10 | * Markup component that creates a video miniature only | |
11 | */ | |
12 | ||
13 | @Component({ | |
14 | selector: 'my-video-miniature-markup', | |
15 | templateUrl: 'video-miniature-markup.component.html', | |
16 | styleUrls: [ 'video-miniature-markup.component.scss' ] | |
17 | }) | |
18 | export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnInit { | |
19 | @Input() uuid: string | |
20 | @Input() onlyDisplayTitle: boolean | |
21 | @Input() video: Video | |
22 | ||
23 | @Output() loaded = new EventEmitter<boolean>() | |
24 | ||
25 | displayOptions: MiniatureDisplayOptions = { | |
26 | date: true, | |
27 | views: true, | |
28 | by: true, | |
29 | avatar: false, | |
30 | privacyLabel: false, | |
31 | privacyText: false, | |
32 | state: false, | |
33 | blacklistInfo: false | |
34 | } | |
35 | ||
36 | constructor ( | |
37 | private auth: AuthService, | |
38 | private findInBulk: FindInBulkService, | |
39 | private notifier: Notifier | |
40 | ) { } | |
41 | ||
42 | getUser () { | |
43 | return this.auth.getUser() | |
44 | } | |
45 | ||
46 | ngOnInit () { | |
47 | if (this.onlyDisplayTitle) { | |
48 | for (const key of Object.keys(this.displayOptions)) { | |
49 | this.displayOptions[key] = false | |
50 | } | |
51 | } | |
52 | ||
53 | if (this.video) return | |
54 | ||
55 | this.findInBulk.getVideo(this.uuid) | |
56 | .pipe(finalize(() => this.loaded.emit(true))) | |
57 | .subscribe({ | |
58 | next: video => this.video = video, | |
59 | ||
60 | error: err => this.notifier.error($localize`Error in video miniature component: ${err.message}`) | |
61 | }) | |
62 | } | |
63 | } |