statsMenu.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 '~/composables/layout/Menus/baseMenu'
  5. /**
  6. * @category composables/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', {name: 'fa-chart-bar'}, '/report_activity', true))
  28. }
  29. if (this.$ability.can('display', 'education_quotas_page')) {
  30. children.push(this.constructMenu('educations_quotas_by_education', {name: 'fa-user-circle'}, '/educations_quotas_by_education_year/list/', true))
  31. }
  32. if (this.$ability.can('display', 'fede_stats_page')) {
  33. children.push(this.constructMenu('fede_stats', {name: 'fa-chart-bar'}, '/statistic/membersfedeonly', true))
  34. }
  35. if (this.$ability.can('display', 'structure_stats_page')) {
  36. children.push(this.constructMenu('structure_stats', {name: 'fa-chart-bar'}, '/statistic/membersfedeassos', true))
  37. }
  38. if (children.length === 1) {
  39. return children[0]
  40. } else if (children.length > 0) {
  41. return this.constructMenu('stats', {name: 'fa-chart-bar'}, undefined, undefined, children)
  42. } else {
  43. return null
  44. }
  45. }
  46. }
  47. export const getStatsMenu = ($config: NuxtConfig, $ability: Ability) => new StatsMenu($config, $ability).getMenu()