]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/modal/video-share.component.ts
remove unused imports
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-share.component.ts
index 14f557f9acb608f467e7558434bd40dbb0a38243..17e2b31e1bb8e4b3c974fc064ee4e22162aa39f9 100644 (file)
@@ -1,9 +1,10 @@
 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
 import { NotificationsService } from 'angular2-notifications'
 import { VideoDetails } from '../../../shared/video/video-details.model'
-import { buildVideoEmbed } from '../../../../assets/player/utils'
+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',
@@ -11,28 +12,36 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
   styleUrls: [ './video-share.component.scss' ]
 })
 export class VideoShareComponent {
+  @ViewChild('modal') modal: ElementRef
+
   @Input() video: VideoDetails = null
 
-  @ViewChild('modal') modal: ElementRef
+  startAtCheckbox = false
+  currentVideoTimestampString: string
+
+  private currentVideoTimestamp: number
 
   constructor (
     private modalService: NgbModal,
     private notificationsService: NotificationsService,
     private i18n: I18n
-  ) {
-    // empty
-  }
+  ) { }
+
+  show (currentVideoTimestamp?: number) {
+    this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
+    this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
 
-  show () {
     this.modalService.open(this.modal)
   }
 
   getVideoIframeCode () {
-    return buildVideoEmbed(this.video.embedUrl)
+    const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
+
+    return buildVideoEmbed(embedUrl)
   }
 
   getVideoUrl () {
-    return window.location.href
+    return buildVideoLink(this.getVideoTimestampIfEnabled())
   }
 
   notSecure () {
@@ -42,4 +51,14 @@ export class VideoShareComponent {
   activateCopiedMessage () {
     this.notificationsService.success(this.i18n('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
+  }
 }