1
0
Fork 0
peertube/client/src/app/+videos/+video-edit/video-add.component.ts

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2019-12-18 14:31:54 +00:00
import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
import { AuthService, CanComponentDeactivate, ServerService, User } from '@app/core'
2019-12-18 14:31:54 +00:00
import { ServerConfig } from '@shared/models'
2020-06-23 12:10:17 +00:00
import { VideoImportTorrentComponent } from './video-add-components/video-import-torrent.component'
import { VideoImportUrlComponent } from './video-add-components/video-import-url.component'
import { VideoUploadComponent } from './video-add-components/video-upload.component'
2016-03-14 12:50:19 +00:00
@Component({
selector: 'my-videos-add',
2017-12-07 15:32:06 +00:00
templateUrl: './video-add.component.html',
styleUrls: [ './video-add.component.scss' ]
2016-03-14 12:50:19 +00:00
})
2019-12-18 14:31:54 +00:00
export class VideoAddComponent implements OnInit, CanComponentDeactivate {
2020-02-07 09:00:34 +00:00
@ViewChild('videoUpload') videoUpload: VideoUploadComponent
@ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent
@ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent
user: User = null
2018-08-06 15:13:39 +00:00
secondStepType: 'upload' | 'import-url' | 'import-torrent'
videoName: string
2019-12-18 14:31:54 +00:00
serverConfig: ServerConfig
2018-08-03 09:10:31 +00:00
constructor (
private auth: AuthService,
2018-08-03 09:10:31 +00:00
private serverService: ServerService
) {}
get userInformationLoaded () {
return this.auth.userInformationLoaded
}
2019-12-18 14:31:54 +00:00
ngOnInit () {
this.user = this.auth.getUser()
2019-12-18 14:31:54 +00:00
this.serverConfig = this.serverService.getTmpConfig()
this.serverService.getConfig()
.subscribe(config => this.serverConfig = config)
}
2018-08-06 15:13:39 +00:00
onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) {
this.secondStepType = type
this.videoName = videoName
}
2018-11-16 09:05:25 +00:00
onError () {
this.videoName = undefined
this.secondStepType = undefined
}
@HostListener('window:beforeunload', [ '$event' ])
onUnload (event: any) {
const { text, canDeactivate } = this.canDeactivate()
if (canDeactivate) return
event.returnValue = text
return text
}
canDeactivate (): { canDeactivate: boolean, text?: string} {
if (this.secondStepType === 'upload') return this.videoUpload.canDeactivate()
2018-08-06 13:18:35 +00:00
if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate()
2018-08-06 15:13:39 +00:00
if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate()
2018-07-12 17:02:00 +00:00
return { canDeactivate: true }
2017-12-07 15:32:06 +00:00
}
2018-08-03 09:10:31 +00:00
2018-08-06 15:13:39 +00:00
isVideoImportHttpEnabled () {
2019-12-18 14:31:54 +00:00
return this.serverConfig.import.videos.http.enabled
2018-08-06 15:13:39 +00:00
}
isVideoImportTorrentEnabled () {
2019-12-18 14:31:54 +00:00
return this.serverConfig.import.videos.torrent.enabled
2018-08-03 09:10:31 +00:00
}
isInSecondStep () {
return !!this.secondStepType
}
isRootUser () {
return this.auth.getUser().username === 'root'
}
2016-03-14 12:50:19 +00:00
}