post.route.ts 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Injectable } from '@angular/core';
  2. import { HttpResponse } from '@angular/common/http';
  3. import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot, Routes } from '@angular/router';
  4. import { UserRouteAccessService } from 'app/core';
  5. import { Observable, of } from 'rxjs';
  6. import { filter, map } from 'rxjs/operators';
  7. import { Post } from 'app/shared/model/post.model';
  8. import { PostService } from './post.service';
  9. import { PostComponent } from './post.component';
  10. import { PostDetailComponent } from './post-detail.component';
  11. import { PostUpdateComponent } from './post-update.component';
  12. import { PostDeletePopupComponent } from './post-delete-dialog.component';
  13. import { IPost } from 'app/shared/model/post.model';
  14. @Injectable({ providedIn: 'root' })
  15. export class PostResolve implements Resolve<IPost> {
  16. constructor(private service: PostService) {}
  17. resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Post> {
  18. const id = route.params['id'] ? route.params['id'] : null;
  19. if (id) {
  20. return this.service.find(id).pipe(
  21. filter((response: HttpResponse<Post>) => response.ok),
  22. map((post: HttpResponse<Post>) => post.body)
  23. );
  24. }
  25. return of(new Post());
  26. }
  27. }
  28. export const postRoute: Routes = [
  29. {
  30. path: 'post',
  31. component: PostComponent,
  32. data: {
  33. authorities: ['ROLE_USER'],
  34. pageTitle: 'zipConnectApp.post.home.title'
  35. },
  36. canActivate: [UserRouteAccessService]
  37. },
  38. {
  39. path: 'post/:id/view',
  40. component: PostDetailComponent,
  41. resolve: {
  42. post: PostResolve
  43. },
  44. data: {
  45. authorities: ['ROLE_USER'],
  46. pageTitle: 'zipConnectApp.post.home.title'
  47. },
  48. canActivate: [UserRouteAccessService]
  49. },
  50. {
  51. path: 'post/new',
  52. component: PostUpdateComponent,
  53. resolve: {
  54. post: PostResolve
  55. },
  56. data: {
  57. authorities: ['ROLE_USER'],
  58. pageTitle: 'zipConnectApp.post.home.title'
  59. },
  60. canActivate: [UserRouteAccessService]
  61. },
  62. {
  63. path: 'post/:id/edit',
  64. component: PostUpdateComponent,
  65. resolve: {
  66. post: PostResolve
  67. },
  68. data: {
  69. authorities: ['ROLE_USER'],
  70. pageTitle: 'zipConnectApp.post.home.title'
  71. },
  72. canActivate: [UserRouteAccessService]
  73. }
  74. ];
  75. export const postPopupRoute: Routes = [
  76. {
  77. path: 'post/:id/delete',
  78. component: PostDeletePopupComponent,
  79. resolve: {
  80. post: PostResolve
  81. },
  82. data: {
  83. authorities: ['ROLE_USER'],
  84. pageTitle: 'zipConnectApp.post.home.title'
  85. },
  86. canActivate: [UserRouteAccessService],
  87. outlet: 'popup'
  88. }
  89. ];