-
-
Save wilcorrea/59bb86823a5cdb01be4cdc61bd7cf744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { get } from 'lodash' | |
import { get as _get } from 'genesis/infra/storage' | |
import store from 'genesis/infra/store/index' | |
import { APP_USER } from 'genesis/support/index' | |
import menu from 'src/bootstrap/menus/drawer' | |
import options from 'src/bootstrap/menus/options' | |
import configurePath from 'src/bootstrap/configure/path' | |
const user = _get(APP_USER) | |
/** | |
* @param {Vue} $component | |
*/ | |
export default ($component) => { | |
const items = menu(configurePath) | |
if (!Array.isArray(items)) { | |
return false | |
} | |
const drawer = items.reduce(reduce, []) | |
store.dispatch('setAppMenu', drawer) | |
store.dispatch('setDashboardOptions', options()) | |
} | |
/** | |
* @param {Array} accumulate | |
* @param {Object} menu | |
* @returns {Array} | |
*/ | |
const reduce = (accumulate, menu) => { | |
if (menu.children) { | |
menu.children = menu.children.reduce(reduce, []) | |
} | |
if (!menu.namespace) { | |
accumulate.push(menu) | |
} | |
else if (get(user.permissions, menu.namespace, false)) { | |
accumulate.push(menu) | |
} | |
return accumulate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment