blob: 15b9118fee8649add24ecbe01442ae6fb24e52f3 [file] [log] [blame]
Matteo Scandolo8942e042015-12-16 14:41:21 -08001'use strict';
2
3angular.module('autoscaling')
Matteo Scandolo4d7ee392015-12-16 16:23:18 -08004.service('Autoscaling', function($http, $interval, $rootScope, lodash){
Matteo Scandolo8942e042015-12-16 14:41:21 -08005
Matteo Scandolo4d7ee392015-12-16 16:23:18 -08006 const pollingFrequency = 10;
Matteo Scandolo8942e042015-12-16 14:41:21 -08007 var pollinginterval;
8
Matteo Scandolo4d7ee392015-12-16 16:23:18 -08009 /**
10 * Convert data to a flat array of resources
11 */
12
13 this.formatData = (data) => {
14 const list = [];
15 // cicle trough all slices
16 lodash.map(data, (item) => {
17 // cicle trough every resource
18 item.resources = lodash.forEach(
19 Object.keys(item.resources),
20 (resource) => {
21 const tmp = item.resources[resource];
22 tmp.service = item.service;
23 tmp.slice = item.slice;
24 tmp.project_id = item.project_id;
25 tmp.instance_name = tmp.xos_instance_info.instance_name;
26 delete tmp.xos_instance_info;
27 list.push(tmp);
28 }
29 )
30 });
31 return list;
32 };
33
Matteo Scandolo8942e042015-12-16 14:41:21 -080034 this.getAutoscalingData = () => {
Matteo Scandolo4d7ee392015-12-16 16:23:18 -080035 // pollinginterval = $interval(() => {
36 // $http.get('/autoscaledata')
37 $http.get('../mocks/mock.json')
38 .success((res) => {
39 $rootScope.$emit('autoscaling.update', this.formatData(res));
Matteo Scandolo8942e042015-12-16 14:41:21 -080040 });
Matteo Scandolo4d7ee392015-12-16 16:23:18 -080041 // }, pollingFrequency * 1000)
Matteo Scandolo8942e042015-12-16 14:41:21 -080042 };
43});