1 import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, AuthUser, CanComponentDeactivate, ServerService } from '@app/core'
4 import { ServerConfig } from '@shared/models'
5 import { VideoEditType } from './shared/video-edit.type'
6 import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
7 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
8 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
9 import { VideoUploadComponent } from './video-add-components/video-upload.component'
12 selector: 'my-videos-add',
13 templateUrl: './video-add.component.html',
14 styleUrls: [ './video-add.component.scss' ]
16 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
17 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
18 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
19 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
20 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
24 secondStepType: VideoEditType
29 private serverConfig: ServerConfig
32 private auth: AuthService,
33 private serverService: ServerService,
34 private route: ActivatedRoute,
35 private router: Router
38 get userInformationLoaded () {
39 return this.auth.userInformationLoaded
43 this.user = this.auth.getUser()
45 this.serverConfig = this.serverService.getTmpConfig()
47 this.serverService.getConfig()
48 .subscribe(config => this.serverConfig = config)
50 this.user = this.auth.getUser()
52 if (this.route.snapshot.fragment) {
53 this.onNavChange(this.route.snapshot.fragment)
57 onNavChange (newActiveNav: string) {
58 this.activeNav = newActiveNav
60 this.router.navigate([], { fragment: this.activeNav })
63 onFirstStepDone (type: VideoEditType, videoName: string) {
64 this.secondStepType = type
65 this.videoName = videoName
69 this.videoName = undefined
70 this.secondStepType = undefined
73 @HostListener('window:beforeunload', [ '$event' ])
74 onUnload (event: any) {
75 const { text, canDeactivate } = this.canDeactivate()
77 if (canDeactivate) return
79 event.returnValue = text
83 canDeactivate (): { canDeactivate: boolean, text?: string} {
84 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
85 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
86 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
88 return { canDeactivate: true }
91 isVideoImportHttpEnabled () {
92 return this.serverConfig.import.videos.http.enabled
95 isVideoImportTorrentEnabled () {
96 return this.serverConfig.import.videos.torrent.enabled
99 isVideoLiveEnabled () {
100 return this.serverConfig.live.enabled
104 return !!this.secondStepType
108 return this.user.username === 'root'