statsMenu.ts 1.7 KB

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