menu.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import {ref, useContext} from "@nuxtjs/composition-api";
  2. import {ItemMenu, ItemsMenu} from "~/types/types";
  3. import {$organizationProfile} from "~/services/profile/organizationProfile";
  4. /**
  5. * @category Use/template
  6. * @class Menu
  7. * Use Classe pour la construction du Menu
  8. */
  9. class Menu{
  10. private $ability:any;
  11. private $config:any;
  12. private $store:any;
  13. /**
  14. * @constructor
  15. * Initialisation des services issues du context
  16. */
  17. constructor() {
  18. const {$ability, $config, store} = useContext();
  19. this.$ability = $ability;
  20. this.$config = $config;
  21. this.$store = store;
  22. }
  23. /**
  24. * Construit le menu
  25. */
  26. useMenuConstruct(){
  27. let menu:ItemsMenu = [ this.constructMenu('fa-home', 'welcome', '/dashboard', true) ]
  28. const accessMenu = this.accessMenu()
  29. if(accessMenu) menu.push(accessMenu)
  30. const agendaMenu = this.agendaMenu()
  31. if(agendaMenu) menu.push(agendaMenu)
  32. const equipmentMenu = this.equipmentMenu()
  33. if(equipmentMenu) menu.push(equipmentMenu)
  34. const educationalMenu = this.educationalMenu()
  35. if(educationalMenu) menu.push(educationalMenu)
  36. return ref(menu)
  37. }
  38. /**
  39. * Construit le menu Répertoire ou null si aucune page accessible
  40. * @return {ItemMenu | null}
  41. */
  42. accessMenu():ItemMenu | null {
  43. const children:ItemsMenu = [];
  44. if (this.$ability().can('display', 'accesses_page')) {
  45. const organization = $organizationProfile(this.$store)
  46. let to = organization.isSchool() ? `/students/list/` : `/adherent/list/`
  47. children.push(this.constructMenu('fa-user', 'person', to, true))
  48. }
  49. if (this.$ability().can('display', 'student_registration_page')) {
  50. children.push(this.constructMenu('fa-users', 'family_view', '/student_registration/new', true))
  51. }
  52. if (this.$ability().can('display', 'education_student_next_year_page')) {
  53. children.push(this.constructMenu('fa-list-alt', 'education_student_next_year', '/education_student_next_year/list/', true))
  54. }
  55. if (this.$ability().can('display', 'commissions_page')) {
  56. children.push(this.constructMenu('fa-street-view', 'commissions', '/commissions/list/', true))
  57. }
  58. if (this.$ability().can('display', 'network_children_page')) {
  59. children.push(this.constructMenu('fa-sitemap', 'network', 'networks/list/', true))
  60. }
  61. if (this.$ability().can('display', 'network_parents_page')) {
  62. children.push(this.constructMenu('fa-sitemap', 'my_network', '/network_artist_schools/list/', true))
  63. }
  64. if(children.length === 1){
  65. return children[0];
  66. }
  67. return children.length > 0 ? this.constructMenu('fa-address-book', 'address_book', undefined, undefined, children) : null;
  68. }
  69. /**
  70. * Construit le menu Agenda ou null si aucune page accessible
  71. * @return {ItemMenu | null}
  72. */
  73. agendaMenu():ItemMenu | null {
  74. const children:ItemsMenu = [];
  75. if (this.$ability().can('display', 'agenda_page')) {
  76. children.push(this.constructMenu('fa-calendar-alt', 'schedule', '/calendar', true))
  77. }
  78. if (this.$ability().can('display', 'attendance_page')) {
  79. children.push(this.constructMenu('fa-calendar-check', 'attendances', '/attendances/list/', true))
  80. }
  81. if(children.length === 1){
  82. return children[0];
  83. }
  84. return children.length > 0 ? this.constructMenu('fa-calendar-alt', 'schedule', undefined, undefined, children) : null;
  85. }
  86. /**
  87. * Construit le menu Equipement ou null si aucune page accessible
  88. * @return {ItemMenu | null}
  89. */
  90. equipmentMenu():ItemMenu | null {
  91. return this.constructMenu('fa-cube', 'equipment', '/equipment/list', true)
  92. }
  93. /**
  94. * Construit le menu Suivi pédagogique ou null si aucune page accessible
  95. * @return {ItemMenu | null}
  96. */
  97. educationalMenu():ItemMenu | null {
  98. const children:ItemsMenu = [];
  99. if (this.$ability().can('display', 'criteria_notations_page')) {
  100. children.push(this.constructMenu('fa-bars', 'criteria_notations', '/criteria_notations/list/', true))
  101. }
  102. if (this.$ability().can('display', 'seizure_period_page')) {
  103. children.push(this.constructMenu('fa-calendar-alt', 'seizure_period', '/education_teachers/list/', true))
  104. }
  105. if (this.$ability().can('display', 'test_seizure_page')) {
  106. children.push(this.constructMenu('fa-pencil-alt', 'test_seizure', '/education_input/list/', true))
  107. }
  108. if (this.$ability().can('display', 'test_validation_page')) {
  109. children.push(this.constructMenu('fa-check', 'test_validation', '/education_notations/list/', true))
  110. }
  111. if (this.$ability().can('display', 'examen_results_page')) {
  112. children.push(this.constructMenu('fa-graduation-cap', 'examen_results', '/examen_convocations/list/', true))
  113. }
  114. if (this.$ability().can('display', 'education_by_student_validation_page')) {
  115. children.push(this.constructMenu('fa-check-square', 'education_by_student_validation', '/education_by_student/list/', true))
  116. }
  117. if(children.length === 1){
  118. return children[0];
  119. }
  120. return children.length > 0 ? this.constructMenu('fa-graduation-cap', 'education_state', undefined, undefined, children) : null;
  121. }
  122. /**
  123. * Construit un ItemMenu
  124. * @param {string} icon
  125. * @param {string} title titre qui sera traduit
  126. * @param {string} link lien
  127. * @param {boolean} isOldLink est-ce un lien renvoyant vers l'ancien admin ?
  128. * @param {Array<ItemMenu>} children Tableau d'ItemMenu représentant les sous menu du menu principal
  129. * @return {ItemMenu}
  130. */
  131. constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>): ItemMenu{
  132. return children ? {
  133. icon: icon,
  134. title: title,
  135. children: children,
  136. } : {
  137. icon: icon,
  138. title: title,
  139. to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`,
  140. old: isOldLink,
  141. }
  142. }
  143. }
  144. export default Menu