blob: f35508a5b1eee23c59448bf739494b4a1ca8025b [file] [log] [blame]
Matteo Scandolo46b56102015-12-16 14:23:08 -08001angular.module('autoscaling')
Matteo Scandolo4d7ee392015-12-16 16:23:18 -08002.directive('serviceContainer', function(lodash, Autoscaling){
Matteo Scandolo46b56102015-12-16 14:23:08 -08003 return {
4 restrict: 'E',
5 scope: {},
6 bindToController: true,
7 controllerAs: 'vm',
8 templateUrl: 'templates/service-container.tpl.html',
Matteo Scandolo4d7ee392015-12-16 16:23:18 -08009 controller: function($rootScope) {
10 Autoscaling.getAutoscalingData();
Matteo Scandolo8942e042015-12-16 14:41:21 -080011 $rootScope.$on('autoscaling.update', (evt, data) => {
Matteo Scandolo4d7ee392015-12-16 16:23:18 -080012 this.printData(data);
Matteo Scandolo8942e042015-12-16 14:41:21 -080013 });
Matteo Scandolo4d7ee392015-12-16 16:23:18 -080014
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 Scandolo46b56102015-12-16 14:23:08 -080038 }
39 };
40});