X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fvideos%2F%2Bvideo-edit%2Fvideo-add.component.ts;h=01fdfcb66742e3a9eb89b85a9fb0f8d0636f676e;hb=674a66bbda7ceb7aed3c2e6aefddc2793207d94b;hp=69b364ddd01943683fbd94487d7c01f12463b8ee;hpb=3d52b300ea79bec21f090e2447c4808307078618;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 69b364ddd..01fdfcb66 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts @@ -1,8 +1,9 @@ -import { Component, ViewChild } from '@angular/core' +import { Component, HostListener, ViewChild } from '@angular/core' import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' -import { VideoImportComponent } from '@app/videos/+video-edit/video-import.component' -import { VideoUploadComponent } from '@app/videos/+video-edit/video-upload.component' +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 { VideoImportTorrentComponent } from '@app/videos/+video-edit/video-add-components/video-import-torrent.component' @Component({ selector: 'my-videos-add', @@ -11,28 +12,49 @@ import { ServerService } from '@app/core' }) export class VideoAddComponent implements CanComponentDeactivate { @ViewChild('videoUpload') videoUpload: VideoUploadComponent - @ViewChild('videoImport') videoImport: VideoImportComponent + @ViewChild('videoImportUrl') videoImportUrl: VideoImportUrlComponent + @ViewChild('videoImportTorrent') videoImportTorrent: VideoImportTorrentComponent - secondStepType: 'upload' | 'import' + secondStepType: 'upload' | 'import-url' | 'import-torrent' videoName: string constructor ( private serverService: ServerService ) {} - onFirstStepDone (type: 'upload' | 'import', videoName: string) { + 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') return this.videoImport.canDeactivate() + if (this.secondStepType === 'import-url') return this.videoImportUrl.canDeactivate() + if (this.secondStepType === 'import-torrent') return this.videoImportTorrent.canDeactivate() return { canDeactivate: true } } - isVideoImportEnabled () { + isVideoImportHttpEnabled () { return this.serverService.getConfig().import.videos.http.enabled } + + isVideoImportTorrentEnabled () { + return this.serverService.getConfig().import.videos.torrent.enabled + } }