cohort.route.ts 2.9KB

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 { Cohort } from 'app/shared/model/cohort.model';
  8. import { CohortService } from './cohort.service';
  9. import { CohortComponent } from './cohort.component';
  10. import { CohortDetailComponent } from './cohort-detail.component';
  11. import { CohortUpdateComponent } from './cohort-update.component';
  12. import { CohortDeletePopupComponent } from './cohort-delete-dialog.component';
  13. import { ICohort } from 'app/shared/model/cohort.model';
  14. @Injectable({ providedIn: 'root' })
  15. export class CohortResolve implements Resolve<ICohort> {
  16. constructor(private service: CohortService) {}
  17. resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Cohort> {
  18. const id = route.params['id'] ? route.params['id'] : null;
  19. if (id) {
  20. return this.service.find(id).pipe(
  21. filter((response: HttpResponse<Cohort>) => response.ok),
  22. map((cohort: HttpResponse<Cohort>) => cohort.body)
  23. );
  24. }
  25. return of(new Cohort());
  26. }
  27. }
  28. export const cohortRoute: Routes = [
  29. {
  30. path: 'cohort',
  31. component: CohortComponent,
  32. data: {
  33. authorities: ['ROLE_USER'],
  34. pageTitle: 'zipConnectApp.cohort.home.title'
  35. },
  36. canActivate: [UserRouteAccessService]
  37. },
  38. {
  39. path: 'cohort/:id/view',
  40. component: CohortDetailComponent,
  41. resolve: {
  42. cohort: CohortResolve
  43. },
  44. data: {
  45. authorities: ['ROLE_USER'],
  46. pageTitle: 'zipConnectApp.cohort.home.title'
  47. },
  48. canActivate: [UserRouteAccessService]
  49. },
  50. {
  51. path: 'cohort/new',
  52. component: CohortUpdateComponent,
  53. resolve: {
  54. cohort: CohortResolve
  55. },
  56. data: {
  57. authorities: ['ROLE_USER'],
  58. pageTitle: 'zipConnectApp.cohort.home.title'
  59. },
  60. canActivate: [UserRouteAccessService]
  61. },
  62. {
  63. path: 'cohort/:id/edit',
  64. component: CohortUpdateComponent,
  65. resolve: {
  66. cohort: CohortResolve
  67. },
  68. data: {
  69. authorities: ['ROLE_USER'],
  70. pageTitle: 'zipConnectApp.cohort.home.title'
  71. },
  72. canActivate: [UserRouteAccessService]
  73. }
  74. ];
  75. export const cohortPopupRoute: Routes = [
  76. {
  77. path: 'cohort/:id/delete',
  78. component: CohortDeletePopupComponent,
  79. resolve: {
  80. cohort: CohortResolve
  81. },
  82. data: {
  83. authorities: ['ROLE_USER'],
  84. pageTitle: 'zipConnectApp.cohort.home.title'
  85. },
  86. canActivate: [UserRouteAccessService],
  87. outlet: 'popup'
  88. }
  89. ];