menu.ts 9.5 KB

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