blob: b09f1ef7cd378cb945bd0ef27370fafa64505f06 [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 Scandoloe9676562016-05-10 14:56:58 -070026 controller: function($scope, $timeout, SlicesPlus, Instances, _){
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070027
28 this.instancePerSliceConfig = {
Matteo Scandoloe9676562016-05-10 14:56:58 -070029 data: [],
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070030 groupBy: 'slice',
31 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070032 classes: 'instance per slice',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070033 labelFormatter: (labels) => {
Matteo Scandoloe9676562016-05-10 14:56:58 -070034 return labels.map(l => {
35 return _.find(this.slices, {id: parseInt(l)}).name
36 });
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070037 }
38 };
39
40 this.instancePerSiteConfig = {
41 data: [],
42 groupBy: 'site',
43 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070044 classes: 'instance per site',
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070045 };
46
47 this.networkPerSliceConfig = {
48 data: [],
49 groupBy: 'name',
50 legend: true,
Matteo Scandoloe9676562016-05-10 14:56:58 -070051 classes: 'network per slice',
Matteo Scandoloa7ad4992016-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 Scandolof51fb7c2016-05-09 16:24:34 -070071 label: 'Active Instances per Sites',
72 type: 'object',
73 prop: 'instance_distribution_ready'
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070074 },
75 {
Matteo Scandolob873bf02016-05-10 15:05:10 -070076 label: 'Total Instances per Sites',
77 type: 'object',
78 prop: 'instance_distribution'
79 },
80 {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070081 label: 'Networks',
82 type: 'custom',
83 formatter: item => item.networks.length
84 }
85 ]
86 };
87
88 // retrieving user list
89 SlicesPlus.query().$promise
Matteo Scandoloe9676562016-05-10 14:56:58 -070090 .then((slices) => {
91 this.slices = slices;
92 return Instances.query().$promise
93 })
94 .then(instances => {
Matteo Scandoloa7ad4992016-05-09 15:27:47 -070095
Matteo Scandolofd4ab862016-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 Scandoloa7ad4992016-05-09 15:27:47 -070099 // retrieving network per slices
Matteo Scandoloe9676562016-05-10 14:56:58 -0700100 let networkPerSlice = _.reduce(this.slices, (list, s) => {
Matteo Scandoloa7ad4992016-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 Scandoloe9676562016-05-10 14:56:58 -0700114 let instancePerSite = _.reduce(this.slices, (list, s) => {
Matteo Scandoloa7ad4992016-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 Scandolofd4ab862016-05-09 15:58:49 -0700123 this.sites = Object.keys(_.groupBy(instancePerSite, 'site'));
124
Matteo Scandoloe9676562016-05-10 14:56:58 -0700125 this.instancePerSliceConfig.data = instances;
126 this.instancePerSiteConfig.data = instancePerSite;
127 this.networkPerSliceConfig.data = networkPerSlice;
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700128
Matteo Scandoloa7ad4992016-05-09 15:27:47 -0700129 })
130 .catch((e) => {
131 throw new Error(e);
132 });
133 }
134 };
135});