blob: edaeb244b6a8b3ff7ed53004c4cc314c816e3224 [file] [log] [blame]
import './nav.scss';
import {IXosNavigationService, IXosNavigationRoute} from '../services/navigation';
import {StyleConfig} from '../../config/style.config';
class NavCtrl {
static $inject = ['$scope', '$state', 'NavigationService'];
public routes: IXosNavigationRoute[];
public navSelected: string;
public appName: string;
constructor(
private $scope: ng.IScope,
private $state: angular.ui.IStateService,
private navigationService: IXosNavigationService
) {
// NOTE we'll need to have:
// - Base routes (defined from configuration based on BRAND)
// - Autogenerated routes (nested somewhere)
// - Service Routes (dynamically added)
this.routes = [];
this.$scope.$watch(() => this.navigationService.query(), (routes) => {
this.routes = routes;
});
this.appName = StyleConfig.projectName;
}
activateRoute(route: IXosNavigationRoute) {
this.navSelected = route.state;
}
includes(state: string): boolean {
return this.$state.includes(state);
}
isSelected(navId: string, navSelected: string) {
// TODO activate only one state
const activeRoute = this.$state.current.name;
const separateRoutes = activeRoute.split('.');
if (!navSelected) {
navSelected = separateRoutes[1];
}
if (navId === navSelected) {
return false;
}
else if (this.$state.current.name.indexOf(navId) === -1 && navId === navSelected ) {
return false;
}
else {
return true;
}
}
}
export const xosNav: angular.IComponentOptions = {
template: require('./nav.html'),
controllerAs: 'vm',
controller: NavCtrl
};