menu.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. }
  19. setUpContext(){
  20. const {$ability, $config, store} = useContext();
  21. this.$ability = $ability;
  22. this.$config = $config;
  23. this.$store = store;
  24. return this;
  25. }
  26. /**
  27. * Construit le menu
  28. */
  29. useMenuConstruct(){
  30. let menu:ItemsMenu = [ this.constructMenu('fa-home', 'welcome', '/dashboard', true) ]
  31. const accessMenu = this.accessMenu()
  32. if(accessMenu) menu.push(accessMenu)
  33. const agendaMenu = this.agendaMenu()
  34. if(agendaMenu) menu.push(agendaMenu)
  35. const equipmentMenu = this.equipmentMenu()
  36. if(equipmentMenu) menu.push(equipmentMenu)
  37. const educationalMenu = this.educationalMenu()
  38. if(educationalMenu) menu.push(educationalMenu)
  39. const billingMenu = this.billingMenu()
  40. if(billingMenu) menu.push(billingMenu)
  41. return ref(menu)
  42. }
  43. /**
  44. * Construit le menu Répertoire ou null si aucune page accessible
  45. * @return {ItemMenu | null}
  46. */
  47. accessMenu():ItemMenu | null {
  48. const children:ItemsMenu = [];
  49. if (this.$ability().can('display', 'accesses_page')) {
  50. const organization = $organizationProfile(this.$store)
  51. let to = organization.isSchool() ? `/students/list/` : `/adherent/list/`
  52. children.push(this.constructMenu('fa-user', 'person', to, true))
  53. }
  54. if (this.$ability().can('display', 'student_registration_page')) {
  55. children.push(this.constructMenu('fa-users', 'family_view', '/student_registration/new', true))
  56. }
  57. if (this.$ability().can('display', 'education_student_next_year_page')) {
  58. children.push(this.constructMenu('fa-list-alt', 'education_student_next_year', '/education_student_next_year/list/', true))
  59. }
  60. if (this.$ability().can('display', 'commissions_page')) {
  61. children.push(this.constructMenu('fa-street-view', 'commissions', '/commissions/list/', true))
  62. }
  63. if (this.$ability().can('display', 'network_children_page')) {
  64. children.push(this.constructMenu('fa-sitemap', 'network', 'networks/list/', true))
  65. }
  66. if (this.$ability().can('display', 'network_parents_page')) {
  67. children.push(this.constructMenu('fa-sitemap', 'my_network', '/network_artist_schools/list/', true))
  68. }
  69. if(children.length === 1){
  70. return children[0];
  71. }
  72. return children.length > 0 ? this.constructMenu('fa-address-book', 'address_book', undefined, undefined, children) : null;
  73. }
  74. /**
  75. * Construit le menu Agenda ou null si aucune page accessible
  76. * @return {ItemMenu | null}
  77. */
  78. agendaMenu():ItemMenu | null {
  79. const children:ItemsMenu = [];
  80. if (this.$ability().can('display', 'agenda_page')) {
  81. children.push(this.constructMenu('fa-calendar-alt', 'schedule', '/calendar', true))
  82. }
  83. if (this.$ability().can('display', 'attendance_page')) {
  84. children.push(this.constructMenu('fa-calendar-check', 'attendances', '/attendances/list/', true))
  85. }
  86. if(children.length === 1){
  87. return children[0];
  88. }
  89. return children.length > 0 ? this.constructMenu('fa-calendar-alt', 'schedule', undefined, undefined, children) : null;
  90. }
  91. /**
  92. * Construit le menu Equipement ou null si aucune page accessible
  93. * @return {ItemMenu | null}
  94. */
  95. equipmentMenu():ItemMenu | null {
  96. return this.constructMenu('fa-cube', 'equipment', '/equipment/list', true)
  97. }
  98. /**
  99. * Construit le menu Suivi pédagogique ou null si aucune page accessible
  100. * @return {ItemMenu | null}
  101. */
  102. educationalMenu():ItemMenu | null {
  103. const children:ItemsMenu = [];
  104. if (this.$ability().can('display', 'criteria_notations_page')) {
  105. children.push(this.constructMenu('fa-bars', 'criteria_notations', '/criteria_notations/list/', true))
  106. }
  107. if (this.$ability().can('display', 'seizure_period_page')) {
  108. children.push(this.constructMenu('fa-calendar-alt', 'seizure_period', '/education_teachers/list/', true))
  109. }
  110. if (this.$ability().can('display', 'test_seizure_page')) {
  111. children.push(this.constructMenu('fa-pencil-alt', 'test_seizure', '/education_input/list/', true))
  112. }
  113. if (this.$ability().can('display', 'test_validation_page')) {
  114. children.push(this.constructMenu('fa-check', 'test_validation', '/education_notations/list/', true))
  115. }
  116. if (this.$ability().can('display', 'examen_results_page')) {
  117. children.push(this.constructMenu('fa-graduation-cap', 'examen_results', '/examen_convocations/list/', true))
  118. }
  119. if (this.$ability().can('display', 'education_by_student_validation_page')) {
  120. children.push(this.constructMenu('fa-check-square', 'education_by_student_validation', '/education_by_student/list/', true))
  121. }
  122. if(children.length === 1){
  123. return children[0];
  124. }
  125. return children.length > 0 ? this.constructMenu('fa-graduation-cap', 'education_state', undefined, undefined, children) : null;
  126. }
  127. /**
  128. * Construit le menu Facturation ou null si aucune page accessible
  129. * @return {ItemMenu | null}
  130. */
  131. billingMenu():ItemMenu | null {
  132. const children:ItemsMenu = [];
  133. if (this.$ability().can('display', 'billing_product_page')) {
  134. children.push(this.constructMenu('fa-cube', 'billing_product', '/intangibles/list/', true))
  135. }
  136. if (this.$ability().can('display', 'billing_products_by_student_page')) {
  137. children.push(this.constructMenu('fa-cubes', 'billing_products_by_student', '/access_intangibles/list/', true))
  138. }
  139. if (this.$ability().can('display', 'billing_edition_page')) {
  140. children.push(this.constructMenu('fa-copy', 'billing_edition', '/billing_edition', true))
  141. }
  142. if (this.$ability().can('display', 'billing_accounting_page')) {
  143. children.push(this.constructMenu('fa-file-alt', 'billing_accounting', '/bill_accountings/list/', true))
  144. }
  145. if (this.$ability().can('display', 'billing_payment_list_page')) {
  146. children.push(this.constructMenu('fa-credit-card', 'billing_payment_list', '/bill_payments_list/list/', true))
  147. }
  148. if (this.$ability().can('display', 'pes_page')) {
  149. children.push(this.constructMenu('fa-align-justify', 'pes_export', '/pes/list/', true))
  150. }
  151. if (this.$ability().can('display', 'berger_levrault_page')) {
  152. children.push(this.constructMenu('fa-align-justify', 'berger_levrault_export', '/berger_levraults/list/', true))
  153. }
  154. if (this.$ability().can('display', 'jvs_page')) {
  155. children.push(this.constructMenu('fa-align-justify', 'jvs_export', '/jvs/list/', true))
  156. }
  157. if(children.length === 1){
  158. return children[0];
  159. }
  160. return children.length > 0 ? this.constructMenu('fa-euro-sign', 'billing', undefined, undefined, children) : null;
  161. }
  162. /**
  163. * Construit un ItemMenu
  164. * @param {string} icon
  165. * @param {string} title titre qui sera traduit
  166. * @param {string} link lien
  167. * @param {boolean} isOldLink est-ce un lien renvoyant vers l'ancien admin ?
  168. * @param {Array<ItemMenu>} children Tableau d'ItemMenu représentant les sous menu du menu principal
  169. * @return {ItemMenu}
  170. */
  171. constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>): ItemMenu{
  172. return children ? {
  173. icon: icon,
  174. title: title,
  175. children: children,
  176. } : {
  177. icon: icon,
  178. title: title,
  179. to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`,
  180. old: isOldLink,
  181. }
  182. }
  183. }
  184. export const $useMenu = new Menu()