Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarded route support to ConfirmDialog #2194

Closed
ova2 opened this issue Mar 1, 2017 · 8 comments
Closed

Guarded route support to ConfirmDialog #2194

ova2 opened this issue Mar 1, 2017 · 8 comments
Assignees
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team

Comments

@ova2
Copy link

ova2 commented Mar 1, 2017

If you use ConfirmDialog with CanDeactivate guard, you normally have to return Promise or Observable in the canDeactivate method. Here is the method signature: https://angular.io/docs/ts/latest/api/router/index/CanDeactivate-interface.html This works very well as long the user clicks on accept or reject buttons. But when the user clicks on the dialog's close button (or hit escape key), the dialog gets closed and can not be opened after that. It stops to work.

Demo is created: https://github.com/ova2/frontend-tooling-tutorial/tree/master/angular-playground/router-primeng-confirmdialog

I think in the confirmdialog.ts, you should not invoke (click)="hide($event)" on close. You should invoke (click)="reject($event)". If you invoke reject which invokes hide on its parts, the dialog is ok. Also on hitting escape key, the this.reject(event) should be called instead of this.hide(event).

Should I provide a pull request?

Thanks.

@ova2
Copy link
Author

ova2 commented Mar 2, 2017

I have found some other weak points in the ConfirmDialog.

  • Confirmation object doesn't need to expose acceptEvent and rejectEvent because they are not used public. You can keep these references in the Component ConfirmDialog itself.
  • Subscription like this.confirmation.acceptEvent.subscribe(...) should be unsubscribed when accept() resp. reject are called. There is unsubscribe() on the return object of subscribe(). See http://stackoverflow.com/questions/36494509/how-to-unsubscribe-from-eventemitter-in-angular-2 If you keep the references in the Component, you can call unsubscribe() in the destroy method.
  • Don't use EventEmitter except for properties decorated with @Output. It's not recommended. Use Observable or Subject. You can read that in some docs. See the stackoverflow post I have mentioned above. Background: Angular will never guarantee us that EventEmitter will continue being an Observable.

@cagataycivici
Copy link
Member

Send a PR please Oleg.

@cagataycivici cagataycivici changed the title ConfirmDialog stops working on close with with guarded routes Guarded route support to ConfirmDialog Jun 20, 2017
@cagataycivici cagataycivici added the Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add label Jun 20, 2017
ova2 added a commit to ova2/primeng that referenced this issue Jun 25, 2017
@ova2
Copy link
Author

ova2 commented Jun 25, 2017

@cagataycivici I have created a PR for weak points: #3201 It looks cleaner now. The issue on close was already fixed earlier.

Thanks. Oleg.

@cagataycivici cagataycivici added this to the 4.1.0 milestone Jun 27, 2017
@cagataycivici cagataycivici self-assigned this Jun 27, 2017
@cagataycivici
Copy link
Member

#921 should fix the original issue right?

But when the user clicks on the dialog's close button (or hit escape key), the dialog gets closed and can not be opened after that. It stops to work.

@cagataycivici cagataycivici removed this from the 4.1.0-RC3 milestone Jun 29, 2017
@cagataycivici cagataycivici added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add labels Jun 29, 2017
@ova2
Copy link
Author

ova2 commented Jun 29, 2017

Yes, the original issue is fixed by #921. This PR fixes weak points I mentioned in "I have found some other weak points in the ConfirmDialog."

@ova2
Copy link
Author

ova2 commented Jun 29, 2017

It's disappointing that PR has conflicts now. Why do we need this.executePostShowActions? Can we not always set focus on first button in the confirm dialog?

@cagataycivici
Copy link
Member

Sorry, this.executePostShowActions is to focus button after show. I can merge manually later, no problem.

@ova2
Copy link
Author

ova2 commented Jun 29, 2017

I've solved conflicts. No problem. You can merge the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Pending Review Issue or pull request is being reviewed by Core Team
Projects
None yet
Development

No branches or pull requests

2 participants