]>
Commit | Line | Data |
---|---|---|
06a55579 C |
1 | import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core' |
2 | import { RedirectService, ScreenService } from '@app/core' | |
3 | import { VideoDetails } from '@app/shared/shared-main' | |
4 | import { VideoShareComponent } from '@app/shared/shared-share-modal' | |
5 | import { SupportModalComponent } from '@app/shared/shared-support-modal' | |
6 | import { VideoActionsDisplayType, VideoDownloadComponent } from '@app/shared/shared-video-miniature' | |
7 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' | |
8 | import { UserVideoRateType, VideoCaption } from '@shared/models/videos' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-action-buttons', | |
12 | templateUrl: './action-buttons.component.html', | |
13 | styleUrls: [ './action-buttons.component.scss' ] | |
14 | }) | |
15 | export class ActionButtonsComponent implements OnInit, OnChanges { | |
16 | @ViewChild('videoShareModal') videoShareModal: VideoShareComponent | |
17 | @ViewChild('supportModal') supportModal: SupportModalComponent | |
18 | @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent | |
19 | ||
20 | @Input() video: VideoDetails | |
21 | @Input() videoCaptions: VideoCaption[] | |
22 | @Input() playlist: VideoPlaylist | |
23 | ||
24 | @Input() isUserLoggedIn: boolean | |
25 | ||
26 | @Input() currentTime: number | |
27 | @Input() currentPlaylistPosition: number | |
28 | ||
29 | likesBarTooltipText = '' | |
30 | ||
31 | tooltipSupport = '' | |
32 | tooltipSaveToPlaylist = '' | |
33 | ||
34 | videoActionsOptions: VideoActionsDisplayType = { | |
35 | playlist: false, | |
36 | download: true, | |
37 | update: true, | |
c729caf6 | 38 | editor: true, |
06a55579 C |
39 | blacklist: true, |
40 | delete: true, | |
41 | report: true, | |
42 | duplicate: true, | |
43 | mute: true, | |
44 | liveInfo: true | |
45 | } | |
46 | ||
47 | userRating: UserVideoRateType | |
48 | ||
49 | constructor ( | |
50 | private screenService: ScreenService, | |
51 | private redirectService: RedirectService | |
52 | ) { } | |
53 | ||
54 | ngOnInit () { | |
55 | // Hide the tooltips for unlogged users in mobile view, this adds confusion with the popover | |
56 | if (this.isUserLoggedIn || !this.screenService.isInMobileView()) { | |
57 | this.tooltipSupport = $localize`Support options for this video` | |
58 | this.tooltipSaveToPlaylist = $localize`Save to playlist` | |
59 | } | |
60 | } | |
61 | ||
62 | ngOnChanges () { | |
63 | this.setVideoLikesBarTooltipText() | |
64 | } | |
65 | ||
66 | showDownloadModal () { | |
67 | this.videoDownloadModal.show(this.video, this.videoCaptions) | |
68 | } | |
69 | ||
70 | isVideoDownloadable () { | |
71 | return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled && !this.video.isLive | |
72 | } | |
73 | ||
74 | showSupportModal () { | |
75 | this.supportModal.show() | |
76 | } | |
77 | ||
78 | showShareModal () { | |
79 | this.videoShareModal.show(this.currentTime, this.currentPlaylistPosition) | |
80 | } | |
81 | ||
82 | onRateUpdated (userRating: UserVideoRateType) { | |
83 | this.userRating = userRating | |
84 | this.setVideoLikesBarTooltipText() | |
85 | } | |
86 | ||
87 | onVideoRemoved () { | |
88 | this.redirectService.redirectToHomepage() | |
89 | } | |
90 | ||
91 | private setVideoLikesBarTooltipText () { | |
92 | this.likesBarTooltipText = `${this.video.likes} likes / ${this.video.dislikes} dislikes` | |
93 | } | |
94 | } |