accessMenu.ts 2.4 KB

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