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 { |
| 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 Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 20 | this.store.query('node') |
| 21 | .subscribe((event) => this.nodes = event.length); |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 22 | this.store.query('slice') |
Matteo Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 23 | .subscribe((event) => this.slices = event.length); |
| 24 | this.store.query('instance') |
| 25 | .subscribe((event) => this.instances = event.length); |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 26 | this.instances = 0; |
Matteo Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 27 | this.nodes = 0; |
| 28 | this.slices = 0; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | export const xosDashboard: angular.IComponentOptions = { |
| 34 | template: require('./dashboard.html'), |
| 35 | controllerAs: 'vm', |
| 36 | controller: DashboardController |
| 37 | }; |