]>
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 | |
23db998f | 28 | ) { } |
cf02fbfb | 29 | |
11b8762f C |
30 | show (currentVideoTimestamp?: number) { |
31 | this.currentVideoTimestamp = Math.floor(currentVideoTimestamp) | |
32 | this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp) | |
33 | ||
63347a0f | 34 | this.modalService.open(this.modal) |
cf02fbfb C |
35 | } |
36 | ||
df98563e | 37 | getVideoIframeCode () { |
11b8762f C |
38 | const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl) |
39 | ||
40 | return buildVideoEmbed(embedUrl) | |
cf02fbfb C |
41 | } |
42 | ||
df98563e | 43 | getVideoUrl () { |
11b8762f | 44 | return buildVideoLink(this.getVideoTimestampIfEnabled()) |
cf02fbfb | 45 | } |
2c8d4697 | 46 | |
df98563e C |
47 | notSecure () { |
48 | return window.location.protocol === 'http:' | |
2c8d4697 | 49 | } |
c7e1e432 JL |
50 | |
51 | activateCopiedMessage () { | |
b1d40cff | 52 | this.notificationsService.success(this.i18n('Success'), this.i18n('Copied')) |
c7e1e432 | 53 | } |
11b8762f C |
54 | |
55 | getStartCheckboxLabel () { | |
56 | return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString }) | |
57 | } | |
58 | ||
59 | private getVideoTimestampIfEnabled () { | |
60 | if (this.startAtCheckbox === true) return this.currentVideoTimestamp | |
61 | ||
62 | return undefined | |
63 | } | |
cf02fbfb | 64 | } |