blob: 72d7f28353b53646efcd1c69594d6eeb88c3a13a [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 {
Matteo Scandolo231de262017-01-04 16:33:14 -08004 static $inject = ['$scope', '$state', 'ModelStore', 'AuthService'];
Matteo Scandolod62ea792016-12-22 14:02:28 -08005
6 public nodes: number;
7 public slices: number;
8 public instances: number;
9
10 constructor(
Matteo Scandolo231de262017-01-04 16:33:14 -080011 private $scope: ng.IScope,
Matteo Scandolod62ea792016-12-22 14:02:28 -080012 private $state: ng.ui.IStateService,
13 private store: IModelStoreService,
14 private auth: IXosAuthService
15 ) {
16
17 if (!this.auth.isAuthenticated()) {
18 this.$state.go('login');
19 }
20 else {
Matteo Scandolo231de262017-01-04 16:33:14 -080021 this.store.query('Node')
22 .subscribe((event) => {
23 this.$scope.$evalAsync(() => {
24 this.nodes = event.length;
25 });
26 });
27 this.store.query('Instance')
28 .subscribe((event) => {
29 this.$scope.$evalAsync(() => {
30 this.instances = event.length;
31 });
32 });
33 this.store.query('Slice')
34 .subscribe((event) => {
35 this.$scope.$evalAsync(() => {
36 this.slices = event.length;
37 });
38 });
Matteo Scandolod62ea792016-12-22 14:02:28 -080039 this.instances = 0;
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080040 this.nodes = 0;
41 this.slices = 0;
Matteo Scandolod62ea792016-12-22 14:02:28 -080042 }
43 }
44}
45
46export const xosDashboard: angular.IComponentOptions = {
47 template: require('./dashboard.html'),
48 controllerAs: 'vm',
49 controller: DashboardController
50};