]>
Commit | Line | Data |
---|---|---|
ba430d75 | 1 | import { Component, HostListener, OnInit, ViewChild } from '@angular/core' |
dfe3f7b7 | 2 | import { AuthService, AuthUser, CanComponentDeactivate, ServerService } from '@app/core' |
ba430d75 | 3 | import { ServerConfig } from '@shared/models' |
67ed6552 C |
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' | |
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 | }) |
ba430d75 | 13 | export class VideoAddComponent implements OnInit, CanComponentDeactivate { |
2f5d2ec5 C |
14 | @ViewChild('videoUpload') videoUpload: VideoUploadComponent |
15 | @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent | |
16 | @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent | |
bfb3a98f | 17 | |
dfe3f7b7 | 18 | user: AuthUser = null |
2e7f2627 | 19 | |
ce33919c | 20 | secondStepType: 'upload' | 'import-url' | 'import-torrent' |
fbad87b0 | 21 | videoName: string |
ba430d75 | 22 | serverConfig: ServerConfig |
bbe0f064 | 23 | |
5d08a6a7 | 24 | constructor ( |
cd3d847d | 25 | private auth: AuthService, |
5d08a6a7 C |
26 | private serverService: ServerService |
27 | ) {} | |
28 | ||
2e7f2627 K |
29 | get userInformationLoaded () { |
30 | return this.auth.userInformationLoaded | |
31 | } | |
32 | ||
ba430d75 | 33 | ngOnInit () { |
2e7f2627 K |
34 | this.user = this.auth.getUser() |
35 | ||
ba430d75 C |
36 | this.serverConfig = this.serverService.getTmpConfig() |
37 | ||
38 | this.serverService.getConfig() | |
39 | .subscribe(config => this.serverConfig = config) | |
dfe3f7b7 K |
40 | |
41 | this.user = this.auth.getUser() | |
ba430d75 C |
42 | } |
43 | ||
ce33919c | 44 | onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) { |
fbad87b0 C |
45 | this.secondStepType = type |
46 | this.videoName = videoName | |
f6a043df C |
47 | } |
48 | ||
7373507f C |
49 | onError () { |
50 | this.videoName = undefined | |
51 | this.secondStepType = undefined | |
52 | } | |
53 | ||
674a66bb C |
54 | @HostListener('window:beforeunload', [ '$event' ]) |
55 | onUnload (event: any) { | |
56 | const { text, canDeactivate } = this.canDeactivate() | |
57 | ||
58 | if (canDeactivate) return | |
59 | ||
60 | event.returnValue = text | |
61 | return text | |
62 | } | |
63 | ||
64 | canDeactivate (): { canDeactivate: boolean, text?: string} { | |
fbad87b0 | 65 | if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate() |
047559af | 66 | if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() |
ce33919c | 67 | if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() |
40e87e9e | 68 | |
fbad87b0 | 69 | return { canDeactivate: true } |
27e1a06c | 70 | } |
5d08a6a7 | 71 | |
ce33919c | 72 | isVideoImportHttpEnabled () { |
ba430d75 | 73 | return this.serverConfig.import.videos.http.enabled |
ce33919c C |
74 | } |
75 | ||
76 | isVideoImportTorrentEnabled () { | |
ba430d75 | 77 | return this.serverConfig.import.videos.torrent.enabled |
5d08a6a7 | 78 | } |
cd3d847d C |
79 | |
80 | isInSecondStep () { | |
81 | return !!this.secondStepType | |
82 | } | |
83 | ||
84 | isRootUser () { | |
dfe3f7b7 | 85 | return this.user.username === 'root' |
cd3d847d | 86 | } |
dc8bc31b | 87 | } |