Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -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 | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | angular.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 Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 44 | controller: function($scope, $timeout, SlicesPlus, Instances, _){ |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 45 | |
| 46 | this.instancePerSliceConfig = { |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 47 | data: [], |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 48 | groupBy: 'slice', |
| 49 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 50 | classes: 'instance per slice', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 51 | labelFormatter: (labels) => { |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 52 | return labels.map(l => { |
| 53 | return _.find(this.slices, {id: parseInt(l)}).name |
| 54 | }); |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 55 | } |
| 56 | }; |
| 57 | |
| 58 | this.instancePerSiteConfig = { |
| 59 | data: [], |
| 60 | groupBy: 'site', |
| 61 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 62 | classes: 'instance per site', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | this.networkPerSliceConfig = { |
| 66 | data: [], |
| 67 | groupBy: 'name', |
| 68 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 69 | classes: 'network per slice', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 70 | }; |
| 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 Scandolo | f51fb7c | 2016-05-09 16:24:34 -0700 | [diff] [blame] | 89 | label: 'Active Instances per Sites', |
| 90 | type: 'object', |
| 91 | prop: 'instance_distribution_ready' |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 92 | }, |
| 93 | { |
Matteo Scandolo | b873bf0 | 2016-05-10 15:05:10 -0700 | [diff] [blame] | 94 | label: 'Total Instances per Sites', |
| 95 | type: 'object', |
| 96 | prop: 'instance_distribution' |
| 97 | }, |
| 98 | { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 99 | label: 'Networks', |
| 100 | type: 'custom', |
| 101 | formatter: item => item.networks.length |
| 102 | } |
| 103 | ] |
| 104 | }; |
| 105 | |
| 106 | // retrieving user list |
| 107 | SlicesPlus.query().$promise |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 108 | .then((slices) => { |
| 109 | this.slices = slices; |
| 110 | return Instances.query().$promise |
| 111 | }) |
| 112 | .then(instances => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 113 | |
Matteo Scandolo | fd4ab86 | 2016-05-09 15:58:49 -0700 | [diff] [blame] | 114 | // formatting data in this way sucks. |
| 115 | // Provide a way to just pass data to the chart if needed [smartPie]. |
| 116 | |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 117 | // retrieving network per slices |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 118 | let networkPerSlice = _.reduce(this.slices, (list, s) => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 119 | 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 Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 132 | let instancePerSite = _.reduce(this.slices, (list, s) => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 133 | _.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 Scandolo | fd4ab86 | 2016-05-09 15:58:49 -0700 | [diff] [blame] | 141 | this.sites = Object.keys(_.groupBy(instancePerSite, 'site')); |
| 142 | |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 143 | this.instancePerSliceConfig.data = instances; |
| 144 | this.instancePerSiteConfig.data = instancePerSite; |
| 145 | this.networkPerSliceConfig.data = networkPerSlice; |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 146 | |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 147 | }) |
| 148 | .catch((e) => { |
| 149 | throw new Error(e); |
| 150 | }); |
| 151 | } |
| 152 | }; |
| 153 | }); |