Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from BlackMix/dashboard.js
Last active November 14, 2017 03:37
Show Gist options
  • Save wilcorrea/59bb86823a5cdb01be4cdc61bd7cf744 to your computer and use it in GitHub Desktop.
Save wilcorrea/59bb86823a5cdb01be4cdc61bd7cf744 to your computer and use it in GitHub Desktop.
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