]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/modal/video-share.component.ts
Clean up change password validation
[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 { 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'
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 notificationsService: NotificationsService,
27 private i18n: I18n
28 ) {
29 // empty
30 }
31
32 show (currentVideoTimestamp?: number) {
33 this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
34 this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
35
36 this.modalService.open(this.modal)
37 }
38
39 getVideoIframeCode () {
40 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
41
42 return buildVideoEmbed(embedUrl)
43 }
44
45 getVideoUrl () {
46 return buildVideoLink(this.getVideoTimestampIfEnabled())
47 }
48
49 notSecure () {
50 return window.location.protocol === 'http:'
51 }
52
53 activateCopiedMessage () {
54 this.notificationsService.success(this.i18n('Success'), this.i18n('Copied'))
55 }
56
57 getStartCheckboxLabel () {
58 return this.i18n('Start at {{timestamp}}', { timestamp: this.currentVideoTimestampString })
59 }
60
61 private getVideoTimestampIfEnabled () {
62 if (this.startAtCheckbox === true) return this.currentVideoTimestamp
63
64 return undefined
65 }
66 }