[mod] remove overpass API call

prepare the code the PR #90
This commit is contained in:
Alexandre Flament 2021-05-29 15:22:20 +02:00 committed by Markus Heiser
parent ee83c99d2b
commit a89b823f8d
7 changed files with 0 additions and 368 deletions

View file

@ -238,89 +238,6 @@ $(document).ready(function(){
*/ */
$(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 += "<tr><td>" + row + "</td><td>";
switch(row) {
case "phone":
case "fax":
newHtml += "<a href=\"tel:" + element.tags[row].replace(/ /g,'') + "\">" + element.tags[row] + "</a>";
break;
case "email":
newHtml += "<a href=\"mailto:" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "website":
case "url":
newHtml += "<a href=\"" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikidata":
newHtml += "<a href=\"https://www.wikidata.org/wiki/" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikipedia":
if(element.tags[row].indexOf(":") != -1) {
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
break;
}
/* jshint ignore:start */
default:
/* jshint ignore:end */
newHtml += element.tags[row];
break;
}
newHtml += "</td></tr>";
}
}
$(result_table).html(newHtml);
$(result_table).removeClass('hidden');
$(result_table_loadicon).addClass('hidden');
}
})
.fail(function() {
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+searx.translations.could_not_load+"</p>");
});
}
}
// this event occour only once per element
$( this ).off( event );
});
$(".searx_init_map").on( "click", function( event ) { $(".searx_init_map").on( "click", function( event ) {
var leaflet_target = $(this).data('leaflet-target'); var leaflet_target = $(this).data('leaflet-target');
var map_lon = $(this).data('map-lon'); var map_lon = $(this).data('map-lon');

View file

@ -16,89 +16,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 += "<tr><td>" + row + "</td><td>";
switch(row) {
case "phone":
case "fax":
newHtml += "<a href=\"tel:" + element.tags[row].replace(/ /g,'') + "\">" + element.tags[row] + "</a>";
break;
case "email":
newHtml += "<a href=\"mailto:" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "website":
case "url":
newHtml += "<a href=\"" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikidata":
newHtml += "<a href=\"https://www.wikidata.org/wiki/" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikipedia":
if(element.tags[row].indexOf(":") != -1) {
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
break;
}
/* jshint ignore:start */
default:
/* jshint ignore:end */
newHtml += element.tags[row];
break;
}
newHtml += "</td></tr>";
}
}
$(result_table).html(newHtml);
$(result_table).removeClass('hidden');
$(result_table_loadicon).addClass('hidden');
}
})
.fail(function() {
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+searx.translations.could_not_load+"</p>");
});
}
}
// this event occour only once per element
$( this ).off( event );
});
$(".searx_init_map").on( "click", function( event ) { $(".searx_init_map").on( "click", function( event ) {
var leaflet_target = $(this).data('leaflet-target'); var leaflet_target = $(this).data('leaflet-target');
var map_lon = $(this).data('map-lon'); var map_lon = $(this).data('map-lon');

View file

@ -1085,93 +1085,6 @@ module.exports = AutoComplete;
'use strict'; 'use strict';
searx.ready(function () { 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 += "<tr><td>" + row + "</td><td>";
switch(row) {
case "phone":
case "fax":
newHtml += "<a href=\"tel:" + element.tags[row].replace(/ /g,'') + "\">" + element.tags[row] + "</a>";
break;
case "email":
newHtml += "<a href=\"mailto:" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "website":
case "url":
newHtml += "<a href=\"" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikidata":
newHtml += "<a href=\"https://www.wikidata.org/wiki/" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikipedia":
if(element.tags[row].indexOf(":") != -1) {
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
break;
}
/* jshint ignore:start */
default:
/* jshint ignore:end */
newHtml += element.tags[row];
break;
}
newHtml += "</td></tr>";
}
}
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) { searx.on('.searx_init_map', 'click', function(event) {
// no more request // no more request
this.classList.remove("searx_init_map"); this.classList.remove("searx_init_map");

View file

@ -19,93 +19,6 @@
'use strict'; 'use strict';
searx.ready(function () { 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 += "<tr><td>" + row + "</td><td>";
switch(row) {
case "phone":
case "fax":
newHtml += "<a href=\"tel:" + element.tags[row].replace(/ /g,'') + "\">" + element.tags[row] + "</a>";
break;
case "email":
newHtml += "<a href=\"mailto:" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "website":
case "url":
newHtml += "<a href=\"" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikidata":
newHtml += "<a href=\"https://www.wikidata.org/wiki/" + element.tags[row] + "\">" + element.tags[row] + "</a>";
break;
case "wikipedia":
if(element.tags[row].indexOf(":") != -1) {
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
break;
}
/* jshint ignore:start */
default:
/* jshint ignore:end */
newHtml += element.tags[row];
break;
}
newHtml += "</td></tr>";
}
}
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) { searx.on('.searx_init_map', 'click', function(event) {
// no more request // no more request
this.classList.remove("searx_init_map"); this.classList.remove("searx_init_map");

View file

@ -7,10 +7,6 @@
<small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small> <small> &bull; <a class="text-info btn-collapse collapsed searx_init_map cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-map-{{ index }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %} data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}">{{ icon('globe') }} {{ _('show map') }}</a></small>
{%- endif -%} {%- endif -%}
{%- if result.osm and (result.osm.type and result.osm.id) -%}
<small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer searx_overpass_request disabled_if_nojs" data-toggle="collapse" data-target="#result-overpass-{{ index }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}">{{ icon('map-marker') }} {{ _('show details') }}</a></small>
{%- endif -%}
{# {% if (result.latitude and result.longitude) %} {# {% if (result.latitude and result.longitude) %}
<small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('map-marker') }} {{ _('show geodata') }}</a></small> <small> &bull; <a class="text-info btn-collapse collapsed cursor-pointer disabled_if_nojs" data-toggle="collapse" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('map-marker') }} {{ _('show geodata') }}</a></small>
{% endif %} #} {% endif %} #}
@ -39,15 +35,6 @@
</p> </p>
{%- endif %} {%- endif %}
{%- if result.osm and (result.osm.type and result.osm.id) -%}
<div class="row result-content collapse col-xs-12 col-sm-7 col-md-8" id="result-overpass-{{ index }}"{% if rtl %} dir="ltr"{% endif %}>
<div class="text-center" id="result-overpass-table-loading-{{ index }}"><img src="{{ url_for('static', filename='img/loader.gif') }}" alt="Loading ..."/></div>
<table class="table table-striped table-condensed hidden" id="result-overpass-table-{{ index }}">
<tr><th>key</th><th>value</th></tr>
</table>
</div>
{%- endif -%}
{# {% if (result.latitude and result.longitude) %} {# {% if (result.latitude and result.longitude) %}
<div class="row collapse col-xs-12 col-sm-5 col-md-4" id="result-geodata-{{ index }}"> <div class="row collapse col-xs-12 col-sm-5 col-md-4" id="result-geodata-{{ index }}">
<strong>Longitude:</strong> {{ result.longitude }} <br/> <strong>Longitude:</strong> {{ result.longitude }} <br/>

View file

@ -7,9 +7,6 @@
<small> &bull; <a class="btn-collapse collapsed searx_init_map hide_if_nojs" data-target="#result-map-{{ index }}" data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %}>{{ icon( 'globe') }} {{ _('show map') }}</a></small> <small> &bull; <a class="btn-collapse collapsed searx_init_map hide_if_nojs" data-target="#result-map-{{ index }}" data-btn-text-collapsed="{{ _('show map') }}" data-btn-text-not-collapsed="{{ _('hide map') }}" data-leaflet-target="osm-map-{{ index }}" data-map-lon="{{ result.longitude }}" data-map-lat="{{ result.latitude }}" {% if result.boundingbox %}data-map-boundingbox='{{ result.boundingbox|tojson|safe }}'{% endif %} {% if result.geojson %}data-map-geojson='{{ result.geojson|tojson|safe }}'{% endif %}>{{ icon( 'globe') }} {{ _('show map') }}</a></small>
{%- endif -%} {%- endif -%}
{%- if result.osm and (result.osm.type and result.osm.id) -%}
<small> &bull; <a class="btn-collapse collapsed hide_if_nojs searx_overpass_request" data-target="#result-overpass-{{ index }}" data-btn-text-collapsed="{{ _('show details') }}" data-btn-text-not-collapsed="{{ _('hide details') }}" data-osm-type="{{ result.osm.type }}" data-osm-id="{{ result.osm.id }}" data-result-table="result-overpass-table-{{ index }}" data-result-table-loadicon="result-overpass-table-loading-{{ index }}">{{ icon('location') }} {{ _('show details') }}</a></small>
{%- endif -%}
{#- {#-
{% if (result.latitude and result.longitude) %} {% if (result.latitude and result.longitude) %}
<small> &bull; <a class="btn-collapse disabled_if_nojs" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('location') }} {{ _('show geodata') }}</a></small> <small> &bull; <a class="btn-collapse disabled_if_nojs" data-target="#result-geodata-{{ index }}" data-btn-text-collapsed="{{ _('show geodata') }}" data-btn-text-not-collapsed="{{ _('hide geodata') }}">{{ icon('location') }} {{ _('show geodata') }}</a></small>
@ -42,16 +39,6 @@
{{- result_sub_footer(result, proxify) -}} {{- result_sub_footer(result, proxify) -}}
{% if result.osm and (result.osm.type and result.osm.id) -%}
<div class="result-content invisible" id="result-overpass-{{ index }}"{% if rtl %} dir="ltr"{% endif %}>
<div id="result-overpass-table-loading-{{ index }}"><div class="loader">{{ _('Loading...') }}</div></div>
<table id="result-overpass-table-{{ index }}">
<tbody>
</tbody>
</table>
</div>
{%- endif %}
{#- {#-
{% if (result.latitude and result.longitude) -%} {% if (result.latitude and result.longitude) -%}
<div id="result-geodata-{{ index }}" class="invisible"> <div id="result-geodata-{{ index }}" class="invisible">

View file

@ -446,8 +446,6 @@ def image_proxify(url):
def get_translations(): def get_translations():
return { return {
# when overpass AJAX request fails (on a map result)
'could_not_load': gettext('could not load data'),
# when there is autocompletion # when there is autocompletion
'no_item_found': gettext('No item found') 'no_item_found': gettext('No item found')
} }