blob: dc4fc1de00dd4b06d811ce80cde5d790cf1b05f8 [file] [log] [blame]
Matteo Scandolod62ea792016-12-22 14:02:28 -08001import {IModelStoreService} from '../../datasources/stores/model.store';
2import {IXosAuthService} from '../../datasources/rest/auth.rest';
3class DashboardController {
4 static $inject = ['$state', 'ModelStore', 'AuthService'];
5
6 public nodes: number;
7 public slices: number;
8 public instances: number;
9
10 constructor(
11 private $state: ng.ui.IStateService,
12 private store: IModelStoreService,
13 private auth: IXosAuthService
14 ) {
15
16 if (!this.auth.isAuthenticated()) {
17 this.$state.go('login');
18 }
19 else {
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080020 this.store.query('node')
21 .subscribe((event) => this.nodes = event.length);
Matteo Scandolod62ea792016-12-22 14:02:28 -080022 this.store.query('slice')
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080023 .subscribe((event) => this.slices = event.length);
24 this.store.query('instance')
25 .subscribe((event) => this.instances = event.length);
Matteo Scandolod62ea792016-12-22 14:02:28 -080026 this.instances = 0;
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080027 this.nodes = 0;
28 this.slices = 0;
Matteo Scandolod62ea792016-12-22 14:02:28 -080029 }
30 }
31}
32
33export const xosDashboard: angular.IComponentOptions = {
34 template: require('./dashboard.html'),
35 controllerAs: 'vm',
36 controller: DashboardController
37};