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