| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- import {ref, useContext} from "@nuxtjs/composition-api";
- import {ItemMenu, ItemsMenu} from "~/types/types";
- import {$organizationProfile} from "~/services/profile/organizationProfile";
- /**
- * @category Use/template
- * @class Menu
- * Use Classe pour la construction du Menu
- */
- class Menu{
- private $ability:any;
- private $config:any;
- private $store:any;
- /**
- * @constructor
- * Initialisation des services issues du context
- */
- constructor() {
- }
- setUpContext(){
- const {$ability, $config, store} = useContext();
- this.$ability = $ability;
- this.$config = $config;
- this.$store = store;
- return this;
- }
- /**
- * Construit le menu
- */
- 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)
- const billingMenu = this.billingMenu()
- if(billingMenu) menu.push(billingMenu)
- return ref(menu)
- }
- /**
- * Construit le menu Répertoire ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- 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;
- }
- /**
- * Construit le menu Agenda ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- 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;
- }
- /**
- * Construit le menu Equipement ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- equipmentMenu():ItemMenu | null {
- return this.constructMenu('fa-cube', 'equipment', '/equipment/list', true)
- }
- /**
- * Construit le menu Suivi pédagogique ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- 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 le menu Facturation ou null si aucune page accessible
- * @return {ItemMenu | null}
- */
- billingMenu():ItemMenu | null {
- const children:ItemsMenu = [];
- if (this.$ability().can('display', 'billing_product_page')) {
- children.push(this.constructMenu('fa-cube', 'billing_product', '/intangibles/list/', true))
- }
- if (this.$ability().can('display', 'billing_products_by_student_page')) {
- children.push(this.constructMenu('fa-cubes', 'billing_products_by_student', '/access_intangibles/list/', true))
- }
- if (this.$ability().can('display', 'billing_edition_page')) {
- children.push(this.constructMenu('fa-copy', 'billing_edition', '/billing_edition', true))
- }
- if (this.$ability().can('display', 'billing_accounting_page')) {
- children.push(this.constructMenu('fa-file-alt', 'billing_accounting', '/bill_accountings/list/', true))
- }
- if (this.$ability().can('display', 'billing_payment_list_page')) {
- children.push(this.constructMenu('fa-credit-card', 'billing_payment_list', '/bill_payments_list/list/', true))
- }
- if (this.$ability().can('display', 'pes_page')) {
- children.push(this.constructMenu('fa-align-justify', 'pes_export', '/pes/list/', true))
- }
- if (this.$ability().can('display', 'berger_levrault_page')) {
- children.push(this.constructMenu('fa-align-justify', 'berger_levrault_export', '/berger_levraults/list/', true))
- }
- if (this.$ability().can('display', 'jvs_page')) {
- children.push(this.constructMenu('fa-align-justify', 'jvs_export', '/jvs/list/', true))
- }
- if(children.length === 1){
- return children[0];
- }
- return children.length > 0 ? this.constructMenu('fa-euro-sign', 'billing', undefined, undefined, children) : null;
- }
- /**
- * Construit un ItemMenu
- * @param {string} icon
- * @param {string} title titre qui sera traduit
- * @param {string} link lien
- * @param {boolean} isOldLink est-ce un lien renvoyant vers l'ancien admin ?
- * @param {Array<ItemMenu>} children Tableau d'ItemMenu représentant les sous menu du menu principal
- * @return {ItemMenu}
- */
- constructMenu(icon: string, title: string, link?: string, isOldLink?: boolean, children?: Array<ItemMenu>): ItemMenu{
- return children ? {
- icon: icon,
- title: title,
- children: children,
- } : {
- icon: icon,
- title: title,
- to: `${isOldLink ? this.$config.baseURL_adminLegacy : ''}${link}`,
- old: isOldLink,
- }
- }
- }
- export const $useMenu = new Menu()
|