accessMenu.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  2. import { $organizationProfile } from '~/services/profile/organizationProfile'
  3. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  4. import {useAbility} from "@casl/vue";
  5. /**
  6. * @category composables/layout/Menus
  7. * @class AccessMenu
  8. * Classe pour la construction du Menu Répertoire
  9. */
  10. class AccessMenu extends BaseMenu implements Menu {
  11. /**
  12. * @constructor
  13. * Initialisation des services issues du context
  14. */
  15. constructor () {
  16. const {$config} = useNuxtApp()
  17. super($config)
  18. }
  19. /**
  20. * Construit le menu Répertoire, ou null si aucune page accessible
  21. * @return {ItemMenu | null}
  22. */
  23. getMenu (): ItemMenu | null {
  24. const children: ItemsMenu = []
  25. const {can} = useAbility()
  26. if (can('display', 'accesses_page')) {
  27. const organization = $organizationProfile()
  28. const to = organization.isSchool() ? '/students/list/' : '/adherent/list/'
  29. children.push(this.constructMenu('person', {name: 'fa-user'}, to, true))
  30. }
  31. if (can('display', 'student_registration_page')) {
  32. children.push(this.constructMenu('family_view', {name: 'fa-users'}, '/student_registration/new', true))
  33. }
  34. if (can('display', 'education_student_next_year_page')) {
  35. children.push(this.constructMenu('education_student_next_year', {name: 'fa-list-alt'}, '/education_student_next_year/list/', true))
  36. }
  37. if (can('display', 'commissions_page')) {
  38. children.push(this.constructMenu('commissions', {name: 'fa-street-view'}, '/commissions/list/', true))
  39. }
  40. if (can('display', 'network_children_page')) {
  41. children.push(this.constructMenu('network', {name: 'fa-sitemap'}, 'networks/list/', true))
  42. }
  43. if (can('display', 'network_parents_page')) {
  44. children.push(this.constructMenu('my_network', {name: 'fa-sitemap'}, '/network_artist_schools/list/', true))
  45. }
  46. if (children.length === 1) {
  47. return children[0]
  48. } else if (children.length > 0) {
  49. return this.constructMenu('address_book', {name: 'fa-address-book'}, undefined, undefined, children)
  50. } else {
  51. return null
  52. }
  53. }
  54. }
  55. export const getAccessMenu = () => new AccessMenu().getMenu()