accessMenuBuilder.ts 2.0 KB

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