]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
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'
8
9 @Component({
10 selector: 'my-video-share',
11 templateUrl: './video-share.component.html',
12 styleUrls: [ './video-share.component.scss' ]
13 })
14 export class VideoShareComponent {
15 @ViewChild('modal') modal: ElementRef
16
17 @Input() video: VideoDetails = null
18
19 startAtCheckbox = false
20 currentVideoTimestampString: string
21
22 private currentVideoTimestamp: number
23
24 constructor (
25 private modalService: NgbModal,
26 private notifier: Notifier,
27 private i18n: I18n
28 ) { }
29
30 show (currentVideoTimestamp?: number) {
31 this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
32 this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
33
34 this.modalService.open(this.modal)
35 }
36
37 getVideoIframeCode () {
38 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
39
40 return buildVideoEmbed(embedUrl)
41 }
42
43 getVideoUrl () {
44 return buildVideoLink(this.getVideoTimestampIfEnabled())
45 }
46
47 notSecure () {
48 return window.location.protocol === 'http:'
49 }
50
51 activateCopiedMessage () {
52 this.notifier.success(this.i18n('Copied'))
53 }
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 }
64 }