]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/video-watch.component.ts
Fix client development so that it uses the local ng binary; (#177)
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
index e35b02f3f57a347e145bfa535e37885cc89b24e7..f1f19476483f29455b5f571e388cb21b289c6357 100644 (file)
@@ -14,9 +14,9 @@ import { VideoDetails } from '../../shared/video/video-details.model'
 import { Video } from '../../shared/video/video.model'
 import { VideoService } from '../../shared/video/video.service'
 import { MarkdownService } from '../shared'
-import { VideoDownloadComponent } from './video-download.component'
-import { VideoReportComponent } from './video-report.component'
-import { VideoShareComponent } from './video-share.component'
+import { VideoDownloadComponent } from './modal/video-download.component'
+import { VideoReportComponent } from './modal/video-report.component'
+import { VideoShareComponent } from './modal/video-share.component'
 
 @Component({
   selector: 'my-video-watch',
@@ -33,7 +33,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   error = false
   loading = false
   player: videojs.Player
-  playerElement: HTMLMediaElement
+  playerElement: HTMLVideoElement
   userRating: UserVideoRateType = null
   video: VideoDetails = null
   videoPlayerLoaded = false
@@ -44,6 +44,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   completeVideoDescription: string
   shortVideoDescription: string
   videoHTMLDescription = ''
+  likesBarTooltipText = ''
 
   private paramsSub: Subscription
 
@@ -136,7 +137,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   blacklistVideo (event: Event) {
     event.preventDefault()
 
-    this.confirmService.confirm('Do you really want to blacklist this video ?', 'Blacklist').subscribe(
+    this.confirmService.confirm('Do you really want to blacklist this video?', 'Blacklist').subscribe(
       res => {
         if (res === false) return
 
@@ -147,7 +148,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
                                       this.router.navigate(['/videos/list'])
                                     },
 
-                                    error => this.notificationsService.error('Error', error.text)
+                                    error => this.notificationsService.error('Error', error.message)
                                   )
       }
     )
@@ -184,7 +185,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
 
         error => {
           this.descriptionLoading = false
-          this.notificationsService.error('Error', error.text)
+          this.notificationsService.error('Error', error.message)
         }
       )
   }
@@ -207,12 +208,16 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     return this.authService.isLoggedIn()
   }
 
+  isVideoUpdatable () {
+    return this.video.isUpdatableBy(this.authService.getUser())
+  }
+
   isVideoBlacklistable () {
     return this.video.isBlackistableBy(this.user)
   }
 
   getAvatarPath () {
-    return Account.GET_ACCOUNT_AVATAR_PATH(this.video.account)
+    return Account.GET_ACCOUNT_AVATAR_URL(this.video.account)
   }
 
   getVideoTags () {
@@ -221,6 +226,33 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     return this.video.tags.join(', ')
   }
 
+  isVideoRemovable () {
+    return this.video.isRemovableBy(this.authService.getUser())
+  }
+
+  removeVideo (event: Event) {
+    event.preventDefault()
+
+    this.confirmService.confirm('Do you really want to delete this video?', 'Delete')
+      .subscribe(
+        res => {
+          if (res === false) return
+
+          this.videoService.removeVideo(this.video.id)
+            .subscribe(
+              status => {
+                this.notificationsService.success('Success', `Video ${this.video.name} deleted.`)
+
+                // Go back to the video-list.
+                this.router.navigate([ '/videos/list' ])
+              },
+
+              error => this.notificationsService.error('Error', error.message)
+            )
+        }
+      )
+  }
+
   private updateVideoDescription (description: string) {
     this.video.description = description
     this.setVideoDescriptionHTML()
@@ -235,6 +267,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     this.videoHTMLDescription = this.markdownService.markdownToHTML(this.video.description)
   }
 
+  private setVideoLikesBarTooltipText () {
+    this.likesBarTooltipText = `${this.video.likes} likes / ${this.video.dislikes} dislikes`
+  }
+
   private handleError (err: any) {
     const errorMessage: string = typeof err === 'string' ? err : err.message
     let message = ''
@@ -288,14 +324,19 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
         if (this.videoPlayerLoaded !== true) {
           this.playerElement = this.elementRef.nativeElement.querySelector('#video-element')
 
+          // If autoplay is true, we don't really need a poster
+          if (this.isAutoplay() === false) {
+            this.playerElement.poster = this.video.previewUrl
+          }
+
           const videojsOptions = {
             controls: true,
-            autoplay: this.user.autoPlayVideo,
+            autoplay: this.isAutoplay(),
             plugins: {
               peertube: {
                 videoFiles: this.video.files,
                 playerElement: this.playerElement,
-                autoplay: this.user.autoPlayVideo,
+                autoplay: this.isAutoplay(),
                 peerTubeLink: false
               }
             }
@@ -315,6 +356,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
         }
 
         this.setVideoDescriptionHTML()
+        this.setVideoLikesBarTooltipText()
 
         this.setOpenGraphTags()
         this.checkUserRating()
@@ -373,4 +415,12 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
 
     }, viewTimeoutSeconds * 1000)
   }
+
+  private isAutoplay () {
+    // True by default
+    if (!this.user) return true
+
+    // Be sure the autoPlay is set to false
+    return this.user.autoPlayVideo !== false
+  }
 }