]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-edit/video-add.component.ts
Bidi support
[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'
2989628b 4import { HTMLServerConfig } 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
2989628b 29 private serverConfig: HTMLServerConfig
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
2989628b 45 this.serverConfig = this.serverService.getHTMLConfig()
dfe3f7b7
K
46
47 this.user = this.auth.getUser()
3914a50b
C
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 })
ba430d75
C
58 }
59
c6c0fa6c 60 onFirstStepDone (type: VideoEditType, videoName: string) {
fbad87b0
C
61 this.secondStepType = type
62 this.videoName = videoName
f6a043df
C
63 }
64
7373507f
C
65 onError () {
66 this.videoName = undefined
67 this.secondStepType = undefined
68 }
69
674a66bb
C
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} {
047559af 81 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 82 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
c6c0fa6c 83 if (this.secondStepType === 'go-live') return this.videoGoLive.canDeactivate()
40e87e9e 84
fbad87b0 85 return { canDeactivate: true }
27e1a06c 86 }
5d08a6a7 87
ce33919c 88 isVideoImportHttpEnabled () {
ba430d75 89 return this.serverConfig.import.videos.http.enabled
ce33919c
C
90 }
91
92 isVideoImportTorrentEnabled () {
ba430d75 93 return this.serverConfig.import.videos.torrent.enabled
5d08a6a7 94 }
cd3d847d 95
c6c0fa6c
C
96 isVideoLiveEnabled () {
97 return this.serverConfig.live.enabled
98 }
99
cd3d847d
C
100 isInSecondStep () {
101 return !!this.secondStepType
102 }
103
104 isRootUser () {
dfe3f7b7 105 return this.user.username === 'root'
cd3d847d 106 }
dc8bc31b 107}