blob: e343ddadb26ccf33393a3368ee868e0698dfcd17 [file] [log] [blame]
Matteo Scandolo86f3f282016-08-11 11:21:33 -07001(function () {
2 'use strict';
3 angular.module('xos.UITutorial')
Matteo Scandoloef969922016-08-11 13:49:12 -07004 .service('ResponseHandler', function(TemplateHandler){
5
6 const exclude = [
7 'deleted',
8 'enabled',
9 'enacted',
10 'exposed_ports',
11 'lazy_blocked',
12 'created',
13 'validators',
14 'controllers',
15 'backend_status',
16 'backend_register',
17 'policed',
18 'no_policy',
19 'write_protect',
20 'no_sync',
21 'updated'
22 ];
23
24 this.parseObject = (obj, comma = '') => {
25 obj = _.omit(obj, exclude);
26 return TemplateHandler.jsonObject({'obj': obj, comma: comma});
27 };
28
29 this.parseCollection = (array) => {
30 array = array.map((o, i) => `${this.parseObject(o, i === (array.length - 1) ? '':',')}`);
31 return TemplateHandler.jsonCollection({'collection': array});
32 };
33
34 this.parse = (res, jsCode, done) => {
35 if(_.isArray(res)) {
36 res = this.parseCollection(res);
Matteo Scandolo86f3f282016-08-11 11:21:33 -070037 }
Matteo Scandoloef969922016-08-11 13:49:12 -070038 else{
39 res = this.parseObject(res);
40 }
41 done(TemplateHandler.resourcesResponse({
42 jsCode: jsCode,
43 res: res
44 }));
Matteo Scandolo86f3f282016-08-11 11:21:33 -070045 };
46 });
47})();