accessMenuBuilder.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
  2. import type { MenuGroup, MenuItem, MenuItems } from '~/types/layout'
  3. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  4. /**
  5. * Menu Répertoire
  6. */
  7. export default class AccessMenuBuilder extends AbstractMenuBuilder {
  8. static override readonly menuName = 'Access'
  9. /**
  10. * Construit le menu Répertoire, ou null si aucune page accessible
  11. */
  12. build(): MenuGroup | MenuItem | null {
  13. const children: MenuItems = []
  14. if (this.ability.can('display', 'accesses_page')) {
  15. const to = this.organizationProfile.isSchool
  16. ? '/students/list/'
  17. : '/adherent/list/'
  18. children.push(
  19. this.createItem(
  20. 'person',
  21. { name: 'fas fa-user' },
  22. to,
  23. MENU_LINK_TYPE.V1,
  24. ),
  25. )
  26. }
  27. if (this.ability.can('display', 'student_registration_page')) {
  28. children.push(
  29. this.createItem(
  30. 'family_view',
  31. { name: 'fas fa-users' },
  32. '/student_registration/new',
  33. MENU_LINK_TYPE.V1,
  34. ),
  35. )
  36. }
  37. if (this.ability.can('display', 'education_student_next_year_page')) {
  38. children.push(
  39. this.createItem(
  40. 'education_student_next_year',
  41. { name: 'fas fa-list-alt' },
  42. '/education_student_next_year/list/',
  43. MENU_LINK_TYPE.V1,
  44. ),
  45. )
  46. }
  47. if (this.ability.can('display', 'commissions_page')) {
  48. children.push(
  49. this.createItem(
  50. 'commissions',
  51. { name: 'fas fa-street-view' },
  52. '/commissions/list/',
  53. MENU_LINK_TYPE.V1,
  54. ),
  55. )
  56. }
  57. if (this.ability.can('display', 'network_children_page')) {
  58. children.push(
  59. this.createItem(
  60. 'network',
  61. { name: 'fas fa-sitemap' },
  62. 'networks/list/',
  63. MENU_LINK_TYPE.V1,
  64. ),
  65. )
  66. }
  67. if (this.ability.can('display', 'network_parents_page')) {
  68. children.push(
  69. this.createItem(
  70. 'my_network',
  71. { name: 'fas fa-sitemap' },
  72. '/network_artist_schools/list/',
  73. MENU_LINK_TYPE.V1,
  74. ),
  75. )
  76. }
  77. if (children.length > 1) {
  78. // Plusieurs éléments, on retourne un groupe
  79. return this.createGroup(
  80. 'address_book',
  81. { name: 'fas fa-address-book' },
  82. children,
  83. )
  84. } else if (children.length === 1) {
  85. // Un seul élément, on retourne cet élément seul
  86. return children[0]
  87. }
  88. return null
  89. }
  90. }