blob: 45bd138297d0bd8f1c0d56c05de572f3bbb4be5f [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';
21class DashboardController {
Matteo Scandolo1aee1982017-02-17 08:33:23 -080022 static $inject = ['$scope', '$state', 'XosModelStore', 'AuthService'];
Matteo Scandolod62ea792016-12-22 14:02:28 -080023
24 public nodes: number;
25 public slices: number;
26 public instances: number;
27
28 constructor(
Matteo Scandolo231de262017-01-04 16:33:14 -080029 private $scope: ng.IScope,
Matteo Scandolod62ea792016-12-22 14:02:28 -080030 private $state: ng.ui.IStateService,
Matteo Scandolo47860fe2017-02-02 12:05:55 -080031 private store: IXosModelStoreService,
Matteo Scandolod62ea792016-12-22 14:02:28 -080032 private auth: IXosAuthService
33 ) {
34
35 if (!this.auth.isAuthenticated()) {
36 this.$state.go('login');
37 }
38 else {
Matteo Scandolo231de262017-01-04 16:33:14 -080039 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 Scandolod62ea792016-12-22 14:02:28 -080057 this.instances = 0;
Matteo Scandolof9dd4d02016-12-22 15:17:01 -080058 this.nodes = 0;
59 this.slices = 0;
Matteo Scandolod62ea792016-12-22 14:02:28 -080060 }
61 }
62}
63
64export const xosDashboard: angular.IComponentOptions = {
65 template: require('./dashboard.html'),
66 controllerAs: 'vm',
67 controller: DashboardController
68};