import {ref, useContext} from "@nuxtjs/composition-api"; import {ItemMenu, ItemsMenu} from "~/types/types"; import {organizationProfile} from "~/services/profile/organizationProfile"; export default class Menu{ private $ability:any; private $config:any; private $store:any; constructor() { const {$ability, $config, store} = useContext(); this.$ability = $ability; this.$config = $config; this.$store = store; } useMenuConstruct(){ let menu:ItemsMenu = [ this.constructMenu('fa-home', 'welcome', '/dashboard', true) ] const accessMenu = this.accessMenu() if(accessMenu) menu.push(accessMenu) const agendaMenu = this.agendaMenu() if(agendaMenu) menu.push(agendaMenu) const equipmentMenu = this.equipmentMenu() if(equipmentMenu) menu.push(equipmentMenu) const educationalMenu = this.educationalMenu() if(educationalMenu) menu.push(educationalMenu) return ref(menu) } /** * Menu Répertoire */ accessMenu():ItemMenu | null { const children:ItemsMenu = []; if (this.$ability().can('display', 'accesses_page')) { const organization = organizationProfile(this.$store) let to = organization.isSchool() ? `/students/list/` : `/adherent/list/` children.push(this.constructMenu('fa-user', 'person', to, true)) } if (this.$ability().can('display', 'student_registration_page')) { children.push(this.constructMenu('fa-users', 'family_view', '/student_registration/new', true)) } if (this.$ability().can('display', 'education_student_next_year_page')) { children.push(this.constructMenu('fa-list-alt', 'education_student_next_year', '/education_student_next_year/list/', true)) } if (this.$ability().can('display', 'commissions_page')) { children.push(this.constructMenu('fa-street-view', 'commissions', '/commissions/list/', true)) } if (this.$ability().can('display', 'network_children_page')) { children.push(this.constructMenu('fa-sitemap', 'network', 'networks/list/', true)) } if (this.$ability().can('display', 'network_parents_page')) { children.push(this.constructMenu('fa-sitemap', 'my_network', '/network_artist_schools/list/', true)) } if(children.length === 1){ return children[0]; } return children.length > 0 ? this.constructMenu('fa-address-book', 'address_book', undefined, undefined, children) : null; } /** * Menu agenda */ agendaMenu():ItemMenu | null { const children:ItemsMenu = []; if (this.$ability().can('display', 'agenda_page')) { children.push(this.constructMenu('fa-calendar-alt', 'schedule', '/calendar', true)) } if (this.$ability().can('display', 'attendance_page')) { children.push(this.constructMenu('fa-calendar-check', 'attendances', '/attendances/list/', true)) } if(children.length === 1){ return children[0]; } return children.length > 0 ? this.constructMenu('fa-calendar-alt', 'schedule', undefined, undefined, children) : null; } /** * Menu equipment */ equipmentMenu():ItemMenu | null { return this.constructMenu('fa-cube', 'equipment', '/equipment/list', true) } /** * Menu suivi pédagogique */ educationalMenu():ItemMenu | null { const children:ItemsMenu = []; if (this.$ability().can('display', 'criteria_notations_page')) { children.push(this.constructMenu('fa-bars', 'criteria_notations', '/criteria_notations/list/', true)) } if (this.$ability().can('display', 'seizure_period_page')) { children.push(this.constructMenu('fa-calendar-alt', 'seizure_period', '/education_teachers/list/', true)) } if (this.$ability().can('display', 'test_seizure_page')) { children.push(this.constructMenu('fa-pencil-alt', 'test_seizure', '/education_input/list/', true)) } if (this.$ability().can('display', 'test_validation_page')) { children.push(this.constructMenu('fa-check', 'test_validation', '/education_notations/list/', true)) } if (this.$ability().can('display', 'examen_results_page')) { children.push(this.constructMenu('fa-graduation-cap', 'examen_results', '/examen_convocations/list/', true)) } if (this.$ability().can('display', 'education_by_student_validation_page')) { children.push(this.constructMenu('fa-check-square', 'education_by_student_validation', '/education_by_student/list/', true)) } if(children.length === 1){ return children[0]; } return children.length > 0 ? this.constructMenu('fa-graduation-cap', 'education_state', undefined, undefined, children) : null; } /** * Construit un ItemMenu * @param icon * @param title * @param link * @param isOldLink * @param children */ constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array): ItemMenu{ return children ? { icon: icon, title: title, children: children, } : { icon: icon, title: title, to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`, old: isOldLink, } } }