parametersMenu.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Ability } from '@casl/ability'
  2. import { NuxtConfig } from '@nuxt/types/config'
  3. import { AnyStore, ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import BaseMenu from '~/composables/layout/Menus/baseMenu'
  5. /**
  6. * @category composables/layout/Menus
  7. * @class ConfigurationMenu
  8. * Classe pour la construction du Menu Paramètres
  9. */
  10. class ParametersMenu extends BaseMenu implements Menu {
  11. private $ability: Ability;
  12. private $store: AnyStore;
  13. /**
  14. * @constructor
  15. * Initialisation des services issues du context
  16. */
  17. constructor ($config: NuxtConfig, $ability: Ability, $store: AnyStore) {
  18. super($config)
  19. this.$ability = $ability
  20. this.$store = $store
  21. }
  22. /**
  23. * Construit le menu Header Configuration ou null si aucune page accessible
  24. * @return {ItemMenu | null}
  25. */
  26. getMenus (): ItemsMenu | null {
  27. const children: ItemsMenu = []
  28. if (this.$ability.can('display', 'parameters_page')) {
  29. children.push(this.constructMenu('general_params', 'fa-cogs',`/parameters`, false))
  30. }
  31. if (this.$ability.can('display', 'parameters_communication_page')) {
  32. children.push(this.constructMenu('communication_params', 'fa-comments',`/parameters/communication`, false))
  33. }
  34. if (this.$ability.can('display', 'parameters_student_page')) {
  35. children.push(this.constructMenu('students_params', 'fa-users',`/parameters/student`, false))
  36. }
  37. if (this.$ability.can('display', 'parameters_education_page')) {
  38. children.push(this.constructMenu('education_params', 'fa-graduation-cap',`/parameters/education`, false))
  39. }
  40. if (this.$ability.can('display', 'parameters_bills_page')) {
  41. children.push(this.constructMenu('bills_params', 'fa-euro-sign',`/parameters/billing`, false))
  42. }
  43. if (this.$ability.can('display', 'parameters_secure_page')) {
  44. children.push(this.constructMenu('secure_params', 'fa-lock',`/parameters/secure`, false))
  45. }
  46. if (children.length > 0) {
  47. return children
  48. } else {
  49. return null
  50. }
  51. }
  52. }
  53. export const getParametersMenu = ($config: NuxtConfig, $ability: Ability, $store: AnyStore) => new ParametersMenu($config, $ability, $store).getMenus()