agendaMenu.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import {ItemMenu, ItemsMenu} from "~/types/types";
  2. import BaseMenu from "~/use/layout/Menus/baseMenu";
  3. class AgendaMenu extends BaseMenu{
  4. private $ability:any;
  5. constructor($config:any, $ability:any) {
  6. super($config)
  7. this.$ability = $ability
  8. }
  9. /**
  10. * Construit le menu Agenda ou null si aucune page accessible
  11. * @return {ItemMenu | null}
  12. */
  13. getMenu():ItemMenu | null {
  14. const children:ItemsMenu = [];
  15. if (this.$ability().can('display', 'agenda_page')) {
  16. children.push(this.constructMenu('schedule', 'fa-calendar-alt', '/calendar', true))
  17. }
  18. if (this.$ability().can('display', 'attendance_page')) {
  19. children.push(this.constructMenu('attendances', 'fa-calendar-check', '/attendances/list/', true))
  20. }
  21. if(children.length === 1){
  22. return children[0];
  23. }
  24. return children.length > 0 ? this.constructMenu('schedule', 'fa-calendar-alt', undefined, undefined, children) : null;
  25. }
  26. }
  27. export const getAgendaMenu = ($config:any, $ability:any) => new AgendaMenu($config, $ability).getMenu()