]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Lazy load all routes
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
CommitLineData
ba430d75 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
67ed6552 2import { AuthService, CanComponentDeactivate, ServerService } from '@app/core'
ba430d75 3import { ServerConfig } from '@shared/models'
67ed6552
C
4import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
5import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
6import { VideoUploadComponent } from './video-add-components/video-upload.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})
ba430d75 13export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2f5d2ec5
C
14 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
bfb3a98f 17
ce33919c 18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
fbad87b0 19 videoName: string
ba430d75 20 serverConfig: ServerConfig
bbe0f064 21
5d08a6a7 22 constructor (
cd3d847d 23 private auth: AuthService,
5d08a6a7
C
24 private serverService: ServerService
25 ) {}
26
ba430d75
C
27 ngOnInit () {
28 this.serverConfig = this.serverService.getTmpConfig()
29
30 this.serverService.getConfig()
31 .subscribe(config => this.serverConfig = config)
32 }
33
ce33919c 34 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
fbad87b0
C
35 this.secondStepType = type
36 this.videoName = videoName
f6a043df
C
37 }
38
7373507f
C
39 onError () {
40 this.videoName = undefined
41 this.secondStepType = undefined
42 }
43
674a66bb
C
44 @HostListener('window:beforeunload', [ '$event' ])
45 onUnload (event: any) {
46 const { text, canDeactivate } = this.canDeactivate()
47
48 if (canDeactivate) return
49
50 event.returnValue = text
51 return text
52 }
53
54 canDeactivate (): { canDeactivate: boolean, text?: string} {
fbad87b0 55 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
047559af 56 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 57 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
40e87e9e 58
fbad87b0 59 return { canDeactivate: true }
27e1a06c 60 }
5d08a6a7 61
ce33919c 62 isVideoImportHttpEnabled () {
ba430d75 63 return this.serverConfig.import.videos.http.enabled
ce33919c
C
64 }
65
66 isVideoImportTorrentEnabled () {
ba430d75 67 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 68 }
cd3d847d
C
69
70 isInSecondStep () {
71 return !!this.secondStepType
72 }
73
74 isRootUser () {
75 return this.auth.getUser().username === 'root'
76 }
dc8bc31b 77}