]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add.component.ts
Merge branch 'develop' into shorter-URLs-channels-accounts
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
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'
10
11 @Component({
12 selector: 'my-videos-add',
13 templateUrl: './video-add.component.html',
14 styleUrls: [ './video-add.component.scss' ]
15 })
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
21
22 user: AuthUser = null
23
24 secondStepType: VideoEditType
25 videoName: string
26
27 activeNav: string
28
29 private serverConfig: ServerConfig
30
31 constructor (
32 private auth: AuthService,
33 private serverService: ServerService,
34 private route: ActivatedRoute,
35 private router: Router
36 ) {}
37
38 get userInformationLoaded () {
39 return this.auth.userInformationLoaded
40 }
41
42 ngOnInit () {
43 this.user = this.auth.getUser()
44
45 this.serverConfig = this.serverService.getTmpConfig()
46
47 this.serverService.getConfig()
48 .subscribe(config => this.serverConfig = config)
49
50 this.user = this.auth.getUser()
51
52 if (this.route.snapshot.fragment) {
53 this.onNavChange(this.route.snapshot.fragment)
54 }
55 }
56
57 onNavChange (newActiveNav: string) {
58 this.activeNav = newActiveNav
59
60 this.router.navigate([], { fragment: this.activeNav })
61 }
62
63 onFirstStepDone (type: VideoEditType, videoName: string) {
64 this.secondStepType = type
65 this.videoName = videoName
66 }
67
68 onError () {
69 this.videoName = undefined
70 this.secondStepType = undefined
71 }
72
73 @HostListener('window:beforeunload', [ '$event' ])
74 onUnload (event: any) {
75 const { text, canDeactivate } = this.canDeactivate()
76
77 if (canDeactivate) return
78
79 event.returnValue = text
80 return text
81 }
82
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()
87
88 return { canDeactivate: true }
89 }
90
91 isVideoImportHttpEnabled () {
92 return this.serverConfig.import.videos.http.enabled
93 }
94
95 isVideoImportTorrentEnabled () {
96 return this.serverConfig.import.videos.torrent.enabled
97 }
98
99 isVideoLiveEnabled () {
100 return this.serverConfig.live.enabled
101 }
102
103 isInSecondStep () {
104 return !!this.secondStepType
105 }
106
107 isRootUser () {
108 return this.user.username === 'root'
109 }
110 }