Matteo Scandolo | 7cd88ba | 2015-12-16 14:23:08 -0800 | [diff] [blame] | 1 | angular.module('autoscaling') |
Matteo Scandolo | eb1e53a | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 2 | .directive('serviceContainer', function(lodash, Autoscaling){ |
Matteo Scandolo | 7cd88ba | 2015-12-16 14:23:08 -0800 | [diff] [blame] | 3 | return { |
| 4 | restrict: 'E', |
| 5 | scope: {}, |
| 6 | bindToController: true, |
| 7 | controllerAs: 'vm', |
| 8 | templateUrl: 'templates/service-container.tpl.html', |
Matteo Scandolo | eb1e53a | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 9 | controller: function($rootScope) { |
| 10 | Autoscaling.getAutoscalingData(); |
Matteo Scandolo | 69adff8 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 11 | $rootScope.$on('autoscaling.update', (evt, data) => { |
Matteo Scandolo | eb1e53a | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 12 | this.printData(data); |
Matteo Scandolo | 69adff8 | 2015-12-16 14:41:21 -0800 | [diff] [blame] | 13 | }); |
Matteo Scandolo | eb1e53a | 2015-12-16 16:23:18 -0800 | [diff] [blame^] | 14 | |
| 15 | /** |
| 16 | * Group resources by service and slice |
| 17 | */ |
| 18 | |
| 19 | this.printData = (data) => { |
| 20 | this.services = lodash.groupBy(data, 'service'); |
| 21 | lodash.forEach(Object.keys(this.services), (service) => { |
| 22 | this.services[service] = lodash.groupBy(this.services[service], 'slice'); |
| 23 | lodash.forEach(Object.keys(this.services[service]), (slice) => { |
| 24 | // grouping instance by name |
| 25 | this.services[service][slice] = lodash.groupBy(this.services[service][slice], 'instance_name'); |
| 26 | // instance can't have the same name, |
| 27 | // so take them out of an array |
| 28 | // and keep only the sample data |
| 29 | lodash.forEach(Object.keys(this.services[service][slice]), (instance) => { |
| 30 | // console.log(this.services[service][slice][instance]); |
| 31 | this.services[service][slice][instance] = this.services[service][slice][instance][0].queue; |
| 32 | }); |
| 33 | |
| 34 | }) |
| 35 | }); |
| 36 | console.log(this.services); |
| 37 | }; |
Matteo Scandolo | 7cd88ba | 2015-12-16 14:23:08 -0800 | [diff] [blame] | 38 | } |
| 39 | }; |
| 40 | }); |