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,
32 show (currentVideoTimestamp?: number) {
33 this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
34 this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
36 this.modalService.open(this.modal)
39 getVideoIframeCode () {
40 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
42 return buildVideoEmbed(embedUrl)
46 return buildVideoLink(this.getVideoTimestampIfEnabled())
50 return window.location.protocol === 'http:'
53 activateCopiedMessage () {
54 this.notificationsService.success(this.i18n('Success'), this.i18n('Copied'))
57 getStartCheckboxLabel () {
58 return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString })
61 private getVideoTimestampIfEnabled () {
62 if (this.startAtCheckbox === true) return this.currentVideoTimestamp