aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-watch/modal/video-share.component.ts
blob: c6205e355ca53076f14e7eb454a3af96901b8ad5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Component, ElementRef, Input, ViewChild } from '@angular/core'
import { Notifier } from '@app/core'
import { VideoDetails } from '../../../shared/video/video-details.model'
import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { durationToString } from '@app/shared/misc/utils'

@Component({
  selector: 'my-video-share',
  templateUrl: './video-share.component.html',
  styleUrls: [ './video-share.component.scss' ]
})
export class VideoShareComponent {
  @ViewChild('modal') modal: ElementRef

  @Input() video: VideoDetails = null

  startAtCheckbox = false
  currentVideoTimestampString: string

  private currentVideoTimestamp: number

  constructor (
    private modalService: NgbModal,
    private notifier: Notifier,
    private i18n: I18n
  ) { }

  show (currentVideoTimestamp?: number) {
    this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
    this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)

    this.modalService.open(this.modal)
  }

  getVideoIframeCode () {
    const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)

    return buildVideoEmbed(embedUrl)
  }

  getVideoUrl () {
    return buildVideoLink(this.getVideoTimestampIfEnabled())
  }

  notSecure () {
    return window.location.protocol === 'http:'
  }

  activateCopiedMessage () {
    this.notifier.success(this.i18n('Copied'))
  }

  getStartCheckboxLabel () {
    return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString })
  }

  private getVideoTimestampIfEnabled () {
    if (this.startAtCheckbox === true) return this.currentVideoTimestamp

    return undefined
  }
}