]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/+video-edit/video-add.component.ts
Display user quota progress bars above upload form (#2981)
[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 { AuthService, CanComponentDeactivate, ServerService, User } from '@app/core'
3 import { ServerConfig } from '@shared/models'
4 import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
5 import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
6 import { VideoUploadComponent } from './video-add-components/video-upload.component'
7
8 @Component({
9 selector: 'my-videos-add',
10 templateUrl: './video-add.component.html',
11 styleUrls: [ './video-add.component.scss' ]
12 })
13 export class VideoAddComponent implements OnInit, CanComponentDeactivate {
14 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
17
18 user: User = null
19
20 secondStepType: 'upload' | 'import-url' | 'import-torrent'
21 videoName: string
22 serverConfig: ServerConfig
23
24 constructor (
25 private auth: AuthService,
26 private serverService: ServerService
27 ) {}
28
29 get userInformationLoaded () {
30 return this.auth.userInformationLoaded
31 }
32
33 ngOnInit () {
34 this.user = this.auth.getUser()
35
36 this.serverConfig = this.serverService.getTmpConfig()
37
38 this.serverService.getConfig()
39 .subscribe(config => this.serverConfig = config)
40 }
41
42 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
43 this.secondStepType = type
44 this.videoName = videoName
45 }
46
47 onError () {
48 this.videoName = undefined
49 this.secondStepType = undefined
50 }
51
52 @HostListener('window:beforeunload', [ '$event' ])
53 onUnload (event: any) {
54 const { text, canDeactivate } = this.canDeactivate()
55
56 if (canDeactivate) return
57
58 event.returnValue = text
59 return text
60 }
61
62 canDeactivate (): { canDeactivate: boolean, text?: string} {
63 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
64 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
65 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
66
67 return { canDeactivate: true }
68 }
69
70 isVideoImportHttpEnabled () {
71 return this.serverConfig.import.videos.http.enabled
72 }
73
74 isVideoImportTorrentEnabled () {
75 return this.serverConfig.import.videos.torrent.enabled
76 }
77
78 isInSecondStep () {
79 return !!this.secondStepType
80 }
81
82 isRootUser () {
83 return this.auth.getUser().username === 'root'
84 }
85 }