accessMenuBuilder.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. name() {
  10. return 'Access'
  11. }
  12. /**
  13. * Construit le menu Répertoire, ou null si aucune page accessible
  14. */
  15. build (): MenuGroup | MenuItem | null {
  16. const children: MenuItems = []
  17. if (this.ability.can('display', 'accesses_page')) {
  18. const organization = $organizationProfile()
  19. const to = organization.isSchool() ? '/students/list/' : '/adherent/list/'
  20. children.push(this.createItem('person', {name: 'fas fa-user'}, to, MENU_LINK_TYPE.V1))
  21. }
  22. if (this.ability.can('display', 'student_registration_page')) {
  23. children.push(this.createItem('family_view', {name: 'fas fa-users'}, '/student_registration/new', MENU_LINK_TYPE.V1))
  24. }
  25. if (this.ability.can('display', 'education_student_next_year_page')) {
  26. children.push(this.createItem('education_student_next_year', {name: 'fas fa-list-alt'}, '/education_student_next_year/list/', MENU_LINK_TYPE.V1))
  27. }
  28. if (this.ability.can('display', 'commissions_page')) {
  29. children.push(this.createItem('commissions', {name: 'fas fa-street-view'}, '/commissions/list/', MENU_LINK_TYPE.V1))
  30. }
  31. if (this.ability.can('display', 'network_children_page')) {
  32. children.push(this.createItem('network', {name: 'fas fa-sitemap'}, 'networks/list/', MENU_LINK_TYPE.V1))
  33. }
  34. if (this.ability.can('display', 'network_parents_page')) {
  35. children.push(this.createItem('my_network', {name: 'fas fa-sitemap'}, '/network_artist_schools/list/', MENU_LINK_TYPE.V1))
  36. }
  37. if (children.length > 1) {
  38. // Plusieurs éléments, on retourne un groupe
  39. return this.createGroup('address_book', {name: 'fas fa-address-book'}, children)
  40. } else if (children.length === 1) {
  41. // Un seul élément, on retourne cet élément seul
  42. return children[0]
  43. }
  44. return null
  45. }
  46. }