Commit b9c8df012e34b42771d3d4902b2cf933f1809111

Authored by isisadmin
1 parent 349fcb7c

client refactoring

js/deepClient.js
... ... @@ -14,19 +14,7 @@ var ComponentService =
14 14 if(request.readyState == 4){
15 15 try {
16 16 var resp = JSON.parse(request.response);
17   - var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link + '">';
18   - //Build jsonPath query string
19   - var query = "";
20   - for(var i=0;i < params.fields.length;i++){
21   - var query_elements = params.fields[i].split(',');
22   - query += "$";
23   - for(var j=0; j < query_elements.length - 1;j++){
24   - query += "['" + query_elements[j] + "']";
25   - }
26   - query += "[*]" + "['" + query_elements[query_elements.length - 1] + "']";
27   - query += "###";
28   - }
29   - query = query.substring(0, query.length - 3);
  17 + var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link +'">';
30 18  
31 19 //Build datalet injecting html code
32 20 var datalet_code = link + '<' + params.component;
... ... @@ -34,7 +22,7 @@ var ComponentService =
34 22 for(var i = 0; i < keys.length; i++){
35 23 datalet_code += ' ' + keys[i] + '="' + params.params[keys[i]] +'"';
36 24 }
37   - datalet_code += ' query="' + query + '"></' + params.component + '>';
  25 + datalet_code += " fields='" + JSON.stringify(params.fields) + "'></" + params.component + ">";
38 26  
39 27 (params.placeHolder.constructor == HTMLElement || params.placeHolder.constructor == HTMLDivElement) ? $(params.placeHolder).html(datalet_code) :/*Injection from Web Component*/
40 28 $("#" + params.placeHolder).html(datalet_code);/*Injection from a static web page*/
... ...
js/deepClient_old.js
... ... @@ -4,28 +4,40 @@
4 4  
5 5 var ComponentService =
6 6 {
7   - deep_url:"",
8   - data:"",
9   - query:"",
10   - component:"",
11   - link:"",
  7 + deep_url:"",
  8 +
12 9 getComponent: function(params){//params = {component, data, fields, placeHolder}
13 10 var request = this.getXMLHttpRequest();
14   - this.component = params.component;
15   - this.data = params.data;
  11 + var component = params.component;
16 12  
17 13 request.onreadystatechange = function(){
18 14 if(request.readyState == 4){
19 15 try {
20 16 var resp = JSON.parse(request.response);
21   - this.link = '<link rel="import" href="' + resp.bridge_link + resp.component_link + '">';
22   - this.query = "";
23   - for(i=0;i < params.fields.length;i++){
24   - this.query += "$.result.records.." + params.fields[i] + " ";
  17 + var link = '<link rel="import" href="' + resp.bridge_link + resp.component_link +'">';
  18 + //Build jsonPath query string
  19 + var query = "";
  20 + for(var i=0;i < params.fields.length;i++){
  21 + var query_elements = params.fields[i].split(',');
  22 + query += "$";
  23 + for(var j=0; j < query_elements.length - 1;j++){
  24 + query += "['" + query_elements[j] + "']";
  25 + }
  26 + query += "[*]" + "['" + query_elements[query_elements.length - 1] + "']";
  27 + query += "###";
  28 + }
  29 + query = query.substring(0, query.length - 3);
  30 +
  31 + //Build datalet injecting html code
  32 + var datalet_code = link + '<' + params.component;
  33 + var keys = Object.keys(params.params);
  34 + for(var i = 0; i < keys.length; i++){
  35 + datalet_code += ' ' + keys[i] + '="' + params.params[keys[i]] +'"';
25 36 }
26   - this.query = this.query.substring(0, this.query.length - 1);
  37 + datalet_code += ' query="' + query + '"></' + params.component + '>';
27 38  
28   - $('#' + params.placeHolder).append(this.link + '<' + params.component + ' data-url="' + params.data +'" query="' + this.query +'"></' + params.component + '>');
  39 + (params.placeHolder.constructor == HTMLElement || params.placeHolder.constructor == HTMLDivElement) ? $(params.placeHolder).html(datalet_code) :/*Injection from Web Component*/
  40 + $("#" + params.placeHolder).html(datalet_code);/*Injection from a static web page*/
29 41  
30 42 } catch (e){
31 43 var resp = {
... ... @@ -35,7 +47,7 @@ var ComponentService =
35 47 }
36 48 }};
37 49  
38   - request.open('GET', this.deep_url + this.component);
  50 + request.open('GET', this.deep_url + component);
39 51 request.send();
40 52 },
41 53  
... ...
js/jquery-2.1.0.min.js 100644 → 100755