1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { VideoDetails } from '../../../shared/video/video-details.model'
4 import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7 import { durationToString } from '@app/shared/misc/utils'
10 selector: 'my-video-share',
11 templateUrl: './video-share.component.html',
12 styleUrls: [ './video-share.component.scss' ]
14 export class VideoShareComponent {
15 @ViewChild('modal') modal: ElementRef
17 @Input() video: VideoDetails = null
19 startAtCheckbox = false
20 currentVideoTimestampString: string
22 private currentVideoTimestamp: number
25 private modalService: NgbModal,
26 private notificationsService: NotificationsService,
30 show (currentVideoTimestamp?: number) {
31 this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
32 this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
34 this.modalService.open(this.modal)
37 getVideoIframeCode () {
38 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
40 return buildVideoEmbed(embedUrl)
44 return buildVideoLink(this.getVideoTimestampIfEnabled())
48 return window.location.protocol === 'http:'
51 activateCopiedMessage () {
52 this.notificationsService.success(this.i18n('Success'), this.i18n('Copied'))
55 getStartCheckboxLabel () {
56 return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString })
59 private getVideoTimestampIfEnabled () {
60 if (this.startAtCheckbox === true) return this.currentVideoTimestamp