1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
3 import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
4 import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
5 import { AuthService, ServerService } from '@app/core'
6 import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
7 import { ServerConfig } from '@shared/models'
10 selector: 'my-videos-add',
11 templateUrl: './video-add.component.html',
12 styleUrls: [ './video-add.component.scss' ]
14 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
15 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
16 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
17 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
19 secondStepType: 'upload' | 'import-url' | 'import-torrent'
21 serverConfig: ServerConfig
24 private auth: AuthService,
25 private serverService: ServerService
29 this.serverConfig = this.serverService.getTmpConfig()
31 this.serverService.getConfig()
32 .subscribe(config => this.serverConfig = config)
35 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
36 this.secondStepType = type
37 this.videoName = videoName
41 this.videoName = undefined
42 this.secondStepType = undefined
45 @HostListener('window:beforeunload', [ '$event' ])
46 onUnload (event: any) {
47 const { text, canDeactivate } = this.canDeactivate()
49 if (canDeactivate) return
51 event.returnValue = text
55 canDeactivate (): { canDeactivate: boolean, text?: string} {
56 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
57 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
58 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
60 return { canDeactivate: true }
63 isVideoImportHttpEnabled () {
64 return this.serverConfig.import.videos.http.enabled
67 isVideoImportTorrentEnabled () {
68 return this.serverConfig.import.videos.torrent.enabled
72 return !!this.secondStepType
76 return this.auth.getUser().username === 'root'