From a89b823f8d273711469cc63622f329598c067a7b Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 29 May 2021 15:22:20 +0200 Subject: [PATCH 1/2] [mod] remove overpass API call prepare the code the PR #90 --- searx/static/themes/oscar/js/searx.js | 83 ------------------ .../static/themes/oscar/src/js/leaflet_map.js | 83 ------------------ searx/static/themes/simple/js/searx.js | 87 ------------------- .../simple/js/searx_src/searx_mapresult.js | 87 ------------------- .../templates/oscar/result_templates/map.html | 13 --- .../simple/result_templates/map.html | 13 --- searx/webapp.py | 2 - 7 files changed, 368 deletions(-) diff --git a/searx/static/themes/oscar/js/searx.js b/searx/static/themes/oscar/js/searx.js index c377e4534..5c0350514 100644 --- a/searx/static/themes/oscar/js/searx.js +++ b/searx/static/themes/oscar/js/searx.js @@ -238,89 +238,6 @@ $(document).ready(function(){ */ $(document).ready(function(){ - $(".searx_overpass_request").on( "click", function( event ) { - var overpass_url = "https://overpass-api.de/api/interpreter?data="; - var query_start = overpass_url + "[out:json][timeout:25];("; - var query_end = ");out meta;"; - - var osm_id = $(this).data('osm-id'); - var osm_type = $(this).data('osm-type'); - var result_table = $(this).data('result-table'); - var result_table_loadicon = "#" + $(this).data('result-table-loadicon'); - - // tags which can be ignored - var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]; - - if(osm_id && osm_type && result_table) { - result_table = "#" + result_table; - var query = null; - switch(osm_type) { - case 'node': - query = query_start + "node(" + osm_id + ");" + query_end; - break; - case 'way': - query = query_start + "way(" + osm_id + ");" + query_end; - break; - case 'relation': - query = query_start + "relation(" + osm_id + ");" + query_end; - break; - default: - break; - } - if(query) { - //alert(query); - var ajaxRequest = $.ajax( query ) - .done(function( html) { - if(html && html.elements && html.elements[0]) { - var element = html.elements[0]; - var newHtml = $(result_table).html(); - for (var row in element.tags) { - if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) { - newHtml += "" + row + ""; - switch(row) { - case "phone": - case "fax": - newHtml += "" + element.tags[row] + ""; - break; - case "email": - newHtml += "" + element.tags[row] + ""; - break; - case "website": - case "url": - newHtml += "" + element.tags[row] + ""; - break; - case "wikidata": - newHtml += "" + element.tags[row] + ""; - break; - case "wikipedia": - if(element.tags[row].indexOf(":") != -1) { - newHtml += "" + element.tags[row] + ""; - break; - } - /* jshint ignore:start */ - default: - /* jshint ignore:end */ - newHtml += element.tags[row]; - break; - } - newHtml += ""; - } - } - $(result_table).html(newHtml); - $(result_table).removeClass('hidden'); - $(result_table_loadicon).addClass('hidden'); - } - }) - .fail(function() { - $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+searx.translations.could_not_load+"

"); - }); - } - } - - // this event occour only once per element - $( this ).off( event ); - }); - $(".searx_init_map").on( "click", function( event ) { var leaflet_target = $(this).data('leaflet-target'); var map_lon = $(this).data('map-lon'); diff --git a/searx/static/themes/oscar/src/js/leaflet_map.js b/searx/static/themes/oscar/src/js/leaflet_map.js index 83364b0c3..08233c42b 100644 --- a/searx/static/themes/oscar/src/js/leaflet_map.js +++ b/searx/static/themes/oscar/src/js/leaflet_map.js @@ -16,89 +16,6 @@ */ $(document).ready(function(){ - $(".searx_overpass_request").on( "click", function( event ) { - var overpass_url = "https://overpass-api.de/api/interpreter?data="; - var query_start = overpass_url + "[out:json][timeout:25];("; - var query_end = ");out meta;"; - - var osm_id = $(this).data('osm-id'); - var osm_type = $(this).data('osm-type'); - var result_table = $(this).data('result-table'); - var result_table_loadicon = "#" + $(this).data('result-table-loadicon'); - - // tags which can be ignored - var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]; - - if(osm_id && osm_type && result_table) { - result_table = "#" + result_table; - var query = null; - switch(osm_type) { - case 'node': - query = query_start + "node(" + osm_id + ");" + query_end; - break; - case 'way': - query = query_start + "way(" + osm_id + ");" + query_end; - break; - case 'relation': - query = query_start + "relation(" + osm_id + ");" + query_end; - break; - default: - break; - } - if(query) { - //alert(query); - var ajaxRequest = $.ajax( query ) - .done(function( html) { - if(html && html.elements && html.elements[0]) { - var element = html.elements[0]; - var newHtml = $(result_table).html(); - for (var row in element.tags) { - if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) { - newHtml += "" + row + ""; - switch(row) { - case "phone": - case "fax": - newHtml += "" + element.tags[row] + ""; - break; - case "email": - newHtml += "" + element.tags[row] + ""; - break; - case "website": - case "url": - newHtml += "" + element.tags[row] + ""; - break; - case "wikidata": - newHtml += "" + element.tags[row] + ""; - break; - case "wikipedia": - if(element.tags[row].indexOf(":") != -1) { - newHtml += "" + element.tags[row] + ""; - break; - } - /* jshint ignore:start */ - default: - /* jshint ignore:end */ - newHtml += element.tags[row]; - break; - } - newHtml += ""; - } - } - $(result_table).html(newHtml); - $(result_table).removeClass('hidden'); - $(result_table_loadicon).addClass('hidden'); - } - }) - .fail(function() { - $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+searx.translations.could_not_load+"

"); - }); - } - } - - // this event occour only once per element - $( this ).off( event ); - }); - $(".searx_init_map").on( "click", function( event ) { var leaflet_target = $(this).data('leaflet-target'); var map_lon = $(this).data('map-lon'); diff --git a/searx/static/themes/simple/js/searx.js b/searx/static/themes/simple/js/searx.js index 88c1823bc..92c99340c 100644 --- a/searx/static/themes/simple/js/searx.js +++ b/searx/static/themes/simple/js/searx.js @@ -1085,93 +1085,6 @@ module.exports = AutoComplete; 'use strict'; searx.ready(function () { - searx.on('.searx_overpass_request', 'click', function(event) { - // no more request - this.classList.remove("searx_overpass_request"); - - // - var overpass_url = "https://overpass-api.de/api/interpreter?data="; - var query_start = overpass_url + "[out:json][timeout:25];("; - var query_end = ");out meta;"; - - var osm_id = this.dataset.osmId; - var osm_type = this.dataset.osmType; - var result_table = d.querySelector("#" + this.dataset.resultTable); - var result_table_loadicon = d.querySelector("#" + this.dataset.resultTableLoadicon); - - // tags which can be ignored - var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]; - - if(osm_id && osm_type && result_table) { - var query = null; - switch(osm_type) { - case 'node': - query = query_start + "node(" + osm_id + ");" + query_end; - break; - case 'way': - query = query_start + "way(" + osm_id + ");" + query_end; - break; - case 'relation': - query = query_start + "relation(" + osm_id + ");" + query_end; - break; - default: - break; - } - if(query) { - // console.log(query); - searx.http( 'GET', query ).then(function(html, contentType) { - html = JSON.parse(html); - if(html && html.elements && html.elements[0]) { - var element = html.elements[0]; - var newHtml = ""; - for (var row in element.tags) { - if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) { - newHtml += "" + row + ""; - switch(row) { - case "phone": - case "fax": - newHtml += "" + element.tags[row] + ""; - break; - case "email": - newHtml += "" + element.tags[row] + ""; - break; - case "website": - case "url": - newHtml += "" + element.tags[row] + ""; - break; - case "wikidata": - newHtml += "" + element.tags[row] + ""; - break; - case "wikipedia": - if(element.tags[row].indexOf(":") != -1) { - newHtml += "" + element.tags[row] + ""; - break; - } - /* jshint ignore:start */ - default: - /* jshint ignore:end */ - newHtml += element.tags[row]; - break; - } - newHtml += ""; - } - } - result_table_loadicon.parentNode.removeChild(result_table_loadicon); - result_table.classList.remove('invisible'); - result_table.querySelector("tbody").innerHTML = newHtml; - } - }) - .catch(function() { - result_table_loadicon.classList.remove('invisible'); - result_table_loadicon.innerHTML = could_not_load; - }); - } - } - - // this event occour only once per element - event.preventDefault(); - }); - searx.on('.searx_init_map', 'click', function(event) { // no more request this.classList.remove("searx_init_map"); diff --git a/searx/static/themes/simple/js/searx_src/searx_mapresult.js b/searx/static/themes/simple/js/searx_src/searx_mapresult.js index 267ac94cb..2ccdbd1c7 100644 --- a/searx/static/themes/simple/js/searx_src/searx_mapresult.js +++ b/searx/static/themes/simple/js/searx_src/searx_mapresult.js @@ -19,93 +19,6 @@ 'use strict'; searx.ready(function () { - searx.on('.searx_overpass_request', 'click', function(event) { - // no more request - this.classList.remove("searx_overpass_request"); - - // - var overpass_url = "https://overpass-api.de/api/interpreter?data="; - var query_start = overpass_url + "[out:json][timeout:25];("; - var query_end = ");out meta;"; - - var osm_id = this.dataset.osmId; - var osm_type = this.dataset.osmType; - var result_table = d.querySelector("#" + this.dataset.resultTable); - var result_table_loadicon = d.querySelector("#" + this.dataset.resultTableLoadicon); - - // tags which can be ignored - var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]; - - if(osm_id && osm_type && result_table) { - var query = null; - switch(osm_type) { - case 'node': - query = query_start + "node(" + osm_id + ");" + query_end; - break; - case 'way': - query = query_start + "way(" + osm_id + ");" + query_end; - break; - case 'relation': - query = query_start + "relation(" + osm_id + ");" + query_end; - break; - default: - break; - } - if(query) { - // console.log(query); - searx.http( 'GET', query ).then(function(html, contentType) { - html = JSON.parse(html); - if(html && html.elements && html.elements[0]) { - var element = html.elements[0]; - var newHtml = ""; - for (var row in element.tags) { - if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) { - newHtml += "" + row + ""; - switch(row) { - case "phone": - case "fax": - newHtml += "" + element.tags[row] + ""; - break; - case "email": - newHtml += "" + element.tags[row] + ""; - break; - case "website": - case "url": - newHtml += "" + element.tags[row] + ""; - break; - case "wikidata": - newHtml += "" + element.tags[row] + ""; - break; - case "wikipedia": - if(element.tags[row].indexOf(":") != -1) { - newHtml += "" + element.tags[row] + ""; - break; - } - /* jshint ignore:start */ - default: - /* jshint ignore:end */ - newHtml += element.tags[row]; - break; - } - newHtml += ""; - } - } - result_table_loadicon.parentNode.removeChild(result_table_loadicon); - result_table.classList.remove('invisible'); - result_table.querySelector("tbody").innerHTML = newHtml; - } - }) - .catch(function() { - result_table_loadicon.classList.remove('invisible'); - result_table_loadicon.innerHTML = could_not_load; - }); - } - } - - // this event occour only once per element - event.preventDefault(); - }); - searx.on('.searx_init_map', 'click', function(event) { // no more request this.classList.remove("searx_init_map"); diff --git a/searx/templates/oscar/result_templates/map.html b/searx/templates/oscar/result_templates/map.html index 9713452b3..011ccc0bd 100644 --- a/searx/templates/oscar/result_templates/map.html +++ b/searx/templates/oscar/result_templates/map.html @@ -7,10 +7,6 @@ {%- endif -%} -{%- if result.osm and (result.osm.type and result.osm.id) -%} - -{%- endif -%} - {# {% if (result.latitude and result.longitude) %} {% endif %} #} @@ -39,15 +35,6 @@

{%- endif %} -{%- if result.osm and (result.osm.type and result.osm.id) -%} -
-
Loading ...
- - - -
-{%- endif -%} - {# {% if (result.latitude and result.longitude) %}
Longitude: {{ result.longitude }}
diff --git a/searx/templates/simple/result_templates/map.html b/searx/templates/simple/result_templates/map.html index 2de445168..15c89b070 100644 --- a/searx/templates/simple/result_templates/map.html +++ b/searx/templates/simple/result_templates/map.html @@ -7,9 +7,6 @@ {%- endif -%} -{%- if result.osm and (result.osm.type and result.osm.id) -%} - -{%- endif -%} {#- {% if (result.latitude and result.longitude) %} {{ icon('location') }} {{ _('show geodata') }} @@ -42,16 +39,6 @@ {{- result_sub_footer(result, proxify) -}} -{% if result.osm and (result.osm.type and result.osm.id) -%} - -{%- endif %} - {#- {% if (result.latitude and result.longitude) -%}