import CisMenuEntry from "./Menu/Entry.js"; import FhcSearchbar from "../searchbar/searchbar.js"; import CisSprachen from "./Sprachen.js"; import ApiCisMenu from '../../api/factory/cis/menu.js'; export default { components: { CisMenuEntry, FhcSearchbar, CisSprachen, }, props: { rootUrl: String, logoUrl: String, avatarUrl: String, logoutUrl: String, selectedtypes: Array, searchbaroptions: Object, searchfunction: Function }, data: () => { return { entries: [], activeEntry:null, url:null, urlMatchRankings:[], navUserDropdown:null, }; }, provide(){ return{ setActiveEntry: this.setActiveEntry, addUrlCount: this.addUrlCount, makeParentContentActive: this.makeParentContentActive, } }, computed:{ highestMatchingUrlCount(){ // gets the hightest ranking inside the array let highestMatch = Math.max(...this.urlMatchRankings); if(this.urlMatchRankings.length > 0){ // if more than one entry has the same ranking, none should be active return this.urlMatchRankings.filter((value)=>value == highestMatch).length > 1 ? null : highestMatch; } return null; }, site_url(){ return FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router; } }, methods: { fetchMenu() { return this.$api .call(ApiCisMenu.getMenu()) .then(res => res.data) .then(menu => { this.entries = menu; }); }, checkSettingsVisibility: function (event) { // hides the settings collapsible if the user clicks somewhere else if (!this.$refs.navUserDropdown.contains(event.target)) { this.navUserDropdown.hide(); } }, handleShowNavUser(){ document.addEventListener("click", this.checkSettingsVisibility); }, handleHideNavUser(){ document.removeEventListener("click", this.checkSettingsVisibility); }, makeParentContentActive(content_id, collection=this.entries, parent=null){ if(!collection) return; if (typeof collection == 'object' && !Array.isArray(collection) && Object.entries(collection).length > 0) { collection = Object.values(collection); } for(let entry of collection){ if(entry.content_id == content_id){ this.activeEntry = parent; } this.makeParentContentActive(content_id, entry.childs, entry.content_id); } }, addUrlCount(count){ this.urlMatchRankings.push(count); }, setActiveEntry(content_id){ this.activeEntry = content_id; }, }, created(){ this.fetchMenu(); }, mounted(){ this.$p.loadCategory(['ui', 'global']) this.navUserDropdown = new bootstrap.Collapse(this.$refs.navUserDropdown,{ toggle: false }); }, template: /*html*/` ` };