]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
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 { ServerService } from '@app/core'
6 import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
7
8 @Component({
9 selector: 'my-videos-add',
10 templateUrl: './video-add.component.html',
11 styleUrls: [ './video-add.component.scss' ]
12 })
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
17
18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
19 videoName: string
20
21 constructor (
22 private serverService: ServerService
23 ) {}
24
25 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
26 this.secondStepType = type
27 this.videoName = videoName
28 }
29
30 onError () {
31 this.videoName = undefined
32 this.secondStepType = undefined
33 }
34
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} {
46 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
47 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
48 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
49
50 return { canDeactivate: true }
51 }
52
53 isVideoImportHttpEnabled () {
54 return this.serverService.getConfig().import.videos.http.enabled
55 }
56
57 isVideoImportTorrentEnabled () {
58 return this.serverService.getConfig().import.videos.torrent.enabled
59 }
60 }