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'; |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 21 | import {Subscription} from 'rxjs/Subscription'; |
| 22 | |
| 23 | |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 24 | class DashboardController { |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 25 | static $inject = [ |
| 26 | '$log', |
| 27 | '$scope', |
| 28 | '$state', |
| 29 | 'XosModelStore', |
| 30 | 'AuthService' |
| 31 | ]; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 32 | |
| 33 | public nodes: number; |
| 34 | public slices: number; |
| 35 | public instances: number; |
| 36 | |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 37 | private nodeSubscription: Subscription; |
| 38 | private sliceSubscription: Subscription; |
| 39 | private instanceSubscription: Subscription; |
| 40 | |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 41 | constructor( |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 42 | private $log: ng.ILogService, |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 43 | private $scope: ng.IScope, |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 44 | private $state: ng.ui.IStateService, |
Matteo Scandolo | 47860fe | 2017-02-02 12:05:55 -0800 | [diff] [blame] | 45 | private store: IXosModelStoreService, |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 46 | private auth: IXosAuthService |
| 47 | ) { |
| 48 | |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 49 | this.$log.info(`[XosDashboardView] Setup`); |
| 50 | |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 51 | if (!this.auth.isAuthenticated()) { |
| 52 | this.$state.go('login'); |
| 53 | } |
| 54 | else { |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 55 | this.nodeSubscription = this.store.query('Node') |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 56 | .subscribe((event) => { |
| 57 | this.$scope.$evalAsync(() => { |
| 58 | this.nodes = event.length; |
| 59 | }); |
| 60 | }); |
Matteo Scandolo | 1a85b0f | 2019-03-13 15:52:48 -0700 | [diff] [blame] | 61 | this.instanceSubscription = this.store.query('ComputeServiceInstance') |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 62 | .subscribe((event) => { |
| 63 | this.$scope.$evalAsync(() => { |
| 64 | this.instances = event.length; |
| 65 | }); |
| 66 | }); |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 67 | this.sliceSubscription = this.store.query('Slice') |
Matteo Scandolo | 231de26 | 2017-01-04 16:33:14 -0800 | [diff] [blame] | 68 | .subscribe((event) => { |
| 69 | this.$scope.$evalAsync(() => { |
| 70 | this.slices = event.length; |
| 71 | }); |
| 72 | }); |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 73 | this.instances = 0; |
Matteo Scandolo | f9dd4d0 | 2016-12-22 15:17:01 -0800 | [diff] [blame] | 74 | this.nodes = 0; |
| 75 | this.slices = 0; |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 76 | } |
| 77 | } |
Matteo Scandolo | afd05d7 | 2017-10-11 17:09:27 -0700 | [diff] [blame] | 78 | |
| 79 | $onDestroy () { |
| 80 | this.nodeSubscription.unsubscribe(); |
| 81 | this.instanceSubscription.unsubscribe(); |
| 82 | this.sliceSubscription.unsubscribe(); |
| 83 | } |
Matteo Scandolo | d62ea79 | 2016-12-22 14:02:28 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | export const xosDashboard: angular.IComponentOptions = { |
| 87 | template: require('./dashboard.html'), |
| 88 | controllerAs: 'vm', |
| 89 | controller: DashboardController |
| 90 | }; |