configurationMenuBuilder.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. import UrlUtils from '~/services/utils/urlUtils'
  5. /**
  6. * Classe pour la construction du Menu Paramètres
  7. */
  8. export default class ConfigurationMenuBuilder extends AbstractMenuBuilder {
  9. static readonly menuName = 'Configuration'
  10. /**
  11. * Construit le menu Header Configuration ou null si aucune page accessible
  12. */
  13. build(): MenuItem | MenuGroup | null {
  14. const children: MenuItems = []
  15. if (this.ability.can('display', 'organization_page')) {
  16. children.push(
  17. this.createItem(
  18. 'organization_page',
  19. undefined,
  20. UrlUtils.join(
  21. '/main/organizations',
  22. this.organizationProfile.id ?? '',
  23. '/dashboard',
  24. ),
  25. MENU_LINK_TYPE.V1,
  26. ),
  27. )
  28. }
  29. if (this.ability.can('display', 'cmf_licence_page')) {
  30. children.push(
  31. this.createItem(
  32. 'cmf_licence_generate',
  33. undefined,
  34. '/cmf_licence_structure',
  35. MENU_LINK_TYPE.INTERNAL,
  36. ),
  37. )
  38. }
  39. if (this.ability.can('display', 'parameters_page')) {
  40. children.push(
  41. this.createItem(
  42. 'parameters',
  43. undefined,
  44. `/parameters`,
  45. MENU_LINK_TYPE.INTERNAL,
  46. ),
  47. )
  48. }
  49. if (this.ability.can('display', 'place_page')) {
  50. children.push(
  51. this.createItem(
  52. 'places',
  53. undefined,
  54. '/places/list/',
  55. MENU_LINK_TYPE.V1,
  56. ),
  57. )
  58. }
  59. if (this.ability.can('display', 'education_page')) {
  60. children.push(
  61. this.createItem(
  62. 'education',
  63. undefined,
  64. '/educations/list/',
  65. MENU_LINK_TYPE.V1,
  66. ),
  67. )
  68. }
  69. if (this.ability.can('display', 'tag_page')) {
  70. children.push(
  71. this.createItem('tags', undefined, '/taggs/list/', MENU_LINK_TYPE.V1),
  72. )
  73. }
  74. if (this.ability.can('display', 'activities_page')) {
  75. children.push(
  76. this.createItem(
  77. 'activities',
  78. undefined,
  79. '/activities/list/',
  80. MENU_LINK_TYPE.V1,
  81. ),
  82. )
  83. }
  84. if (this.ability.can('display', 'template_systems_page')) {
  85. children.push(
  86. this.createItem(
  87. 'template_systems',
  88. undefined,
  89. '/template_systems/list/',
  90. MENU_LINK_TYPE.V1,
  91. ),
  92. )
  93. }
  94. if (this.ability.can('display', 'billing_settings_page')) {
  95. children.push(
  96. this.createItem(
  97. 'billing_settings',
  98. undefined,
  99. UrlUtils.join(
  100. '/main/edit/billing_settings/',
  101. this.organizationProfile.id ?? '',
  102. ),
  103. MENU_LINK_TYPE.V1,
  104. ),
  105. )
  106. }
  107. if (this.ability.can('display', 'billing_schedules_settings_page')) {
  108. children.push(
  109. this.createItem(
  110. 'billing_schedules',
  111. undefined,
  112. '/bill_schedules/list/',
  113. MENU_LINK_TYPE.V1,
  114. ),
  115. )
  116. }
  117. if (this.ability.can('display', 'online_registration_settings_page')) {
  118. children.push(
  119. this.createItem(
  120. 'online_registration_settings',
  121. undefined,
  122. UrlUtils.join(
  123. '/main/edit/online_registration_settings/',
  124. this.organizationProfile.id ?? '',
  125. ),
  126. MENU_LINK_TYPE.V1,
  127. ),
  128. )
  129. }
  130. if (this.ability.can('display', 'course_duplication_page')) {
  131. children.push(
  132. this.createItem(
  133. 'course_duplication',
  134. undefined,
  135. '/duplicate_courses',
  136. MENU_LINK_TYPE.V1,
  137. ),
  138. )
  139. }
  140. if (this.ability.can('display', 'import_page')) {
  141. children.push(
  142. this.createItem('import', undefined, '/import/all', MENU_LINK_TYPE.V1),
  143. )
  144. }
  145. if (children.length > 1) {
  146. // Plusieurs éléments, on retourne un groupe
  147. return this.createGroup(
  148. 'configuration',
  149. { name: 'fas fa-cogs' },
  150. children,
  151. )
  152. } else if (children.length === 1) {
  153. // Un seul élément, on retourne cet élément seul
  154. return children[0]
  155. }
  156. return null
  157. }
  158. }