Dinamically generate views for CORE Models

Change-Id: Ib1d042f366f916c2ba8513ee62014e7256ceb53d
diff --git a/src/app/core/header/header.ts b/src/app/core/header/header.ts
index 140abff..c91ef5f 100644
--- a/src/app/core/header/header.ts
+++ b/src/app/core/header/header.ts
@@ -1,19 +1,20 @@
 import './header.scss';
 import {StyleConfig} from '../../config/style.config';
-import {IStoreService} from '../../datasources/stores/slices.store';
 import {IWSEvent} from '../../datasources/websocket/global';
+import {IStoreService} from '../../datasources/stores/synchronizer.store';
 
 interface INotification extends IWSEvent {
   viewed?: boolean;
 }
 
 class HeaderController {
-  static $inject = ['SynchronizerStore'];
+  static $inject = ['$scope', 'SynchronizerStore'];
   public title: string;
   public notifications: INotification[] = [];
   public newNotifications: INotification[] = [];
 
   constructor(
+    private $scope: angular.IScope,
     private syncStore: IStoreService
   ) {
     this.title = StyleConfig.projectName;
@@ -21,8 +22,10 @@
     this.syncStore.query()
       .subscribe(
         (event: IWSEvent) => {
-          this.notifications.unshift(event);
-          this.newNotifications = this.getNewNotifications(this.notifications);
+          $scope.$evalAsync(() => {
+            this.notifications.unshift(event);
+            this.newNotifications = this.getNewNotifications(this.notifications);
+          });
         }
       );
   }
diff --git a/src/app/core/index.ts b/src/app/core/index.ts
index ee73f99..270541b 100644
--- a/src/app/core/index.ts
+++ b/src/app/core/index.ts
@@ -4,12 +4,16 @@
 import routesConfig from './routes';
 import {xosLogin} from './login/login';
 import {xosTable} from './table/table';
+import {RuntimeStates} from './services/runtime-states';
+import {NavigationService} from './services/navigation';
 
 export const xosCore = 'xosCore';
 
 angular
   .module('xosCore', ['ui.router'])
   .config(routesConfig)
+  .provider('RuntimeStates', RuntimeStates)
+  .service('NavigationService', NavigationService)
   .component('xosHeader', xosHeader)
   .component('xosFooter', xosFooter)
   .component('xosNav', xosNav)
diff --git a/src/app/core/nav/nav.html b/src/app/core/nav/nav.html
index 6256369..2bcdadd 100644
--- a/src/app/core/nav/nav.html
+++ b/src/app/core/nav/nav.html
@@ -1,7 +1,8 @@
 <div class="nav">
   <ul>
-    <li ng-repeat="route in vm.routes" ui-sref-active="active">
-      <a ui-sref="{{route.state}}">{{route.label}}</a>
+    <li ng-repeat="route in vm.routes" ui-sref-active="active" ng-class="vm.isRouteActive(route)">
+      <a ng-if="route.state" ui-sref="{{route.state}}">{{route.label}}</a>
+      <a ng-if="route.url" href="#/{{route.url}}">{{route.label}}</a>
     </li>
   </ul>
 </div>
diff --git a/src/app/core/nav/nav.scss b/src/app/core/nav/nav.scss
index 8591c15..5c2c85c 100644
--- a/src/app/core/nav/nav.scss
+++ b/src/app/core/nav/nav.scss
@@ -2,8 +2,9 @@
   display: flex;
   flex: 1;
   flex-direction: column;
-  flex-basis: 10%;
+  flex-basis: 15%;
   background: darken(grey, 10);
+  overflow-y: scroll;
 
   ul {
     list-style: none;
diff --git a/src/app/core/nav/nav.ts b/src/app/core/nav/nav.ts
index 82d9d64..d83f859 100644
--- a/src/app/core/nav/nav.ts
+++ b/src/app/core/nav/nav.ts
@@ -1,32 +1,19 @@
 import './nav.scss';
-
-export interface INavItem {
-  label: string;
-  state: string;
-}
+import {IXosNavigationService, IXosNavigationRoute} from '../services/navigation';
 
 class NavCtrl {
-  public routes: INavItem[];
+  static $inject = ['$state', 'NavigationService'];
+  public routes: IXosNavigationRoute[];
 
-  constructor() {
-    this.routes = [
-      {
-        label: 'Home',
-        state: 'xos.dashboard'
-      },
-      {
-        label: 'Instances',
-        state: 'xos.instances'
-      },
-      {
-        label: 'Slices',
-        state: 'xos.slices'
-      },
-      {
-        label: 'Nodes',
-        state: 'xos.nodes'
-      }
-    ];
+  constructor(
+    private $state: angular.ui.IStateService,
+    private navigationService: IXosNavigationService
+  ) {
+    this.routes = this.navigationService.query();
+  }
+
+  isRouteActive(route: IXosNavigationRoute) {
+    return this.$state.current.url === route.url ? 'active' : '';
   }
 }
 
diff --git a/src/app/core/services/navigation.ts b/src/app/core/services/navigation.ts
new file mode 100644
index 0000000..8cb3b66
--- /dev/null
+++ b/src/app/core/services/navigation.ts
@@ -0,0 +1,31 @@
+export interface IXosNavigationRoute {
+  label: string;
+  state?: string;
+  url?: string;
+}
+
+export interface IXosNavigationService {
+  query(): IXosNavigationRoute[];
+  add(route: IXosNavigationRoute): void;
+}
+
+export class NavigationService {
+  private routes: IXosNavigationRoute[];
+
+  constructor() {
+    this.routes = [
+      {
+        label: 'Home',
+        state: 'xos.dashboard'
+      }
+    ];
+  }
+
+  query() {
+    return this.routes;
+  }
+
+  add(route: IXosNavigationRoute) {
+    this.routes.push(route);
+  }
+}
diff --git a/src/app/core/services/runtime-states.ts b/src/app/core/services/runtime-states.ts
new file mode 100644
index 0000000..401075a
--- /dev/null
+++ b/src/app/core/services/runtime-states.ts
@@ -0,0 +1,15 @@
+import {IXosState} from '../../../index';
+export interface IRuntimeStatesService {
+  addState(name: string, state: angular.ui.IState): void;
+}
+
+export function RuntimeStates($stateProvider: angular.ui.IStateProvider): angular.IServiceProvider {
+  this.$get = function($state: angular.ui.IStateService) { // for example
+    return {
+      addState: function(name: string, state: IXosState) {
+        $stateProvider.state(name, state);
+      }
+    };
+  };
+  return this;
+}
diff --git a/src/app/core/table/table.ts b/src/app/core/table/table.ts
index a837600..1d40092 100644
--- a/src/app/core/table/table.ts
+++ b/src/app/core/table/table.ts
@@ -11,7 +11,7 @@
 
 export interface IXosTableCfg {
   columns: any[];
-  order: IXosTableCgfOrder; // | boolean;
+  order?: IXosTableCgfOrder; // | boolean;
 }
 
 class TableCtrl {