blob: 285c2df12757e3f1cd64c52318f4623d54672cd5 [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
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 Scandolo47860fe2017-02-02 12:05:55 -080019import {IXosModelStoreService} from '../../datasources/stores/model.store';
Matteo Scandolod62ea792016-12-22 14:02:28 -080020import {IXosAuthService} from '../../datasources/rest/auth.rest';
Matteo Scandoloafd05d72017-10-11 17:09:27 -070021import {Subscription} from 'rxjs/Subscription';
22
23
Matteo Scandolod62ea792016-12-22 14:02:28 -080024class DashboardController {
Matteo Scandoloafd05d72017-10-11 17:09:27 -070025 static $inject = [
26 '$log',
27 '$scope',
28 '$state',
29 'XosModelStore',
30 'AuthService'
31 ];
Matteo Scandolod62ea792016-12-22 14:02:28 -080032
33 public nodes: number;
34 public slices: number;
35 public instances: number;
36
Matteo Scandoloafd05d72017-10-11 17:09:27 -070037 private nodeSubscription: Subscription;
38 private sliceSubscription: Subscription;
39 private instanceSubscription: Subscription;
40
Matteo Scandolod62ea792016-12-22 14:02:28 -080041 constructor(
Matteo Scandoloafd05d72017-10-11 17:09:27 -070042 private $log: ng.ILogService,
Matteo Scandolo231de262017-01-04 16:33:14 -080043 private $scope: ng.IScope,
Matteo Scandolod62ea792016-12-22 14:02:28 -080044 private $state: ng.ui.IStateService,
Matteo Scandolo47860fe2017-02-02 12:05:55 -080045 private store: IXosModelStoreService,
Matteo Scandolod62ea792016-12-22 14:02:28 -080046 private auth: IXosAuthService
47 ) {
48
Matteo Scandoloafd05d72017-10-11 17:09:27 -070049 this.$log.info(`[XosDashboardView] Setup`);
50
Matteo Scandolod62ea792016-12-22 14:02:28 -080051 if (!this.auth.isAuthenticated()) {
52 this.$state.go('login');
53 }
54 else {
Matteo Scandoloafd05d72017-10-11 17:09:27 -070055 this.nodeSubscription = this.store.query('Node')
Matteo Scandolo231de262017-01-04 16:33:14 -080056 .subscribe((event) => {
57 this.$scope.$evalAsync(() => {
58 this.nodes = event.length;
59 });
60 });
Matteo Scandoloafd05d72017-10-11 17:09:27 -070061 this.instanceSubscription = this.store.query('Instance')
Matteo Scandolo231de262017-01-04 16:33:14 -080062 .subscribe((event) => {
63 this.$scope.$evalAsync(() => {
64 this.instances = event.length;
65 });
66 });
Matteo Scandoloafd05d72017-10-11 17:09:27 -070067 this.sliceSubscription = this.store.query('Slice')
Matteo Scandolo231de262017-01-04 16:33:14 -080068 .subscribe((event) => {
69 this.$scope.$evalAsync(() => {
70 this.slices = event.length;
71 });
72 });
Matteo Scandolod62ea792016-12-22 14:02:28 -080073 this.instances = 0;
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080074 this.nodes = 0;
75 this.slices = 0;
Matteo Scandolod62ea792016-12-22 14:02:28 -080076 }
77 }
Matteo Scandoloafd05d72017-10-11 17:09:27 -070078
79 $onDestroy () {
80 this.nodeSubscription.unsubscribe();
81 this.instanceSubscription.unsubscribe();
82 this.sliceSubscription.unsubscribe();
83 }
Matteo Scandolod62ea792016-12-22 14:02:28 -080084}
85
86export const xosDashboard: angular.IComponentOptions = {
87 template: require('./dashboard.html'),
88 controllerAs: 'vm',
89 controller: DashboardController
90};