Commit 2b65b828b416b8217e934bad85e1c71d28e32b40

Authored by isisadmin
1 parent ca817ac6

base datalet fix

datalets/base-datalet/base-datalet.html
... ... @@ -130,20 +130,6 @@ Example :
130 130 BaseDatalet = Polymer({
131 131 is: 'base-datalet',
132 132  
133   - objectDatalet: {
134   - /**
135   - * It contains the json data from async xhr call returned from core-ajax core component
136   - *
137   - * @attribute json_resultDatalet
138   - * @type object
139   - * @default 'null'.
140   - */
141   - json_resultDatalet: {
142   - type: Object,
143   - value: {}
144   - }
145   - },
146   -
147 133 hideFooter: function() {
148 134 this.$.base_datalet_container.innerHTML = "";
149 135 this.$.base_datalet_container.style.border = 0;
... ... @@ -167,12 +153,8 @@ Example :
167 153 },
168 154  
169 155 ready: function(){
170   -
171 156 if(this.dataUrl != undefined) {
172 157  
173   - //cKan organized with or not catalog
174   - var queryInitial = this.dataUrl.substring(0, this.dataUrl.indexOf("api")); //SOURCE
175   -
176 158 var urlSource = this.dataUrl.split("/")[0] + "//" + this.dataUrl.split("/")[2];
177 159 this.$.base_datalet_source.innerHTML = urlSource;
178 160 this.$.base_datalet_source.setAttribute("href", urlSource);
... ... @@ -181,101 +163,29 @@ Example :
181 163 //OpenDataSoft check
182 164 if(this.dataUrl.indexOf("/records/") > -1 )
183 165 {
184   - //Resourceid of a datalet
185   - var query = this.dataUrl.substring(this.dataUrl.indexOf("?"), this.dataUrl.length);
186   - var params = this.decomponeQueryString(query);
187   - var resultIssyIdDatalet = params["dataset"];
188   - var resultIssyAPI = "explore/dataset/";
189   - var urlPageDatasetIssy = queryInitial + resultIssyAPI + resultIssyIdDatalet + "/";
190   -
191   - this.$.base_datalet_link.setAttribute("href", urlPageDatasetIssy);
  166 + this.$.base_datalet_link.setAttribute("href", urlSource + "/explore/dataset/" + this.dataUrl.substring(this.dataUrl.indexOf("=")+1,this.dataUrl.indexOf("&")));
192 167 }
193   - else
  168 + // CKAN
  169 + else if(this.dataUrl.indexOf("datastore_search?resource_id") > -1 )
194 170 {
195   - //CKAN portal
196   - var urlDatalet;
197   -
198   - var apiIdResource = "resource_show?id=";
199   -
200   - //Resourceid of a datalet
201   - var query = this.dataUrl.substring(this.dataUrl.indexOf("?"), this.dataUrl.length);
202   - var params = this.decomponeQueryString(query);
203   - //CKAN
204   - var resultIdDatalet = params["resource_id"];
205   -
206   - //cKan organized with or not catalog
207   - var queryFinal = this.dataUrl.substring(this.dataUrl.indexOf("api"), this.dataUrl.indexOf("datastore_search"));
208   -
209   - urlDatalet = queryInitial + queryFinal + apiIdResource + resultIdDatalet;
210   - this.requestDataletData(urlDatalet);
  171 + var comp = this;
  172 + $.ajax({
  173 + url: this.dataUrl.replace("datastore_search?resource_id", "resource_show?id"),
  174 + dataType: "json",
  175 + success: function(e){
  176 + comp.$.base_datalet_link.setAttribute("href", urlSource + "/dataset/" + e.result.package_id + "/resource/" + e.result.id);
  177 + }
  178 + });
211 179 }
212 180 }
213   -
214 181 },
  182 +
215 183 /**
216 184 * Set the domain url to show in the footer
217 185 */
218 186 setDomain: function(url){
219 187 this.$.domain.textContent = url;
220 188 },
221   - /**
222   - * Get the (key, value) query string parameters
223   - **/
224   - decomponeQueryString: function (querystring) {
225   - // remove any preceding url and split
226   - querystring = querystring.substring(querystring.indexOf('?')+1).split('&');
227   - var params = {}, pair, d = decodeURIComponent;
228   - // march and parse
229   - for (var i = querystring.length - 1; i >= 0; i--) {
230   - pair = querystring[i].split('=');
231   - params[d(pair[0])] = d(pair[1]);
232   - }
233   - return params;
234   - },
235   - /**
236   - * Make an AJAX call to the dataset URL to retrieve package_id
237   - *
238   - * @method urlDatalet
239   - */
240   - requestDataletData: function(urlDatalet){
241   - var comp = this;
242   - $.ajax({
243   - url: urlDatalet, //url con package
244   - dataType: "json",
245   - success: function(e){
246   - comp.handleDataletResponse(e);
247   - }
248   - });
249   - },
250   - /**
251   - * Called when core-ajax component receive the json data from called url.
252   - *
253   - * @method handleResponse
254   - */
255   - handleDataletResponse: function(e) {
256   - this.objectDatalet.json_resultDatalet.value = e;
257   - //packageId of a give datalet
258   - packageIdDatalet = this.objectDatalet.json_resultDatalet.value.result.package_id;
259   - resourceId = this.objectDatalet.json_resultDatalet.value.result.id;
260   -
261   - //url complete of download
262   - urlDatasetDownload = this.objectDatalet.json_resultDatalet.value.result.url;
263   -
264   - if(this.dataUrl != undefined){
265   - //static url
266   - lastStringResourceId = this.dataUrl.split("/")[5];
267   - resourceId = lastStringResourceId.split('=')[1];
268   - var urlDatalet = this.dataUrl.split("/")[0]+ "//" + this.dataUrl.split("/")[2] + "/dataset/" + packageIdDatalet +"/resource/" +resourceId;
269   -
270   - urlDatalet = urlDatasetDownload.replace(/\/download\/.*/, '');
271   - urlSource = this.dataUrl.split("/")[0] + "//" + this.dataUrl.split("/")[2];
272   -
273   - this.$.base_datalet_link.setAttribute("href", urlDatalet);
274   - }
275   - },
276   -
277   -
278   -
279   - });
  189 + });
280 190 </script>
281 191 </dom-module>
282 192 \ No newline at end of file
... ...