]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, Input, ViewChild } from '@angular/core' |
c7e1e432 | 2 | import { NotificationsService } from 'angular2-notifications' |
4635f59d | 3 | import { VideoDetails } from '../../../shared/video/video-details.model' |
11b8762f | 4 | import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils' |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
63347a0f | 6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
11b8762f | 7 | import { durationToString } from '@app/shared/misc/utils' |
cf02fbfb C |
8 | |
9 | @Component({ | |
10 | selector: 'my-video-share', | |
c7e1e432 JL |
11 | templateUrl: './video-share.component.html', |
12 | styleUrls: [ './video-share.component.scss' ] | |
cf02fbfb C |
13 | }) |
14 | export class VideoShareComponent { | |
11b8762f C |
15 | @ViewChild('modal') modal: ElementRef |
16 | ||
404b54e1 | 17 | @Input() video: VideoDetails = null |
cf02fbfb | 18 | |
11b8762f C |
19 | startAtCheckbox = false |
20 | currentVideoTimestampString: string | |
21 | ||
22 | private currentVideoTimestamp: number | |
cf02fbfb | 23 | |
b1d40cff | 24 | constructor ( |
63347a0f | 25 | private modalService: NgbModal, |
b1d40cff C |
26 | private notificationsService: NotificationsService, |
27 | private i18n: I18n | |
28 | ) { | |
cf02fbfb C |
29 | // empty |
30 | } | |
31 | ||
11b8762f C |
32 | show (currentVideoTimestamp?: number) { |
33 | this.currentVideoTimestamp = Math.floor(currentVideoTimestamp) | |
34 | this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp) | |
35 | ||
63347a0f | 36 | this.modalService.open(this.modal) |
cf02fbfb C |
37 | } |
38 | ||
df98563e | 39 | getVideoIframeCode () { |
11b8762f C |
40 | const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl) |
41 | ||
42 | return buildVideoEmbed(embedUrl) | |
cf02fbfb C |
43 | } |
44 | ||
df98563e | 45 | getVideoUrl () { |
11b8762f | 46 | return buildVideoLink(this.getVideoTimestampIfEnabled()) |
cf02fbfb | 47 | } |
2c8d4697 | 48 | |
df98563e C |
49 | notSecure () { |
50 | return window.location.protocol === 'http:' | |
2c8d4697 | 51 | } |
c7e1e432 JL |
52 | |
53 | activateCopiedMessage () { | |
b1d40cff | 54 | this.notificationsService.success(this.i18n('Success'), this.i18n('Copied')) |
c7e1e432 | 55 | } |
11b8762f C |
56 | |
57 | getStartCheckboxLabel () { | |
58 | return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString }) | |
59 | } | |
60 | ||
61 | private getVideoTimestampIfEnabled () { | |
62 | if (this.startAtCheckbox === true) return this.currentVideoTimestamp | |
63 | ||
64 | return undefined | |
65 | } | |
cf02fbfb | 66 | } |