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