blob: 5cb919b052c86c20f93b0d97b5dd9e034fce26f3 [file] [log] [blame]
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -07001'use strict';
2
3angular.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 Scandolo62c62d62016-05-10 14:56:58 -070026 controller: function($scope, $timeout, SlicesPlus, Instances, _){
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070027
28 this.instancePerSliceConfig = {
Matteo Scandolo62c62d62016-05-10 14:56:58 -070029 data: [],
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070030 groupBy: 'slice',
31 legend: true,
Matteo Scandolo62c62d62016-05-10 14:56:58 -070032 classes: 'instance per slice',
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070033 labelFormatter: (labels) => {
Matteo Scandolo62c62d62016-05-10 14:56:58 -070034 return labels.map(l => {
35 return _.find(this.slices, {id: parseInt(l)}).name
36 });
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070037 }
38 };
39
40 this.instancePerSiteConfig = {
41 data: [],
42 groupBy: 'site',
43 legend: true,
Matteo Scandolo62c62d62016-05-10 14:56:58 -070044 classes: 'instance per site',
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070045 };
46
47 this.networkPerSliceConfig = {
48 data: [],
49 groupBy: 'name',
50 legend: true,
Matteo Scandolo62c62d62016-05-10 14:56:58 -070051 classes: 'network per slice',
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070052 };
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 Scandolo2a49c052016-05-09 16:24:34 -070071 label: 'Total Instances per Sites',
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070072 type: 'object',
73 prop: 'instance_distribution'
Matteo Scandolo2a49c052016-05-09 16:24:34 -070074 },
75 {
76 label: 'Active Instances per Sites',
77 type: 'object',
78 prop: 'instance_distribution_ready'
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070079 },
80 {
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 Scandolo62c62d62016-05-10 14:56:58 -070090 .then((slices) => {
91 this.slices = slices;
92 return Instances.query().$promise
93 })
94 .then(instances => {
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070095
Matteo Scandolo89be3072016-05-09 15:58:49 -070096 // formatting data in this way sucks.
97 // Provide a way to just pass data to the chart if needed [smartPie].
98
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -070099 // retrieving network per slices
Matteo Scandolo62c62d62016-05-10 14:56:58 -0700100 let networkPerSlice = _.reduce(this.slices, (list, s) => {
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -0700101 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 Scandolo62c62d62016-05-10 14:56:58 -0700114 let instancePerSite = _.reduce(this.slices, (list, s) => {
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -0700115 _.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 Scandolo89be3072016-05-09 15:58:49 -0700123 this.sites = Object.keys(_.groupBy(instancePerSite, 'site'));
124
Matteo Scandolo62c62d62016-05-10 14:56:58 -0700125 this.instancePerSliceConfig.data = instances;
126 this.instancePerSiteConfig.data = instancePerSite;
127 this.networkPerSliceConfig.data = networkPerSlice;
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -0700128
Matteo Scandolob4fdd0a2016-05-09 15:27:47 -0700129 })
130 .catch((e) => {
131 throw new Error(e);
132 });
133 }
134 };
135});