-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsidebar.controller.js
46 lines (38 loc) · 1.19 KB
/
sidebar.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(function () {
'use strict';
angular
.module('app.layout')
.controller('SidebarController', SidebarController);
SidebarController.$inject = ['routerHelper', '$scope', '$rootScope'];
/* @ngInject */
function SidebarController (routerHelper, $scope, $rootScope) {
var vm = this;
vm.hideSidebar = hideSidebar;
init();
///////////////
function init () {
// generate sidebar nav menus
vm.navs = _getNavMenus();
// tell others we have sidebar
$rootScope.hasSidebar = true;
$scope.$on('$destroy', function () {
$rootScope.hasSidebar = false;
});
}
function hideSidebar () {
$rootScope.showSidebar = false;
}
function _getNavMenus () {
var navs = [];
var allStates = routerHelper.getStates();
allStates.forEach(function (state) {
if (state.sidebar) {
var nav = state.sidebar;
nav.link = state.name;
navs.push(nav);
}
});
return navs;
}
}
})();