]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/modal/video-share.component.ts
Merge branch 'feature/correctly-send-activities' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-share.component.ts
index 5c988a43b51fb3797d7a53ce116b8cc6bdd1189e..c6205e355ca53076f14e7eb454a3af96901b8ad5 100644 (file)
@@ -1,11 +1,10 @@
-import { Component, Input, ViewChild } from '@angular/core'
-
-import { NotificationsService } from 'angular2-notifications'
-
-import { ModalDirective } from 'ngx-bootstrap/modal'
+import { Component, ElementRef, Input, ViewChild } from '@angular/core'
+import { Notifier } from '@app/core'
 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',
@@ -13,31 +12,36 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
   styleUrls: [ './video-share.component.scss' ]
 })
 export class VideoShareComponent {
+  @ViewChild('modal') modal: ElementRef
+
   @Input() video: VideoDetails = null
 
-  @ViewChild('modal') modal: ModalDirective
+  startAtCheckbox = false
+  currentVideoTimestampString: string
+
+  private currentVideoTimestamp: number
 
   constructor (
-    private notificationsService: NotificationsService,
+    private modalService: NgbModal,
+    private notifier: Notifier,
     private i18n: I18n
-  ) {
-    // empty
-  }
+  ) { }
 
-  show () {
-    this.modal.show()
-  }
+  show (currentVideoTimestamp?: number) {
+    this.currentVideoTimestamp = Math.floor(currentVideoTimestamp)
+    this.currentVideoTimestampString = durationToString(this.currentVideoTimestamp)
 
-  hide () {
-    this.modal.hide()
+    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 () {
@@ -45,6 +49,16 @@ export class VideoShareComponent {
   }
 
   activateCopiedMessage () {
-    this.notificationsService.success(this.i18n('Success'), this.i18n('Copied'))
+    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
   }
 }