-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from Apes2getherStrong/wtg-51-alert-when-leav…
…ing-edit-without-saving Wtg 51 alert when leaving edit without saving
- Loading branch information
Showing
6 changed files
with
131 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/app/shared/guards/can-deactivate-form-guard.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {Injectable} from "@angular/core"; | ||
import {ConfirmationDialogService} from "../confirmation-dialog/confirmation-dialog.service"; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class CanDeactivateFormGuardService { | ||
|
||
constructor(private confirmationDialogService: ConfirmationDialogService) {} | ||
|
||
canDeactivateForm(isDirty: boolean):Promise<boolean> { | ||
if (isDirty) { | ||
return new Promise((resolve) => { | ||
this.confirmationDialogService | ||
.confirm( | ||
'Confirm Exiting', | ||
`You are about to exit without saving the changes. Do you want to proceed?`, | ||
'Yes', | ||
'Cancel' | ||
) | ||
.subscribe((confirmed: boolean) => { | ||
resolve(confirmed); | ||
}); | ||
}); | ||
} else { | ||
return Promise.resolve(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {Observable} from "rxjs"; | ||
import {Injectable} from "@angular/core"; | ||
import {CanDeactivate} from "@angular/router"; | ||
|
||
export interface CanComponentDeactivate { | ||
canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class CanDeactivateGuard implements CanDeactivate<CanComponentDeactivate> { | ||
canDeactivate (component: CanComponentDeactivate) : Observable<boolean> | Promise<boolean> | boolean { | ||
return component.canDeactivate(); | ||
} | ||
} |