]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/+video-edit/video-add.component.ts
Speedup embed first paint
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add.component.ts
CommitLineData
674a66bb 1import { Component, HostListener, ViewChild } from '@angular/core'
f6a043df 2import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
78848714
C
3import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
4import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
cd3d847d 5import { AuthService, ServerService } from '@app/core'
ce33919c 6import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component'
1553e15d 7
dc8bc31b
C
8@Component({
9 selector: 'my-videos-add',
27e1a06c 10 templateUrl: './video-add.component.html',
fbad87b0 11 styleUrls: [ './video-add.component.scss' ]
dc8bc31b 12})
fbad87b0 13export class VideoAddComponent implements CanComponentDeactivate {
f36da21e
C
14 @ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
bfb3a98f 17
ce33919c 18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
fbad87b0 19 videoName: string
bbe0f064 20
5d08a6a7 21 constructor (
cd3d847d 22 private auth: AuthService,
5d08a6a7
C
23 private serverService: ServerService
24 ) {}
25
ce33919c 26 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
fbad87b0
C
27 this.secondStepType = type
28 this.videoName = videoName
f6a043df
C
29 }
30
7373507f
C
31 onError () {
32 this.videoName = undefined
33 this.secondStepType = undefined
34 }
35
674a66bb
C
36 @HostListener('window:beforeunload', [ '$event' ])
37 onUnload (event: any) {
38 const { text, canDeactivate } = this.canDeactivate()
39
40 if (canDeactivate) return
41
42 event.returnValue = text
43 return text
44 }
45
46 canDeactivate (): { canDeactivate: boolean, text?: string} {
fbad87b0 47 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
047559af 48 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
ce33919c 49 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
40e87e9e 50
fbad87b0 51 return { canDeactivate: true }
27e1a06c 52 }
5d08a6a7 53
ce33919c
C
54 isVideoImportHttpEnabled () {
55 return this.serverService.getConfig().import.videos.http.enabled
56 }
57
58 isVideoImportTorrentEnabled () {
a84b8fa5 59 return this.serverService.getConfig().import.videos.torrent.enabled
5d08a6a7 60 }
cd3d847d
C
61
62 isInSecondStep () {
63 return !!this.secondStepType
64 }
65
66 isRootUser () {
67 return this.auth.getUser().username === 'root'
68 }
dc8bc31b 69}