blob: c4ddcd880e9ac9ca77dbd0a413a7c7f56ba6dea6 [file] [log] [blame]
Matteo Scandoloa7ad4992016-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 Scandolofd4ab862016-05-09 15:58:49 -070026 controller: function($timeout, SlicesPlus, _){
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070027
28 this.instancePerSliceConfig = {
29 resource: 'Instances',
30 groupBy: 'slice',
31 legend: true,
32 labelFormatter: (labels) => {
33 return labels.map(l => _.find(this.slices, {id: parseInt(l)}).name);
34 }
35 };
36
37 this.instancePerSiteConfig = {
38 data: [],
39 groupBy: 'site',
40 legend: true,
41 };
42
43 this.networkPerSliceConfig = {
44 data: [],
45 groupBy: 'name',
46 legend: true,
47 };
48
49 this.tableConfig = {
50 columns: [
51 {
52 label: 'Name',
53 prop: 'name'
54 },
55 {
56 label: 'Privileges',
57 prop: 'current_user_roles',
58 type: 'array'
59 },
60 {
61 label: 'Number of Instances (active / total)',
62 type: 'custom',
63 formatter: item => `${item.instance_total_ready} / ${item.instance_total}`
64 },
65 {
Matteo Scandolof51fb7c2016-05-09 16:24:34 -070066 label: 'Total Instances per Sites',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070067 type: 'object',
68 prop: 'instance_distribution'
Matteo Scandolof51fb7c2016-05-09 16:24:34 -070069 },
70 {
71 label: 'Active Instances per Sites',
72 type: 'object',
73 prop: 'instance_distribution_ready'
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070074 },
75 {
76 label: 'Networks',
77 type: 'custom',
78 formatter: item => item.networks.length
79 }
80 ]
81 };
82
83 // retrieving user list
84 SlicesPlus.query().$promise
85 .then(slices => {
86
Matteo Scandolofd4ab862016-05-09 15:58:49 -070087 // formatting data in this way sucks.
88 // Provide a way to just pass data to the chart if needed [smartPie].
89
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070090 // retrieving network per slices
91 let networkPerSlice = _.reduce(slices, (list, s) => {
92 if( s.networks.length > 1){
93 // push s.neworks.length values in array
94 for(let i = 0; i < s.networks.length; i++){
95 list.push({id: s.id, name: s.name, network: s.networks[i]})
96 }
97 }
98 else if ( s.networks.length === 1){
99 list.push({id: s.id, name: s.name, network: s.networks[0]});
100 }
101 return list;
102 }, []);
103
104 // retrieving instance distribution across sites
105 let instancePerSite = _.reduce(slices, (list, s) => {
106 _.forEach(Object.keys(s.instance_distribution), k => {
107 for(let i = 0; i < s.instance_distribution[k]; i++){
108 list.push({site: k, instance: i})
109 }
110 })
111 return list;
112 }, []);
113
Matteo Scandolofd4ab862016-05-09 15:58:49 -0700114 this.sites = Object.keys(_.groupBy(instancePerSite, 'site'));
115
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700116 $timeout(() => {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700117 this.instancePerSiteConfig.data = instancePerSite;
118 this.networkPerSliceConfig.data = networkPerSlice;
Matteo Scandolofd4ab862016-05-09 15:58:49 -0700119 }, 0);
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700120
121 this.slices = slices;
122 })
123 .catch((e) => {
124 throw new Error(e);
125 });
126 }
127 };
128});