]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Merge branch 'release/3.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
CommitLineData
ba430d75 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
3914a50b 2import { ActivatedRoute, Router } from '@angular/router'
dfe3f7b7 3import { AuthService, AuthUser, CanComponentDeactivate, ServerService } from '@app/core'
ba430d75 4import { ServerConfig } from '@shared/models'
c6c0fa6c
C
5import { VideoEditType } from './shared/video-edit.type'
6import { VideoGoLiveComponent } from './video-add-components/video-go-live.component'
67ed6552
C
7import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
8import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
9import { VideoUploadComponent } from './video-add-components/video-upload.component'
1553e15d 10
dc8bc31b
C
11@Component({
12 selector: 'my-videos-add',
27e1a06c 13 templateUrl: './video-add.component.html',
fbad87b0 14 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 15})
ba430d75 16export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2f5d2ec5
C
17 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
18 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
19 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
c6c0fa6c 20 @ViewChild('videoGoLive') videoGoLive: VideoGoLiveComponent
bfb3a98f 21
dfe3f7b7 22 user: AuthUser = null
2e7f2627 23
c6c0fa6c 24 secondStepType: VideoEditType
fbad87b0 25 videoName: string
3914a50b
C
26
27 activeNav: string
28
29 private serverConfig: ServerConfig
bbe0f064 30
5d08a6a7 31 constructor (
cd3d847d 32 private auth: AuthService,
3914a50b
C
33 private serverService: ServerService,
34 private route: ActivatedRoute,
35 private router: Router
5d08a6a7
C
36 ) {}
37
2e7f2627
K
38 get userInformationLoaded () {
39 return this.auth.userInformationLoaded
40 }
41
ba430d75 42 ngOnInit () {
2e7f2627
K
43 this.user = this.auth.getUser()
44
ba430d75
C
45 this.serverConfig = this.serverService.getTmpConfig()
46
47 this.serverService.getConfig()
48 .subscribe(config => this.serverConfig = config)
dfe3f7b7
K
49
50 this.user = this.auth.getUser()
3914a50b
C
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 })
ba430d75
C
61 }
62
c6c0fa6c 63 onFirstStepDone (type: VideoEditType, videoName: string) {
fbad87b0
C
64 this.secondStepType = type
65 this.videoName = videoName
f6a043df
C
66 }
67
7373507f
C
68 onError () {
69 this.videoName = undefined
70 this.secondStepType = undefined
71 }
72
674a66bb
C
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} {
047559af 84 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 85 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
c6c0fa6c 86 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
40e87e9e 87
fbad87b0 88 return { canDeactivate: true }
27e1a06c 89 }
5d08a6a7 90
ce33919c 91 isVideoImportHttpEnabled () {
ba430d75 92 return this.serverConfig.import.videos.http.enabled
ce33919c
C
93 }
94
95 isVideoImportTorrentEnabled () {
ba430d75 96 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 97 }
cd3d847d 98
c6c0fa6c
C
99 isVideoLiveEnabled () {
100 return this.serverConfig.live.enabled
101 }
102
cd3d847d
C
103 isInSecondStep () {
104 return !!this.secondStepType
105 }
106
107 isRootUser () {
dfe3f7b7 108 return this.user.username === 'root'
cd3d847d 109 }
dc8bc31b 110}