]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/video-add.component.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add.component.ts
CommitLineData
674a66bb 1import { Component, HostListener, ViewChild } from '@angular/core'
f6a043df 2import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
78848714
C
3import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
4import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
5d08a6a7 5import { ServerService } from '@app/core'
ce33919c 6import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
1553e15d 7
dc8bc31b
C
8@Component({
9 selector: 'my-videos-add',
27e1a06c 10 templateUrl: './video-add.component.html',
fbad87b0 11 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 12})
fbad87b0 13export class VideoAddComponent implements CanComponentDeactivate {
f36da21e
C
14 @ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
bfb3a98f 17
ce33919c 18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
fbad87b0 19 videoName: string
bbe0f064 20
5d08a6a7
C
21 constructor (
22 private serverService: ServerService
23 ) {}
24
ce33919c 25 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
fbad87b0
C
26 this.secondStepType = type
27 this.videoName = videoName
f6a043df
C
28 }
29
7373507f
C
30 onError () {
31 this.videoName = undefined
32 this.secondStepType = undefined
33 }
34
674a66bb
C
35 @HostListener('window:beforeunload', [ '$event' ])
36 onUnload (event: any) {
37 const { text, canDeactivate } = this.canDeactivate()
38
39 if (canDeactivate) return
40
41 event.returnValue = text
42 return text
43 }
44
45 canDeactivate (): { canDeactivate: boolean, text?: string} {
fbad87b0 46 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
047559af 47 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 48 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
40e87e9e 49
fbad87b0 50 return { canDeactivate: true }
27e1a06c 51 }
5d08a6a7 52
ce33919c
C
53 isVideoImportHttpEnabled () {
54 return this.serverService.getConfig().import.videos.http.enabled
55 }
56
57 isVideoImportTorrentEnabled () {
a84b8fa5 58 return this.serverService.getConfig().import.videos.torrent.enabled
5d08a6a7 59 }
dc8bc31b 60}