accessMenu.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {ItemMenu, ItemsMenu} from "~/types/types";
  2. import {$organizationProfile} from "~/services/profile/organizationProfile";
  3. import BaseMenu from "~/use/layout/Menus/baseMenu";
  4. class AccessMenu extends BaseMenu{
  5. private $ability:any;
  6. private $store:any;
  7. constructor($config:any, $ability:any, $store:any) {
  8. super($config)
  9. this.$ability = $ability
  10. this.$store = $store
  11. }
  12. /**
  13. * Construit le menu Répertoire ou null si aucune page accessible
  14. * @return {ItemMenu | null}
  15. */
  16. getMenu():ItemMenu | null {
  17. const children:ItemsMenu = [];
  18. if (this.$ability().can('display', 'accesses_page')) {
  19. const organization = $organizationProfile(this.$store)
  20. let to = organization.isSchool() ? `/students/list/` : `/adherent/list/`
  21. children.push(this.constructMenu('person', 'fa-user', to, true))
  22. }
  23. if (this.$ability().can('display', 'student_registration_page')) {
  24. children.push(this.constructMenu('family_view', 'fa-users', '/student_registration/new', true))
  25. }
  26. if (this.$ability().can('display', 'education_student_next_year_page')) {
  27. children.push(this.constructMenu('education_student_next_year', 'fa-list-alt', '/education_student_next_year/list/', true))
  28. }
  29. if (this.$ability().can('display', 'commissions_page')) {
  30. children.push(this.constructMenu('commissions', 'fa-street-view', '/commissions/list/', true))
  31. }
  32. if (this.$ability().can('display', 'network_children_page')) {
  33. children.push(this.constructMenu('network', 'fa-sitemap', 'networks/list/', true))
  34. }
  35. if (this.$ability().can('display', 'network_parents_page')) {
  36. children.push(this.constructMenu('my_network', 'fa-sitemap', '/network_artist_schools/list/', true))
  37. }
  38. if(children.length === 1){
  39. return children[0];
  40. }
  41. return children.length > 0 ? this.constructMenu('address_book', 'fa-address-book', undefined, undefined, children) : null;
  42. }
  43. }
  44. export const getAccessMenu = ($config:any, $ability:any, $store:any) => new AccessMenu($config, $ability, $store).getMenu()