]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-watch/modal/video-share.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-share.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, Input, ViewChild } from '@angular/core'
f8b2c1b4 2import { Notifier } from '@app/core'
4635f59d 3import { VideoDetails } from '../../../shared/video/video-details.model'
11b8762f 4import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
b1d40cff 5import { I18n } from '@ngx-translate/i18n-polyfill'
63347a0f 6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
11b8762f 7import { 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})
14export 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,
f8b2c1b4 26 private notifier: Notifier,
b1d40cff 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 () {
f8b2c1b4 52 this.notifier.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}