blob: 21fbbde96263f41ea90cf8b3bf6e55bd86237edf [file] [log] [blame]
Matteo Scandolo47860fe2017-02-02 12:05:55 -08001import {IXosModelStoreService} from '../../datasources/stores/model.store';
Matteo Scandolod62ea792016-12-22 14:02:28 -08002import {IXosAuthService} from '../../datasources/rest/auth.rest';
3class DashboardController {
Matteo Scandolo1aee1982017-02-17 08:33:23 -08004 static $inject = ['$scope', '$state', 'XosModelStore', '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,
Matteo Scandolo47860fe2017-02-02 12:05:55 -080013 private store: IXosModelStoreService,
Matteo Scandolod62ea792016-12-22 14:02:28 -080014 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};