]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/+videos/+video-edit/video-add.component.ts
Restore line feed for markdown lists support in comments
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-edit / video-add.component.ts
... / ...
CommitLineData
1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2import { AuthService, AuthUser, CanComponentDeactivate, ServerService } from '@app/core'
3import { ServerConfig } from '@shared/models'
4import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
5import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
6import { 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})
13export class VideoAddComponent implements OnInit, CanComponentDeactivate {
14 @ViewChild('videoUpload') videoUpload: VideoUploadComponent
15 @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
16 @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
17
18 user: AuthUser = 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 this.user = this.auth.getUser()
42 }
43
44 onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
45 this.secondStepType = type
46 this.videoName = videoName
47 }
48
49 onError () {
50 this.videoName = undefined
51 this.secondStepType = undefined
52 }
53
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} {
65 if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
66 if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
67 if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
68
69 return { canDeactivate: true }
70 }
71
72 isVideoImportHttpEnabled () {
73 return this.serverConfig.import.videos.http.enabled
74 }
75
76 isVideoImportTorrentEnabled () {
77 return this.serverConfig.import.videos.torrent.enabled
78 }
79
80 isInSecondStep () {
81 return !!this.secondStepType
82 }
83
84 isRootUser () {
85 return this.user.username === 'root'
86 }
87}