]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add.component.ts
Move to sass @use
[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 { HTMLServerConfig } 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: HTMLServerConfig
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.getHTMLConfig()
46
47 this.user = this.auth.getUser()
48
49 if (this.route.snapshot.fragment) {
50 this.onNavChange(this.route.snapshot.fragment)
51 }
52 }
53
54 onNavChange (newActiveNav: string) {
55 this.activeNav = newActiveNav
56
57 this.router.navigate([], { fragment: this.activeNav })
58 }
59
60 onFirstStepDone (type: VideoEditType, videoName: string) {
61 this.secondStepType = type
62 this.videoName = videoName
63 }
64
65 onError () {
66 this.videoName = undefined
67 this.secondStepType = undefined
68 }
69
70 @HostListener('window:beforeunload', [ '$event' ])
71 onUnload (event: any) {
72 const { text, canDeactivate } = this.canDeactivate()
73
74 if (canDeactivate) return
75
76 event.returnValue = text
77 return text
78 }
79
80 canDeactivate (): { canDeactivate: boolean, text?: string} {
81 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
82 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
83 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
84
85 return { canDeactivate: true }
86 }
87
88 isVideoImportHttpEnabled () {
89 return this.serverConfig.import.videos.http.enabled
90 }
91
92 isVideoImportTorrentEnabled () {
93 return this.serverConfig.import.videos.torrent.enabled
94 }
95
96 isVideoLiveEnabled () {
97 return this.serverConfig.live.enabled
98 }
99
100 isInSecondStep () {
101 return !!this.secondStepType
102 }
103
104 isRootUser () {
105 return this.user.username === 'root'
106 }
107 }