statsMenu.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {ItemMenu, ItemsMenu, Menu} from "~/types/interfaces";
  2. import BaseMenu from "~/use/layout/Menus/baseMenu";
  3. import {NuxtConfig} from "@nuxt/types/config";
  4. import {Ability} from "@casl/ability";
  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. }
  38. return children.length > 0 ? this.constructMenu('stats', 'fa-chart-bar', undefined, undefined, children) : null;
  39. }
  40. }
  41. export const getStatsMenu = ($config:NuxtConfig, $ability:Ability) => new StatsMenu($config, $ability).getMenu()