(function(){ 'use strict'; angular.module('sbAdminApp').factory('navService', [ '$location', '$rootScope', function ($location, $rootScope) { var section = []; section.push({ name: 'Recommend a Startup', type: 'link', sref: '.user', role: ['user'], }); section.push({ name: 'Apply Late as Startup', type: 'link', sref: '.startUp', role: ['user'], }); var sections = []; for(var i = 0; i < section.length; i++) { if(section[i].role.indexOf($rootScope.userDetails.role) !== -1){ sections.push(section[i]); } } var self; return self = { sections: sections, toggleSelectSection: function (section) { self.openedSection = (self.openedSection === section ? null : section); }, isSectionSelected: function (section) { return self.openedSection === section; }, selectPage: function (section, page) { page && page.url && $location.path(page.url); self.currentSection = section; self.currentPage = page; } }; function sortByHumanName(a, b) { return (a.humanName < b.humanName) ? -1 : (a.humanName > b.humanName) ? 1 : 0; } }]) })();