accessMenu.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Ability } from '@casl/ability'
  2. import { NuxtConfig } from '@nuxt/types/config'
  3. import { AnyStore, ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import { $organizationProfile } from '~/services/profile/organizationProfile'
  5. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  6. /**
  7. * @category composables/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 readonly $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. const 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. } else if (children.length > 0) {
  52. return this.constructMenu('address_book', 'fa-address-book', undefined, undefined, children)
  53. } else {
  54. return null
  55. }
  56. }
  57. }
  58. export const getAccessMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new AccessMenu($config, $ability, $store).getMenu()