post-delete-dialog.component.ts 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { IPost } from 'app/shared/model/post.model';
  6. import { PostService } from './post.service';
  7. @Component({
  8. selector: 'jhi-post-delete-dialog',
  9. templateUrl: './post-delete-dialog.component.html'
  10. })
  11. export class PostDeleteDialogComponent {
  12. post: IPost;
  13. constructor(private postService: PostService, public activeModal: NgbActiveModal, private eventManager: JhiEventManager) {}
  14. clear() {
  15. this.activeModal.dismiss('cancel');
  16. }
  17. confirmDelete(id: number) {
  18. this.postService.delete(id).subscribe(response => {
  19. this.eventManager.broadcast({
  20. name: 'postListModification',
  21. content: 'Deleted an post'
  22. });
  23. this.activeModal.dismiss(true);
  24. });
  25. }
  26. }
  27. @Component({
  28. selector: 'jhi-post-delete-popup',
  29. template: ''
  30. })
  31. export class PostDeletePopupComponent implements OnInit, OnDestroy {
  32. private ngbModalRef: NgbModalRef;
  33. constructor(private activatedRoute: ActivatedRoute, private router: Router, private modalService: NgbModal) {}
  34. ngOnInit() {
  35. this.activatedRoute.data.subscribe(({ post }) => {
  36. setTimeout(() => {
  37. this.ngbModalRef = this.modalService.open(PostDeleteDialogComponent as Component, { size: 'lg', backdrop: 'static' });
  38. this.ngbModalRef.componentInstance.post = post;
  39. this.ngbModalRef.result.then(
  40. result => {
  41. this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
  42. this.ngbModalRef = null;
  43. },
  44. reason => {
  45. this.router.navigate([{ outlets: { popup: null } }], { replaceUrl: true, queryParamsHandling: 'merge' });
  46. this.ngbModalRef = null;
  47. }
  48. );
  49. }, 0);
  50. });
  51. }
  52. ngOnDestroy() {
  53. this.ngbModalRef = null;
  54. }
  55. }