X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-edit%2Fvideo-add.component.ts;h=5bd7688092020553001626b29f52321d9d606749;hb=67ed6552b831df66713bac9e672738796128d33f;hp=e74fa1f15c14a2b2ccf2c384c00060d315190957;hpb=788487140c500abeb69ca44daf3a9e26efa8d36f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts index e74fa1f15..5bd768809 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts @@ -1,38 +1,77 @@ -import { Component, ViewChild } from '@angular/core' -import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' -import { VideoImportUrlComponent } from '@app/videos/+video-edit/video-add-components/video-import-url.component' -import { VideoUploadComponent } from '@app/videos/+video-edit/video-add-components/video-upload.component' -import { ServerService } from '@app/core' +import { Component, HostListener, OnInit, ViewChild } from '@angular/core' +import { AuthService, CanComponentDeactivate, ServerService } from '@app/core' +import { ServerConfig } from '@shared/models' +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' @Component({ selector: 'my-videos-add', templateUrl: './video-add.component.html', styleUrls: [ './video-add.component.scss' ] }) -export class VideoAddComponent implements CanComponentDeactivate { +export class VideoAddComponent implements OnInit, CanComponentDeactivate { @ViewChild('videoUpload') videoUpload: VideoUploadComponent @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent + @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent - secondStepType: 'upload' | 'import-url' + secondStepType: 'upload' | 'import-url' | 'import-torrent' videoName: string + serverConfig: ServerConfig constructor ( + private auth: AuthService, private serverService: ServerService ) {} - onFirstStepDone (type: 'upload' | 'import-url', videoName: string) { + ngOnInit () { + this.serverConfig = this.serverService.getTmpConfig() + + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + } + + onFirstStepDone (type: 'upload' | 'import-url' | 'import-torrent', videoName: string) { this.secondStepType = type this.videoName = videoName } - canDeactivate () { + 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() if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() + if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() return { canDeactivate: true } } - isVideoImportEnabled () { - return this.serverService.getConfig().import.videos.http.enabled + isVideoImportHttpEnabled () { + return this.serverConfig.import.videos.http.enabled + } + + isVideoImportTorrentEnabled () { + return this.serverConfig.import.videos.torrent.enabled + } + + isInSecondStep () { + return !!this.secondStepType + } + + isRootUser () { + return this.auth.getUser().username === 'root' } }