mirror of https://github.com/akveo/blur-admin
Sidebar is built once
parent
f89cdf0916
commit
4e9ba8ab4e
|
@ -7,6 +7,7 @@
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function baSidebarServiceProvider() {
|
function baSidebarServiceProvider() {
|
||||||
var staticMenuItems = [];
|
var staticMenuItems = [];
|
||||||
|
var menuItems = [];
|
||||||
|
|
||||||
this.addStaticItem = function() {
|
this.addStaticItem = function() {
|
||||||
staticMenuItems.push.apply(staticMenuItems, arguments);
|
staticMenuItems.push.apply(staticMenuItems, arguments);
|
||||||
|
@ -19,20 +20,15 @@
|
||||||
function _factory() {
|
function _factory() {
|
||||||
var isMenuCollapsed = shouldMenuBeCollapsed();
|
var isMenuCollapsed = shouldMenuBeCollapsed();
|
||||||
|
|
||||||
this.getMenuItems = function() {
|
this.getMenuItems = function () {
|
||||||
var states = defineMenuItemStates();
|
if (!menuItems.length) {
|
||||||
var menuItems = states.filter(function(item) {
|
menuItems = createMenu();
|
||||||
return item.level == 0;
|
}
|
||||||
});
|
return menuItems;
|
||||||
|
};
|
||||||
|
|
||||||
menuItems.forEach(function(item) {
|
this.addMenuItem = function(item) {
|
||||||
var children = states.filter(function(child) {
|
menuItems.push(item);
|
||||||
return child.level == 1 && child.name.indexOf(item.name) === 0;
|
|
||||||
});
|
|
||||||
item.subMenu = children.length ? children : null;
|
|
||||||
});
|
|
||||||
|
|
||||||
return menuItems.concat(staticMenuItems);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.shouldMenuBeCollapsed = shouldMenuBeCollapsed;
|
this.shouldMenuBeCollapsed = shouldMenuBeCollapsed;
|
||||||
|
@ -63,6 +59,32 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function createMenu() {
|
||||||
|
var parentLevel = 0;
|
||||||
|
var states = defineMenuItemStates();
|
||||||
|
var parents = states.filter(function(item) {
|
||||||
|
return item.level == parentLevel;
|
||||||
|
});
|
||||||
|
|
||||||
|
bindMenuItems(parents, ++parentLevel);
|
||||||
|
return parents.concat(staticMenuItems);
|
||||||
|
|
||||||
|
function bindMenuItems(parents, childLevel) {
|
||||||
|
var child = states.filter(function (item) {
|
||||||
|
return item.level == childLevel;
|
||||||
|
});
|
||||||
|
if (child.length) {
|
||||||
|
parents.forEach(function (p) {
|
||||||
|
var children = child.filter(function (c) {
|
||||||
|
return c.name.indexOf(p.name) === 0;
|
||||||
|
});
|
||||||
|
p.subMenu = children.length ? children : null;
|
||||||
|
});
|
||||||
|
bindMenuItems(child, ++childLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function defineMenuItemStates() {
|
function defineMenuItemStates() {
|
||||||
return $state.get()
|
return $state.get()
|
||||||
.filter(function(s) {
|
.filter(function(s) {
|
||||||
|
|
Loading…
Reference in New Issue