accessMenu.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * Construit le menu Répertoire, ou null si aucune page accessible
  13. * @return {ItemMenu | null}
  14. */
  15. getMenu (): ItemMenu | null {
  16. const children: ItemsMenu = []
  17. const {can} = useAbility()
  18. if (can('display', 'accesses_page')) {
  19. const organization = $organizationProfile()
  20. const to = organization.isSchool() ? '/students/list/' : '/adherent/list/'
  21. children.push(this.constructMenuItem('person', {name: 'fa-user'}, to, true))
  22. }
  23. if (can('display', 'student_registration_page')) {
  24. children.push(this.constructMenuItem('family_view', {name: 'fa-users'}, '/student_registration/new', true))
  25. }
  26. if (can('display', 'education_student_next_year_page')) {
  27. children.push(this.constructMenuItem('education_student_next_year', {name: 'fa-list-alt'}, '/education_student_next_year/list/', true))
  28. }
  29. if (can('display', 'commissions_page')) {
  30. children.push(this.constructMenuItem('commissions', {name: 'fa-street-view'}, '/commissions/list/', true))
  31. }
  32. if (can('display', 'network_children_page')) {
  33. children.push(this.constructMenuItem('network', {name: 'fa-sitemap'}, 'networks/list/', true))
  34. }
  35. if (can('display', 'network_parents_page')) {
  36. children.push(this.constructMenuItem('my_network', {name: 'fa-sitemap'}, '/network_artist_schools/list/', true))
  37. }
  38. if (children.length === 1) {
  39. return children[0]
  40. } else if (children.length > 0) {
  41. return this.constructMenuItem('address_book', {name: 'fa-address-book'}, undefined, undefined, children)
  42. } else {
  43. return null
  44. }
  45. }
  46. }
  47. export const getAccessMenu = () => new AccessMenu().getMenu()