import { Injectable } from '@angular/core'
import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
import { Observable } from 'rxjs/Observable'
-import { ConfirmService } from '../core'
+import { ConfirmService } from '../../core/index'
export interface CanComponentDeactivate {
- canDeactivate: () => Observable<boolean> | boolean
+ canDeactivate: () => { text?: string, canDeactivate: Observable<boolean> | boolean }
}
@Injectable()
currentState: RouterStateSnapshot,
nextState: RouterStateSnapshot
): Observable<boolean> | boolean {
- return component.canDeactivate() || this.confirmService.confirm(
- 'All unsaved data will be lost, are you sure you want to leave ?',
- 'Unsaved Data'
+ const result = component.canDeactivate()
+ const text = result.text || 'All unsaved data will be lost, are you sure you want to leave this page?'
+
+ return result.canDeactivate || this.confirmService.confirm(
+ text,
+ 'Warning'
)
}
import { MetaGuard } from '@ngx-meta/core'
import { LoginGuard } from '../../core'
-import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service'
+import { CanDeactivateGuard } from '../../shared/guards/can-deactivate-guard.service'
import { VideoAddComponent } from './video-add.component'
const videoAddRoutes: Routes = [
path: '',
component: VideoAddComponent,
canActivate: [ MetaGuard, LoginGuard ],
- canDeactivate: [CanDeactivateGuard]
+ canDeactivate: [ CanDeactivateGuard ]
}
]
import { HttpEventType, HttpResponse } from '@angular/common/http'
-import { Component, OnInit, ViewChild } from '@angular/core'
+import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
import { FormBuilder, FormGroup } from '@angular/forms'
import { Router } from '@angular/router'
import { UserService } from '@app/shared'
+import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
import { NotificationsService } from 'angular2-notifications'
import { BytesPipe } from 'ngx-pipes'
+import { Subscription } from 'rxjs/Subscription'
import { VideoPrivacy } from '../../../../../shared/models/videos'
import { AuthService, ServerService } from '../../core'
import { FormReactive } from '../../shared'
import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
import { VideoEdit } from '../../shared/video/video-edit.model'
import { VideoService } from '../../shared/video/video.service'
-import { CanComponentDeactivate } from '@app/shared/can-deactivate-guard.service'
@Component({
selector: 'my-videos-add',
]
})
-export class VideoAddComponent extends FormReactive implements OnInit, CanComponentDeactivate {
+export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy, CanComponentDeactivate {
@ViewChild('videofileInput') videofileInput
isUploadingVideo = false
videoUploaded = false
- videoUploadObservable = null
+ videoUploadObservable: Subscription = null
videoUploadPercents = 0
videoUploadedIds = {
id: 0,
})
}
+ ngOnDestroy () {
+ if (this.videoUploadObservable) {
+ this.videoUploadObservable.unsubscribe()
+ }
+ }
+
canDeactivate () {
- return !this.isUploadingVideo
+ let text = ''
+
+ if (this.videoUploaded === true) {
+ text = 'Your video was uploaded in your account and is private.' +
+ ' But associated data (tags, description...) will be lost, are you sure you want to leave this page?'
+ } else {
+ text = 'Your video is not uploaded yet, are you sure you want to leave this page?'
+ }
+
+ return {
+ canDeactivate: !this.isUploadingVideo,
+ text
+ }
}
fileChange () {