Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | 47860fe | 2017-02-02 12:05:55 -0800 | [diff] [blame] | 19 | import {IXosModelStoreService} from '../../datasources/stores/model.store'; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 20 | import {IXosAuthService} from '../../datasources/rest/auth.rest'; |
| 21 | class DashboardController { |
Matteo Scandolo | 1aee198 | 2017-02-17 08:33:23 -0800 | [diff] [blame] | 22 | static $inject = ['$scope', '$state', 'XosModelStore', 'AuthService']; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 23 | |
| 24 | public nodes: number; |
| 25 | public slices: number; |
| 26 | public instances: number; |
| 27 | |
| 28 | constructor( |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 29 | private $scope: ng.IScope, |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 30 | private $state: ng.ui.IStateService, |
Matteo Scandolo | 47860fe | 2017-02-02 12:05:55 -0800 | [diff] [blame] | 31 | private store: IXosModelStoreService, |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 32 | private auth: IXosAuthService |
| 33 | ) { |
| 34 | |
| 35 | if (!this.auth.isAuthenticated()) { |
| 36 | this.$state.go('login'); |
| 37 | } |
| 38 | else { |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 39 | this.store.query('Node') |
| 40 | .subscribe((event) => { |
| 41 | this.$scope.$evalAsync(() => { |
| 42 | this.nodes = event.length; |
| 43 | }); |
| 44 | }); |
| 45 | this.store.query('Instance') |
| 46 | .subscribe((event) => { |
| 47 | this.$scope.$evalAsync(() => { |
| 48 | this.instances = event.length; |
| 49 | }); |
| 50 | }); |
| 51 | this.store.query('Slice') |
| 52 | .subscribe((event) => { |
| 53 | this.$scope.$evalAsync(() => { |
| 54 | this.slices = event.length; |
| 55 | }); |
| 56 | }); |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 57 | this.instances = 0; |
Matteo Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 58 | this.nodes = 0; |
| 59 | this.slices = 0; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export const xosDashboard: angular.IComponentOptions = { |
| 65 | template: require('./dashboard.html'), |
| 66 | controllerAs: 'vm', |
| 67 | controller: DashboardController |
| 68 | }; |