accessMenuBuilder.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import {$organizationProfile} from '~/services/profile/organizationProfile'
  2. import AbstractMenuBuilder from '~/services/menuBuilder/abstractMenuBuilder'
  3. import {MenuGroup, MenuItem, MenuItems} from "~/types/layout";
  4. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  5. /**
  6. * Menu Répertoire
  7. */
  8. export default class AccessMenuBuilder extends AbstractMenuBuilder {
  9. static readonly menuName = "Access"
  10. /**
  11. * Construit le menu Répertoire, ou null si aucune page accessible
  12. */
  13. build (): MenuGroup | MenuItem | null {
  14. const children: MenuItems = []
  15. if (this.ability.can('display', 'accesses_page')) {
  16. const organization = $organizationProfile()
  17. const to = organization.isSchool() ? '/students/list/' : '/adherent/list/'
  18. children.push(this.createItem('person', {name: 'fas fa-user'}, to, MENU_LINK_TYPE.V1))
  19. }
  20. if (this.ability.can('display', 'student_registration_page')) {
  21. children.push(this.createItem('family_view', {name: 'fas fa-users'}, '/student_registration/new', MENU_LINK_TYPE.V1))
  22. }
  23. if (this.ability.can('display', 'education_student_next_year_page')) {
  24. children.push(this.createItem('education_student_next_year', {name: 'fas fa-list-alt'}, '/education_student_next_year/list/', MENU_LINK_TYPE.V1))
  25. }
  26. if (this.ability.can('display', 'commissions_page')) {
  27. children.push(this.createItem('commissions', {name: 'fas fa-street-view'}, '/commissions/list/', MENU_LINK_TYPE.V1))
  28. }
  29. if (this.ability.can('display', 'network_children_page')) {
  30. children.push(this.createItem('network', {name: 'fas fa-sitemap'}, 'networks/list/', MENU_LINK_TYPE.V1))
  31. }
  32. if (this.ability.can('display', 'network_parents_page')) {
  33. children.push(this.createItem('my_network', {name: 'fas fa-sitemap'}, '/network_artist_schools/list/', MENU_LINK_TYPE.V1))
  34. }
  35. if (children.length > 1) {
  36. // Plusieurs éléments, on retourne un groupe
  37. return this.createGroup('address_book', {name: 'fas fa-address-book'}, children)
  38. } else if (children.length === 1) {
  39. // Un seul élément, on retourne cet élément seul
  40. return children[0]
  41. }
  42. return null
  43. }
  44. }