]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/video-watch.component.ts
Move video form inside a component
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
index 2a7290cbd99735de3ebd45c3273aff4a9c0403b4..87db023bfe6d7ec0d00eadae218b3c112b9a1568 100644 (file)
@@ -1,22 +1,22 @@
 import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
+import { MetaService } from '@ngx-meta/core'
+import { NotificationsService } from 'angular2-notifications'
+import { VideoService } from 'app/shared/video/video.service'
 import { Observable } from 'rxjs/Observable'
 import { Subscription } from 'rxjs/Subscription'
-
 import videojs from 'video.js'
+import { UserVideoRateType, VideoRateType } from '../../../../../shared'
 import '../../../assets/player/peertube-videojs-plugin'
-
-import { MetaService } from '@ngx-meta/core'
-import { NotificationsService } from 'angular2-notifications'
-
 import { AuthService, ConfirmService } from '../../core'
+import { VideoBlacklistService } from '../../shared'
+import { Account } from '../../shared/account/account.model'
+import { VideoDetails } from '../../shared/video/video-details.model'
+import { Video } from '../../shared/video/video.model'
+import { MarkdownService } from '../shared'
 import { VideoDownloadComponent } from './video-download.component'
-import { VideoShareComponent } from './video-share.component'
 import { VideoReportComponent } from './video-report.component'
-import { VideoDetails, VideoService, MarkdownService } from '../shared'
-import { VideoBlacklistService } from '../../shared'
-import { UserVideoRateType, VideoRateType } from '../../../../../shared'
-import { BehaviorSubject } from 'rxjs/BehaviorSubject'
+import { VideoShareComponent } from './video-share.component'
 
 @Component({
   selector: 'my-video-watch',
@@ -28,13 +28,12 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   @ViewChild('videoShareModal') videoShareModal: VideoShareComponent
   @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
 
-  downloadSpeed: number
+  otherVideos: Video[] = []
+
   error = false
   loading = false
-  numPeers: number
   player: videojs.Player
   playerElement: HTMLMediaElement
-  uploadSpeed: number
   userRating: UserVideoRateType = null
   video: VideoDetails = null
   videoPlayerLoaded = false
@@ -62,6 +61,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   ) {}
 
   ngOnInit () {
+    this.videoService.getVideos({ currentPage: 1, itemsPerPage: 5 }, '-createdAt')
+      .subscribe(
+        data => this.otherVideos = data.videos,
+
+    err => console.error(err)
+      )
+
     this.paramsSub = this.route.params.subscribe(routeParams => {
       let uuid = routeParams['uuid']
       this.videoService.getVideo(uuid).subscribe(
@@ -119,27 +125,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
                      )
   }
 
-  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.text)
-                          )
-      }
-    )
-  }
-
   blacklistVideo (event: Event) {
     event.preventDefault()
 
@@ -170,7 +155,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   }
 
   showLessDescription () {
-
     this.updateVideoDescription(this.shortVideoDescription)
     this.completeDescriptionShown = false
   }
@@ -215,16 +199,18 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     return this.authService.isLoggedIn()
   }
 
-  canUserUpdateVideo () {
-    return this.video.isUpdatableBy(this.authService.getUser())
+  isVideoBlacklistable () {
+    return this.video.isBlackistableBy(this.authService.getUser())
   }
 
-  isVideoRemovable () {
-    return this.video.isRemovableBy(this.authService.getUser())
+  getAvatarPath () {
+    return Account.GET_ACCOUNT_AVATAR_PATH(this.video.account)
   }
 
-  isVideoBlacklistable () {
-    return this.video.isBlackistableBy(this.authService.getUser())
+  getVideoTags () {
+    if (!this.video || Array.isArray(this.video.tags) === false) return []
+
+    return this.video.tags.join(', ')
   }
 
   private updateVideoDescription (description: string) {
@@ -285,7 +271,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           return this.router.navigate([ '/videos/list' ])
         }
 
-        this.playerElement = this.elementRef.nativeElement.querySelector('#video-container')
+        this.playerElement = this.elementRef.nativeElement.querySelector('#video-element')
 
         const videojsOptions = {
           controls: true,
@@ -308,18 +294,14 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           this.on('customError', (event, data) => {
             self.handleError(data.err)
           })
-
-          this.on('torrentInfo', (event, data) => {
-            self.downloadSpeed = data.downloadSpeed
-            self.numPeers = data.numPeers
-            self.uploadSpeed = data.uploadSpeed
-          })
         })
 
         this.setVideoDescriptionHTML()
 
         this.setOpenGraphTags()
         this.checkUserRating()
+
+        this.prepareViewAdd()
       }
     )
   }
@@ -360,4 +342,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     this.metaService.setTag('og:url', window.location.href)
     this.metaService.setTag('url', window.location.href)
   }
+
+  private prepareViewAdd () {
+    // After 30 seconds (or 3/4 of the video), increment add a view
+    let viewTimeoutSeconds = 30
+    if (this.video.duration < viewTimeoutSeconds) viewTimeoutSeconds = (this.video.duration * 3) / 4
+
+    setTimeout(() => {
+      this.videoService
+        .viewVideo(this.video.uuid)
+        .subscribe()
+
+    }, viewTimeoutSeconds * 1000)
+  }
 }