menu.ts 8.6 KB

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