]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.ts
Refactor video links builders
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / video-miniature-markup.component.ts
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 { Video, VideoService } from '../../shared-main'
5 import { MiniatureDisplayOptions } from '../../shared-video-miniature'
6 import { CustomMarkupComponent } from './shared'
7
8 /*
9 * Markup component that creates a video miniature only
10 */
11
12 @Component({
13 selector: 'my-video-miniature-markup',
14 templateUrl: 'video-miniature-markup.component.html',
15 styleUrls: [ 'video-miniature-markup.component.scss' ]
16 })
17 export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
18 @Input() uuid: string
19 @Input() onlyDisplayTitle: boolean
20
21 @Output() loaded = new EventEmitter<boolean>()
22
23 video: Video
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 videoService: VideoService,
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 this.videoService.getVideo({ videoId: this.uuid })
54 .pipe(finalize(() => this.loaded.emit(true)))
55 .subscribe(
56 video => this.video = video,
57
58 err => this.notifier.error('Error in video miniature component: ' + err.message)
59 )
60 }
61 }