blob: 31dca575b62d4d71a2013332bd57f5ba0528751f [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -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 Scandoloa7ad4992016-05-09 15:27:47 -070019'use strict';
20
21angular.module('xos.developer', [
22 'ngResource',
23 'ngCookies',
24 'ui.router',
25 'xos.helpers'
26])
27.config(($stateProvider) => {
28 $stateProvider
29 .state('developer', {
30 url: '/',
31 template: '<developer-dashboard></developer-dashboard>'
32 });
33})
34.config(function($httpProvider){
35 $httpProvider.interceptors.push('NoHyperlinks');
36})
37.directive('developerDashboard', function(){
38 return {
39 restrict: 'E',
40 scope: {},
41 bindToController: true,
42 controllerAs: 'vm',
43 templateUrl: 'templates/developer-dashboard.tpl.html',
Matteo Scandoloe9676562016-05-10 14:56:58 -070044 controller: function($scope, $timeout, SlicesPlus, Instances, _){
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070045
46 this.instancePerSliceConfig = {
Matteo Scandoloe9676562016-05-10 14:56:58 -070047 data: [],
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070048 groupBy: 'slice',
49 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070050 classes: 'instance per slice',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070051 labelFormatter: (labels) => {
Matteo Scandoloe9676562016-05-10 14:56:58 -070052 return labels.map(l => {
53 return _.find(this.slices, {id: parseInt(l)}).name
54 });
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070055 }
56 };
57
58 this.instancePerSiteConfig = {
59 data: [],
60 groupBy: 'site',
61 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070062 classes: 'instance per site',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070063 };
64
65 this.networkPerSliceConfig = {
66 data: [],
67 groupBy: 'name',
68 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070069 classes: 'network per slice',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070070 };
71
72 this.tableConfig = {
73 columns: [
74 {
75 label: 'Name',
76 prop: 'name'
77 },
78 {
79 label: 'Privileges',
80 prop: 'current_user_roles',
81 type: 'array'
82 },
83 {
84 label: 'Number of Instances (active / total)',
85 type: 'custom',
86 formatter: item => `${item.instance_total_ready} / ${item.instance_total}`
87 },
88 {
Matteo Scandolof51fb7c2016-05-09 16:24:34 -070089 label: 'Active Instances per Sites',
90 type: 'object',
91 prop: 'instance_distribution_ready'
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070092 },
93 {
Matteo Scandolob873bf02016-05-10 15:05:10 -070094 label: 'Total Instances per Sites',
95 type: 'object',
96 prop: 'instance_distribution'
97 },
98 {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070099 label: 'Networks',
100 type: 'custom',
101 formatter: item => item.networks.length
102 }
103 ]
104 };
105
106 // retrieving user list
107 SlicesPlus.query().$promise
Matteo Scandoloe9676562016-05-10 14:56:58 -0700108 .then((slices) => {
109 this.slices = slices;
110 return Instances.query().$promise
111 })
112 .then(instances => {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700113
Matteo Scandolofd4ab862016-05-09 15:58:49 -0700114 // formatting data in this way sucks.
115 // Provide a way to just pass data to the chart if needed [smartPie].
116
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700117 // retrieving network per slices
Matteo Scandoloe9676562016-05-10 14:56:58 -0700118 let networkPerSlice = _.reduce(this.slices, (list, s) => {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700119 if( s.networks.length > 1){
120 // push s.neworks.length values in array
121 for(let i = 0; i < s.networks.length; i++){
122 list.push({id: s.id, name: s.name, network: s.networks[i]})
123 }
124 }
125 else if ( s.networks.length === 1){
126 list.push({id: s.id, name: s.name, network: s.networks[0]});
127 }
128 return list;
129 }, []);
130
131 // retrieving instance distribution across sites
Matteo Scandoloe9676562016-05-10 14:56:58 -0700132 let instancePerSite = _.reduce(this.slices, (list, s) => {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700133 _.forEach(Object.keys(s.instance_distribution), k => {
134 for(let i = 0; i < s.instance_distribution[k]; i++){
135 list.push({site: k, instance: i})
136 }
137 })
138 return list;
139 }, []);
140
Matteo Scandolofd4ab862016-05-09 15:58:49 -0700141 this.sites = Object.keys(_.groupBy(instancePerSite, 'site'));
142
Matteo Scandoloe9676562016-05-10 14:56:58 -0700143 this.instancePerSliceConfig.data = instances;
144 this.instancePerSiteConfig.data = instancePerSite;
145 this.networkPerSliceConfig.data = networkPerSlice;
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700146
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700147 })
148 .catch((e) => {
149 throw new Error(e);
150 });
151 }
152 };
153});