Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 1 | import {IModelStoreService} from '../../datasources/stores/model.store'; |
| 2 | import {IXosAuthService} from '../../datasources/rest/auth.rest'; |
| 3 | class DashboardController { |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 4 | static $inject = ['$scope', '$state', 'ModelStore', 'AuthService']; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 5 | |
| 6 | public nodes: number; |
| 7 | public slices: number; |
| 8 | public instances: number; |
| 9 | |
| 10 | constructor( |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 11 | private $scope: ng.IScope, |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 12 | 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 Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 21 | 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 Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 39 | this.instances = 0; |
Matteo Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 40 | this.nodes = 0; |
| 41 | this.slices = 0; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | export const xosDashboard: angular.IComponentOptions = { |
| 47 | template: require('./dashboard.html'), |
| 48 | controllerAs: 'vm', |
| 49 | controller: DashboardController |
| 50 | }; |