]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-edit/video-add.component.ts
improve likes-dislikes bar usability
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-edit / video-add.component.ts
1 import { Component, HostListener, ViewChild } from '@angular/core'
2 import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
3 import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component'
4 import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component'
5 import { AuthService, ServerService } from '@app/core'
6 import { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.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 CanComponentDeactivate {
14 @ViewChild('videoUpload', { static: false }) videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl', { static: false }) videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent', { static: false }) videoImportTorrent: VideoImportTorrentComponent
17
18 secondStepType: 'upload' | 'import-url' | 'import-torrent'
19 videoName: string
20
21 constructor (
22 private auth: AuthService,
23 private serverService: ServerService
24 ) {}
25
26 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
27 this.secondStepType = type
28 this.videoName = videoName
29 }
30
31 onError () {
32 this.videoName = undefined
33 this.secondStepType = undefined
34 }
35
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} {
47 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
48 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
49 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
50
51 return { canDeactivate: true }
52 }
53
54 isVideoImportHttpEnabled () {
55 return this.serverService.getConfig().import.videos.http.enabled
56 }
57
58 isVideoImportTorrentEnabled () {
59 return this.serverService.getConfig().import.videos.torrent.enabled
60 }
61
62 isInSecondStep () {
63 return !!this.secondStepType
64 }
65
66 isRootUser () {
67 return this.auth.getUser().username === 'root'
68 }
69 }