]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-edit/video-add.component.ts
Use ::ng-deep instead of /deep/
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add.component.ts
index 64071b40c37753dc4f0dc9f3c4bf5dba418d5c3f..193de441db729b638303e89e92249f3946b1c2d7 100644 (file)
@@ -1,7 +1,9 @@
-import { Component, ViewChild } from '@angular/core'
+import { Component, HostListener, ViewChild } from '@angular/core'
 import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
-import { VideoImportComponent } from '@app/videos/+video-edit/video-import.component'
-import { VideoUploadComponent } from '@app/videos/+video-edit/video-upload.component'
+import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
+import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
+import { ServerService } from '@app/core'
+import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
 
 @Component({
   selector: 'my-videos-add',
@@ -9,21 +11,50 @@ import { VideoUploadComponent } from '@app/videos/+video-edit/video-upload.compo
   styleUrls: [ './video-add.component.scss' ]
 })
 export class VideoAddComponent implements CanComponentDeactivate {
-  @ViewChild('videoUpload') videoUpload: VideoUploadComponent
-  @ViewChild('videoImport') videoImport: VideoImportComponent
+  @ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
+  @ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
+  @ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
 
-  secondStepType: 'upload' | 'import'
+  secondStepType: 'upload' | 'import-url' | 'import-torrent'
   videoName: string
 
-  onFirstStepDone (type: 'upload' | 'import', videoName: string) {
+  constructor (
+    private serverService: ServerService
+  ) {}
+
+  onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
     this.secondStepType = type
     this.videoName = videoName
   }
 
-  canDeactivate () {
+  onError () {
+    this.videoName = undefined
+    this.secondStepType = undefined
+  }
+
+  @HostListener('window:beforeunload', [ '$event' ])
+  onUnload (event: any) {
+    const { text, canDeactivate } = this.canDeactivate()
+
+    if (canDeactivate) return
+
+    event.returnValue = text
+    return text
+  }
+
+  canDeactivate (): { canDeactivate: boolean, text?: string} {
     if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
-    if (this.secondStepType === 'import') return this.videoImport.canDeactivate()
+    if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
+    if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
 
     return { canDeactivate: true }
   }
+
+  isVideoImportHttpEnabled () {
+    return this.serverService.getConfig().import.videos.http.enabled
+  }
+
+  isVideoImportTorrentEnabled () {
+    return this.serverService.getConfig().import.videos.torrent.enabled
+  }
 }