statsMenuBuilder.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import AbstractMenuBuilder from '~/services/layout/menuBuilder/abstractMenuBuilder'
  2. import type { MenuGroup, MenuItem, MenuItems } from '~/types/layout'
  3. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  4. /**
  5. * Menu Statistiques
  6. */
  7. export default class StatsMenuBuilder extends AbstractMenuBuilder {
  8. static override readonly menuName = 'Stats'
  9. /**
  10. * Construit le menu Statistique et Dons ou null si aucune page accessible
  11. */
  12. build(): MenuItem | MenuGroup | null {
  13. const children: MenuItems = []
  14. if (this.ability.can('display', 'report_activity_page')) {
  15. children.push(
  16. this.createItem(
  17. 'report_activity',
  18. { name: 'fas fa-chart-bar' },
  19. '/report_activity',
  20. MENU_LINK_TYPE.V1,
  21. ),
  22. )
  23. }
  24. if (this.ability.can('display', 'education_quotas_page')) {
  25. children.push(
  26. this.createItem(
  27. 'educations_quotas_by_education',
  28. { name: 'fas fa-user-circle' },
  29. '/educations_quotas_by_education_year/list/',
  30. MENU_LINK_TYPE.V1,
  31. ),
  32. )
  33. children.push(
  34. this.createItem(
  35. 'accesses_quotas_courses_hebdos',
  36. { name: 'fas fa-user-circle' },
  37. '/accesses_quotas_courses_hebdos/list/',
  38. MENU_LINK_TYPE.V1,
  39. ),
  40. )
  41. }
  42. if (this.ability.can('display', 'fede_stats_page')) {
  43. children.push(
  44. this.createItem(
  45. 'fede_stats',
  46. { name: 'fas fa-chart-bar' },
  47. '/statistic/membersfedeonly',
  48. MENU_LINK_TYPE.V1,
  49. ),
  50. )
  51. }
  52. if (children.length > 1) {
  53. // Plusieurs éléments, on retourne un groupe
  54. return this.createGroup('stats', { name: 'fas fa-chart-bar' }, children)
  55. } else if (children.length === 1) {
  56. // Un seul élément, on retourne cet élément seul
  57. return children[0]
  58. }
  59. return null
  60. }
  61. }