Added child routes, and config defined routes
Change-Id: I61c5a49a330a63737312d1eb6077aab02236a44f
diff --git a/src/app/core/services/navigation.ts b/src/app/core/services/navigation.ts
index 04eb575..c840878 100644
--- a/src/app/core/services/navigation.ts
+++ b/src/app/core/services/navigation.ts
@@ -1,7 +1,15 @@
+/// <reference path="../../../../typings/index.d.ts" />
+
+import * as _ from 'lodash';
+import {StyleConfig} from '../../config/style.config';
+
export interface IXosNavigationRoute {
label: string;
state?: string;
url?: string;
+ parent?: string;
+ children?: [IXosNavigationRoute];
+ opened?: boolean;
}
export interface IXosNavigationService {
@@ -13,12 +21,18 @@
private routes: IXosNavigationRoute[];
constructor() {
- this.routes = [
+ const defaultRoutes = [
+ {
+ label: 'Core',
+ state: 'xos.core'
+ },
{
label: 'Home',
state: 'xos.dashboard'
}
];
+ // adding configuration defined routes
+ this.routes = StyleConfig.routes.concat(defaultRoutes).reverse();
}
query() {
@@ -29,6 +43,21 @@
if (angular.isDefined(route.state) && angular.isDefined(route.url)) {
throw new Error('[XosNavigation] You can\'t provide both state and url');
}
- this.routes.push(route);
+
+
+ if (angular.isDefined(route.parent)) {
+ // route parent should be a state for now
+ const parentRoute = _.find(this.routes, {state: route.parent});
+
+ if (angular.isArray(parentRoute.children)) {
+ parentRoute.children.push(route);
+ }
+ else {
+ parentRoute.children = [route];
+ }
+ }
+ else {
+ this.routes.push(route);
+ }
}
}