Commit 0314f4874a2479cde280033375f237f07fe04fa8

Authored by Renato De Donato
1 parent e94f9513

filters opendatasoft

controllets/datalet-selection-controllet/demo/index.html
... ... @@ -19,6 +19,7 @@
19 19 <body>
20 20  
21 21 <datalet-selection-controllet fields='["result,records,Anno","result,records,Cinesi","result,records,Albanesi","result,records,Rumeni","result,records,Pakistani","result,records,Marocchini","result,records,Altri stranieri" ]' data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=e04338cf-7a92-4221-81c6-fe12f41003d5" deep-url="http://172.16.15.38/DEEalerProvider/DEEP/" datalets-list-url="http://172.16.15.38/DEEalerProvider/DEEP/datalets-list"></datalet-selection-controllet>
  22 +<!--<datalet-selection-controllet fields='["records,fields,title", "records,fields,published"]' data-url="https://data.issy.com/api/records/1.0/search?dataset=flux-rss-des-offres-demplois-a-issy-les-moulineaux&sort=published&facet=published&refine.published=2015%2F10" deep-url="http://172.16.15.38/DEEalerProvider/DEEP/" datalets-list-url="http://172.16.15.38/DEEalerProvider/DEEP/datalets-list"></datalet-selection-controllet>-->
22 23  
23 24 </body>
24 25  
... ...
controllets/select-data-controllet/demo/index.html
... ... @@ -16,8 +16,8 @@
16 16 <body>
17 17  
18 18 <!--<select-data-controllet id="tvmt" root-name="data" opened-path="records,geometry" preselected-fields='["nhits", "records,datasetid", "records,recordid"]' data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&limit=5"></select-data-controllet>-->
19   - <!--<select-data-controllet id="tvmt" root-name="data" data-url="https://data.issy.com/api/records/1.0/search?dataset=flux-rss-des-offres-demplois-a-issy-les-moulineaux&sort=published&facet=published&refine.published=2015%2F10"></select-data-controllet>-->
20   - <select-data-controllet id="tvmt" root-name="data" data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&limit=5"></select-data-controllet>
  19 + <select-data-controllet id="tvmt" root-name="data" data-url="https://data.issy.com/api/records/1.0/search?dataset=flux-rss-des-offres-demplois-a-issy-les-moulineaux&sort=published&facet=published&refine.published=2015%2F10"></select-data-controllet>
  20 + <!--<select-data-controllet id="tvmt" root-name="data" data-url="http://ckan.routetopa.eu/api/action/datastore_search?resource_id=73e02092-85a1-434e-85fe-0c9a43aa9a52&limit=5"></select-data-controllet>-->
21 21  
22 22 <script>
23 23 ln["localization"] = "en";
... ...
controllets/select-data-controllet/select-data-controllet.html
... ... @@ -152,11 +152,19 @@
152 152 },
153 153  
154 154 _filterJson : function(data){
  155 + //ckan
155 156 if(data.result != undefined && data.result.resource_id != undefined) {
156 157 this.rootName = "result,records"
157 158 return data.result.records;
158 159 }
159   - return data;
  160 + //openDataSoft
  161 + else if(data.parameters != undefined && data.parameters.dataset != undefined) {
  162 + this.rootName = "records,fields";
  163 + return data.records[0].fields;
  164 + }
  165 + else{
  166 + return data;
  167 + }
160 168 },
161 169  
162 170 _updateSelectedFields : function() {
... ...
controllets/tree-view-controllet/tree-view-controllet.html
... ... @@ -135,7 +135,7 @@
135 135 list.push(this._createTree(nodeName+","+child, node[0][child]));
136 136 else
137 137 for(var child in node)
138   - list.push(this._createTree(child, node[child]));
  138 + list.push(this._createTree(nodeName+","+child, node[child]));
139 139  
140 140 return this._paper_submenu(nodeName, list);
141 141 },
... ...
datalets/barchart-datalet/barchart-datalet.html
... ... @@ -74,13 +74,13 @@ Example:
74 74 xAxis: {
75 75 categories: this.properties.categories.value,
76 76 title: {
77   - text: this._component.xAxisLabel
  77 + text: this._component.yAxisLabel
78 78 }
79 79 },
80 80 yAxis: {
81 81 min: 0,
82 82 title: {
83   - text: this._component.yAxisLabel,
  83 + text: this._component.xAxisLabel,
84 84 align: 'high'
85 85 },
86 86 labels: {
... ...
datalets/base-ajax-json-alasql-datalet/static/js/AjaxJsonAlasqlBehavior.js
... ... @@ -87,57 +87,76 @@ var AjaxJsonAlasqlBehavior = {
87 87  
88 88 this._component.fields = JSON.parse(this._component.fields);
89 89  
90   - var fields = [];
91   - for (var i=0; i < this._component.fields.length; i++){
92   - fields.push("["+this._fieldName(this._component.fields[i])+"]");
93   - }
  90 + var provider = this._getProvider(this._component.fields[0]);
94 91  
95   - //console.log(fields);
96   -
97   - var path = this._path(this._component.fields[0]);
98 92 var filters = JSON.parse(this._component.getAttribute("filters"));
99 93 var aggregators = JSON.parse(this._component.getAttribute("aggregators"));
100 94 var orders = JSON.parse(this._component.getAttribute("orders"));
101 95  
  96 + var path = this._path(this._component.fields[0], provider);
  97 +
  98 + var fields = [];
  99 + for (var i=0; i < this._component.fields.length; i++)
  100 + fields.push(this._fieldName(this._component.fields[i], provider));
  101 +
  102 +
  103 +
102 104 //WHERE
103 105 var where = "";
104 106 if(filters && filters.length) {
  107 +
  108 + for (var i=0; i < filters.length; i++)
  109 + filters[i]["field"] = this._fieldName(filters[i]["field"], provider);
  110 +
105 111 where = "WHERE ";
106 112 for (var i=0; i < filters.length; i++) {
107 113 if(filters[i]["operation"] == "contains")
108   - where += "[" + filters[i]["field"] + "] like '%" + filters[i]["value"] + "%' AND ";
  114 + where += filters[i]["field"] + " like '%" + filters[i]["value"] + "%' AND ";
109 115 else if(filters[i]["operation"] == "start")
110   - where += "[" + filters[i]["field"] + "] like '" + filters[i]["value"] + "%' AND ";
  116 + where += filters[i]["field"] + " like '" + filters[i]["value"] + "%' AND ";
111 117 else if(filters[i]["operation"] == "ends")
112   - where += "[" + filters[i]["field"] + "] like '%" + filters[i]["value"] + "' AND ";
  118 + where += filters[i]["field"] + " like '%" + filters[i]["value"] + "' AND ";
113 119 else
114   - where += "[" + filters[i]["field"] + "] " + filters[i]["operation"] + " " + filters[i]["value"] + " AND ";
  120 + where += filters[i]["field"] + " " + filters[i]["operation"] + " " + filters[i]["value"] + " AND ";
115 121 }
116 122 where = where.slice(0, -5);
117 123 }
118 124  
  125 + provider="";
  126 +
119 127 //ORDER BY
120 128 var orderBy = "";
121 129 if(orders && orders.length) {
  130 +
  131 + for (var i=0; i < orders.length; i++)
  132 + orders[i]["field"] = this._fieldName(orders[i]["field"], provider);
  133 +
122 134 orderBy = "ORDER BY ";
123 135 for (var i = 0; i < orders.length; i++)
124   - orderBy += "[" + orders[i]["field"] + "] " + orders[i]["operation"] + ", ";
  136 + orderBy += orders[i]["field"] + " " + orders[i]["operation"] + ", ";
125 137 orderBy = orderBy.slice(0, -2);
126 138 }
127 139  
128 140 //SELECT;
129 141 var select = "SELECT ";
130 142 for (var i = 0; i < fields.length; i++)
131   - select += fields[i] + ", ";
  143 + //select += fields[i] + ", ";
  144 + select += fields[i] + " as " + this._fieldName(this._component.fields[i], "") + ", ";
132 145 select = select.slice(0, -2);
133 146  
  147 + var pureSelect = select;
  148 +
134 149 //GROUP BY
135 150 var groupBy = "";
136 151 if(aggregators && aggregators.length) {
137   - groupBy = "GROUP BY [" + aggregators[0]["field"] + "]";
138   - select = "SELECT [" + aggregators[0]["field"] + "]";
  152 +
  153 + for (var i=0; i < aggregators.length; i++)
  154 + aggregators[i]["field"] = this._fieldName(aggregators[i]["field"], provider);
  155 +
  156 + groupBy = "GROUP BY " + aggregators[0]["field"];
  157 + select = "SELECT " + aggregators[0]["field"];
139 158 for (var i = 1; i < aggregators.length; i++)
140   - select += ", " + aggregators[i]["operation"] + "([" + aggregators[i]["field"] + "]) as [" + aggregators[i]["field"] + "]";
  159 + select += ", " + aggregators[i]["operation"] + "(" + aggregators[i]["field"] + ") as " + aggregators[i]["field"];
141 160 }
142 161  
143 162 //QUERY
... ... @@ -146,14 +165,22 @@ var AjaxJsonAlasqlBehavior = {
146 165  
147 166 var records = res[0][path];
148 167  
149   - console.log(select + ' FROM ? ' + where + ' ' + groupBy + ' ' + orderBy + '');
150   - var obj = alasql(select + " FROM ? " + where + " " + groupBy + " " + orderBy + "", [records]);
  168 + //console.log(select + ' FROM ? ' + where + ' ' + groupBy + ' ' + orderBy + '');
  169 + //var obj = alasql(select + " FROM ? " + where + " " + groupBy + " " + orderBy + "", [records]);
151 170  
152   - //var query = "SELECT [Lat], COUNT([Lng]) as Lng FROM ? GROUP BY [Lat] ORDER BY Lng";
153   - //console.log(query);
154   - //var obj = alasql(query, [records]);
  171 + console.log(pureSelect + ' FROM ? ' + where);
  172 + var obj = alasql(pureSelect + " FROM ? " + where, [records]);
155 173  
156   - this._pushData(obj);
  174 + if (groupBy != "") {
  175 + console.log(select + ' FROM ? ' + groupBy + ' ' + orderBy + '');
  176 + var obj = alasql(select + " FROM ? " + groupBy + " " + orderBy + "", [obj]);
  177 + }
  178 +
  179 + //PUSH DATA
  180 + if(!obj || obj.length == 0)
  181 + this.data = []
  182 + else
  183 + this._pushData(obj);
157 184  
158 185 this._deleteWaitImage();
159 186 },
... ... @@ -182,12 +209,37 @@ var AjaxJsonAlasqlBehavior = {
182 209 }
183 210 },
184 211  
185   - _fieldName : function(field) {
186   - return field.substring(field.lastIndexOf(",")+1, field.length);
  212 + _getProvider : function(field) {
  213 + if(field.indexOf("result,records") > -1)
  214 + return "ckan";
  215 + else if(field.indexOf("records,fields") > -1)
  216 + return "openDataSoft";
  217 + else
  218 + return "provider";
187 219 },
188 220  
189   - _path : function(field) {
190   - return field.substring(0, field.lastIndexOf(",")).replace(",", "->");
  221 + _fieldName : function(field, provider) {
  222 + if(provider.indexOf("ckan") > -1) {
  223 + return "[" + field.substring(field.lastIndexOf(",") + 1, field.length) + "]";
  224 + }
  225 + else if(provider.indexOf("openDataSoft") > -1) {
  226 + return "fields->["+field.substring(field.lastIndexOf(",")+1, field.length)+"]";
  227 + }
  228 + else {
  229 + return "["+field.substring(field.lastIndexOf(",")+1, field.length)+"]";
  230 + }
  231 + },
  232 +
  233 + _path : function(field, provider) {
  234 + if(provider.indexOf("ckan") > -1) {
  235 + return "result->records"
  236 + }
  237 + else if(provider.indexOf("openDataSoft") > -1) {
  238 + return "records";
  239 + }
  240 + else {
  241 + return field.substring(0, field.lastIndexOf(",")).replace(",", "->");
  242 + }
191 243 },
192 244  
193 245 /**
... ...