user-profile-delete-dialog.component.ts 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2. import { ActivatedRoute, Router } from '@angular/router';
  3. import { NgbActiveModal, NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
  4. import { JhiEventManager } from 'ng-jhipster';
  5. import { IUserProfile } from 'app/shared/model/user-profile.model';
  6. import { UserProfileService } from './user-profile.service';
  7. @Component({
  8. selector: 'jhi-user-profile-delete-dialog',
  9. templateUrl: './user-profile-delete-dialog.component.html'
  10. })
  11. export class UserProfileDeleteDialogComponent {
  12. userProfile: IUserProfile;
  13. constructor(
  14. private userProfileService: UserProfileService,
  15. public activeModal: NgbActiveModal,
  16. private eventManager: JhiEventManager
  17. ) {}
  18. clear() {
  19. this.activeModal.dismiss('cancel');
  20. }
  21. confirmDelete(id: number) {
  22. this.userProfileService.delete(id).subscribe(response => {
  23. this.eventManager.broadcast({
  24. name: 'userProfileListModification',
  25. content: 'Deleted an userProfile'
  26. });
  27. this.activeModal.dismiss(true);
  28. });
  29. }
  30. }
  31. @Component({
  32. selector: 'jhi-user-profile-delete-popup',
  33. template: ''
  34. })
  35. export class UserProfileDeletePopupComponent implements OnInit, OnDestroy {
  36. private ngbModalRef: NgbModalRef;
  37. constructor(private activatedRoute: ActivatedRoute, private router: Router, private modalService: NgbModal) {}
  38. ngOnInit() {
  39. this.activatedRoute.data.subscribe(({ userProfile }) => {
  40. setTimeout(() => {
  41. this.ngbModalRef = this.modalService.open(UserProfileDeleteDialogComponent as Component, {
  42. size: 'lg',
  43. backdrop: 'static'
  44. });
  45. this.ngbModalRef.componentInstance.userProfile = userProfile;
  46. this.ngbModalRef.result.then(
  47. result => {
  48. this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
  49. this.ngbModalRef = null;
  50. },
  51. reason => {
  52. this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
  53. this.ngbModalRef = null;
  54. }
  55. );
  56. }, 0);
  57. });
  58. }
  59. ngOnDestroy() {
  60. this.ngbModalRef = null;
  61. }
  62. }