Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.developer', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('developer', { |
| 12 | url: '/', |
| 13 | template: '<developer-dashboard></developer-dashboard>' |
| 14 | }); |
| 15 | }) |
| 16 | .config(function($httpProvider){ |
| 17 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 18 | }) |
| 19 | .directive('developerDashboard', function(){ |
| 20 | return { |
| 21 | restrict: 'E', |
| 22 | scope: {}, |
| 23 | bindToController: true, |
| 24 | controllerAs: 'vm', |
| 25 | templateUrl: 'templates/developer-dashboard.tpl.html', |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 26 | controller: function($scope, $timeout, SlicesPlus, Instances, _){ |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 27 | |
| 28 | this.instancePerSliceConfig = { |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 29 | data: [], |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 30 | groupBy: 'slice', |
| 31 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 32 | classes: 'instance per slice', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 33 | labelFormatter: (labels) => { |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 34 | return labels.map(l => { |
| 35 | return _.find(this.slices, {id: parseInt(l)}).name |
| 36 | }); |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 37 | } |
| 38 | }; |
| 39 | |
| 40 | this.instancePerSiteConfig = { |
| 41 | data: [], |
| 42 | groupBy: 'site', |
| 43 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 44 | classes: 'instance per site', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | this.networkPerSliceConfig = { |
| 48 | data: [], |
| 49 | groupBy: 'name', |
| 50 | legend: true, |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 51 | classes: 'network per slice', |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | this.tableConfig = { |
| 55 | columns: [ |
| 56 | { |
| 57 | label: 'Name', |
| 58 | prop: 'name' |
| 59 | }, |
| 60 | { |
| 61 | label: 'Privileges', |
| 62 | prop: 'current_user_roles', |
| 63 | type: 'array' |
| 64 | }, |
| 65 | { |
| 66 | label: 'Number of Instances (active / total)', |
| 67 | type: 'custom', |
| 68 | formatter: item => `${item.instance_total_ready} / ${item.instance_total}` |
| 69 | }, |
| 70 | { |
Matteo Scandolo | f51fb7c | 2016-05-09 16:24:34 -0700 | [diff] [blame] | 71 | label: 'Active Instances per Sites', |
| 72 | type: 'object', |
| 73 | prop: 'instance_distribution_ready' |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 74 | }, |
| 75 | { |
Matteo Scandolo | b873bf0 | 2016-05-10 15:05:10 -0700 | [diff] [blame] | 76 | label: 'Total Instances per Sites', |
| 77 | type: 'object', |
| 78 | prop: 'instance_distribution' |
| 79 | }, |
| 80 | { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 81 | label: 'Networks', |
| 82 | type: 'custom', |
| 83 | formatter: item => item.networks.length |
| 84 | } |
| 85 | ] |
| 86 | }; |
| 87 | |
| 88 | // retrieving user list |
| 89 | SlicesPlus.query().$promise |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 90 | .then((slices) => { |
| 91 | this.slices = slices; |
| 92 | return Instances.query().$promise |
| 93 | }) |
| 94 | .then(instances => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 95 | |
Matteo Scandolo | fd4ab86 | 2016-05-09 15:58:49 -0700 | [diff] [blame] | 96 | // formatting data in this way sucks. |
| 97 | // Provide a way to just pass data to the chart if needed [smartPie]. |
| 98 | |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 99 | // retrieving network per slices |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 100 | let networkPerSlice = _.reduce(this.slices, (list, s) => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 101 | if( s.networks.length > 1){ |
| 102 | // push s.neworks.length values in array |
| 103 | for(let i = 0; i < s.networks.length; i++){ |
| 104 | list.push({id: s.id, name: s.name, network: s.networks[i]}) |
| 105 | } |
| 106 | } |
| 107 | else if ( s.networks.length === 1){ |
| 108 | list.push({id: s.id, name: s.name, network: s.networks[0]}); |
| 109 | } |
| 110 | return list; |
| 111 | }, []); |
| 112 | |
| 113 | // retrieving instance distribution across sites |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 114 | let instancePerSite = _.reduce(this.slices, (list, s) => { |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 115 | _.forEach(Object.keys(s.instance_distribution), k => { |
| 116 | for(let i = 0; i < s.instance_distribution[k]; i++){ |
| 117 | list.push({site: k, instance: i}) |
| 118 | } |
| 119 | }) |
| 120 | return list; |
| 121 | }, []); |
| 122 | |
Matteo Scandolo | fd4ab86 | 2016-05-09 15:58:49 -0700 | [diff] [blame] | 123 | this.sites = Object.keys(_.groupBy(instancePerSite, 'site')); |
| 124 | |
Matteo Scandolo | e967656 | 2016-05-10 14:56:58 -0700 | [diff] [blame] | 125 | this.instancePerSliceConfig.data = instances; |
| 126 | this.instancePerSiteConfig.data = instancePerSite; |
| 127 | this.networkPerSliceConfig.data = networkPerSlice; |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 128 | |
Matteo Scandolo | a7ad499 | 2016-05-09 15:27:47 -0700 | [diff] [blame] | 129 | }) |
| 130 | .catch((e) => { |
| 131 | throw new Error(e); |
| 132 | }); |
| 133 | } |
| 134 | }; |
| 135 | }); |