menu.ts 9.1 KB

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