* issue #195 * fixing missing provider definition * fix styling issue * fix styling issue * removed unecessary code * using angular confirmService instead of window.confirm * gitignore unecessary folders * style fixes * using a generic canDeactivateGuard * fixing lint style
This commit is contained in:
parent
c360c49456
commit
529479f924
|
@ -0,0 +1,25 @@
|
|||
import { Injectable } from '@angular/core'
|
||||
import { CanDeactivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'
|
||||
import { Observable } from 'rxjs/Observable'
|
||||
import { ConfirmService } from '../core'
|
||||
|
||||
export interface CanComponentDeactivate {
|
||||
canDeactivate: () => Observable<boolean> | boolean
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> {
|
||||
constructor (private confirmService: ConfirmService) { }
|
||||
|
||||
canDeactivate (component: CanComponentDeactivate,
|
||||
currentRoute: ActivatedRouteSnapshot,
|
||||
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'
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -4,13 +4,15 @@ import { RouterModule, Routes } from '@angular/router'
|
|||
import { MetaGuard } from '@ngx-meta/core'
|
||||
|
||||
import { LoginGuard } from '../../core'
|
||||
import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service'
|
||||
import { VideoAddComponent } from './video-add.component'
|
||||
|
||||
const videoAddRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: VideoAddComponent,
|
||||
canActivate: [ MetaGuard, LoginGuard ]
|
||||
canActivate: [ MetaGuard, LoginGuard ],
|
||||
canDeactivate: [CanDeactivateGuard]
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ValidatorMessage } from '../../shared/forms/form-validators/validator-m
|
|||
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',
|
||||
|
@ -22,7 +23,7 @@ import { VideoService } from '../../shared/video/video.service'
|
|||
]
|
||||
})
|
||||
|
||||
export class VideoAddComponent extends FormReactive implements OnInit {
|
||||
export class VideoAddComponent extends FormReactive implements OnInit, CanComponentDeactivate {
|
||||
@ViewChild('videofileInput') videofileInput
|
||||
|
||||
isUploadingVideo = false
|
||||
|
@ -84,6 +85,10 @@ export class VideoAddComponent extends FormReactive implements OnInit {
|
|||
})
|
||||
}
|
||||
|
||||
canDeactivate () {
|
||||
return !this.isUploadingVideo
|
||||
}
|
||||
|
||||
fileChange () {
|
||||
this.uploadFirstStep()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import { SharedModule } from '../../shared'
|
|||
import { VideoEditModule } from './shared/video-edit.module'
|
||||
import { VideoAddRoutingModule } from './video-add-routing.module'
|
||||
import { VideoAddComponent } from './video-add.component'
|
||||
import { CanDeactivateGuard } from '../../shared/can-deactivate-guard.service'
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
|
@ -12,15 +13,14 @@ import { VideoAddComponent } from './video-add.component'
|
|||
SharedModule,
|
||||
ProgressBarModule
|
||||
],
|
||||
|
||||
declarations: [
|
||||
VideoAddComponent
|
||||
],
|
||||
|
||||
exports: [
|
||||
VideoAddComponent
|
||||
],
|
||||
|
||||
providers: [ ]
|
||||
providers: [
|
||||
CanDeactivateGuard
|
||||
]
|
||||
})
|
||||
export class VideoAddModule { }
|
||||
|
|
Loading…
Reference in New Issue