1 import { Component, HostListener, 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'
9 selector: 'my-videos-add',
10 templateUrl: './video-add.component.html',
11 styleUrls: [ './video-add.component.scss' ]
13 export class VideoAddComponent implements CanComponentDeactivate {
14 @ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
22 private auth: AuthService,
23 private serverService: ServerService
26 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
27 this.secondStepType = type
28 this.videoName = videoName
32 this.videoName = undefined
33 this.secondStepType = undefined
36 @HostListener('window:beforeunload', [ '$event' ])
37 onUnload (event: any) {
38 const { text, canDeactivate } = this.canDeactivate()
40 if (canDeactivate) return
42 event.returnValue = text
46 canDeactivate (): { canDeactivate: boolean, text?: string} {
47 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
48 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
49 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
51 return { canDeactivate: true }
54 isVideoImportHttpEnabled () {
55 return this.serverService.getConfig().import.videos.http.enabled
58 isVideoImportTorrentEnabled () {
59 return this.serverService.getConfig().import.videos.torrent.enabled
63 return !!this.secondStepType
67 return this.auth.getUser().username === 'root'