statsMenu.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { NuxtConfig } from '@nuxt/types/config'
  2. import { Ability } from '@casl/ability'
  3. import { ItemMenu, ItemsMenu, Menu } from '~/types/interfaces'
  4. import BaseMenu from '~/use/layout/Menus/baseMenu'
  5. /**
  6. * @category Use/layout/Menus
  7. * @class StatsMenu
  8. * Classe pour la construction du Menu Statistiques
  9. */
  10. class StatsMenu extends BaseMenu implements Menu {
  11. private $ability: Ability;
  12. /**
  13. * @constructor
  14. * Initialisation des services issues du context
  15. */
  16. constructor ($config: NuxtConfig, $ability: Ability) {
  17. super($config)
  18. this.$ability = $ability
  19. }
  20. /**
  21. * Construit le menu Statistique et Dons ou null si aucune page accessible
  22. * @return {ItemMenu | null}
  23. */
  24. getMenu (): ItemMenu | null {
  25. const children: ItemsMenu = []
  26. if (this.$ability.can('display', 'report_activity_page')) {
  27. children.push(this.constructMenu('report_activity', 'fa-chart-bar', '/report_activity', true))
  28. }
  29. if (this.$ability.can('display', 'fede_stats_page')) {
  30. children.push(this.constructMenu('fede_stats', 'fa-chart-bar', '/statistic/membersfedeonly', true))
  31. }
  32. if (this.$ability.can('display', 'structure_stats_page')) {
  33. children.push(this.constructMenu('structure_stats', 'fa-chart-bar', '/statistic/membersfedeassos', true))
  34. }
  35. if (children.length === 1) {
  36. return children[0]
  37. } else if (children.length > 0) {
  38. return this.constructMenu('stats', 'fa-chart-bar', undefined, undefined, children)
  39. } else {
  40. return null
  41. }
  42. }
  43. }
  44. export const getStatsMenu = ($config: NuxtConfig, $ability: Ability) => new StatsMenu($config, $ability).getMenu()