From e0d087f4a2b5fbc758de432f8932de296279a82f Mon Sep 17 00:00:00 2001 From: marc tobias Date: Tue, 7 Jul 2020 02:24:14 +0200 Subject: [PATCH] all templates in one document, deal with window.history change --- build.sh | 57 ++-- dist/assets/css/common.css | 11 + dist/assets/js/nominatim-ui.js | 95 ++++-- dist/deletable.hbs | 39 --- dist/deletable.html | 521 ++++++++++++++++++++++++++++++++- dist/details.html | 294 ++++++++++++++++++- dist/detailspage-index.hbs | 56 ---- dist/detailspage.hbs | 209 ------------- dist/polygons.hbs | 45 --- dist/polygons.html | 515 +++++++++++++++++++++++++++++++- dist/reverse.html | 496 ++++++++++++++++++++++++++++++- dist/reversepage.hbs | 64 ---- dist/search.html | 429 ++++++++++++++++++++++++++- dist/searchpage.hbs | 131 --------- src/assets/css/common.css | 11 + src/assets/js/base.js | 19 +- src/assets/js/controller.js | 50 ++++ src/assets/js/deletable.js | 5 +- src/assets/js/detailpage.js | 5 +- src/assets/js/polygons.js | 7 +- src/assets/js/searchpage.js | 11 +- src/layout.html | 5 +- 22 files changed, 2428 insertions(+), 647 deletions(-) delete mode 100644 dist/deletable.hbs delete mode 100644 dist/detailspage-index.hbs delete mode 100644 dist/detailspage.hbs delete mode 100644 dist/polygons.hbs delete mode 100644 dist/reversepage.hbs delete mode 100644 dist/searchpage.hbs create mode 100644 src/assets/js/controller.js diff --git a/build.sh b/build.sh index 9ecf435..973ccbd 100755 --- a/build.sh +++ b/build.sh @@ -1,78 +1,69 @@ #!/bin/bash mkdir -p dist/assets/ -rsync --quiet --recursive src/assets/css/ dist/assets/css/ +rsync --quiet --recursive src/assets/css/ dist/assets/css/ rsync --quiet --recursive src/assets/images/ dist/assets/images/ mkdir -p dist/assets/js/ -cat src/assets/js/base.js src/assets/js/detailpage.js src/assets/js/searchpage.js src/assets/js/deletable.js src/assets/js/polygons.js > dist/assets/js/nominatim-ui.js +cat src/assets/js/base.js \ + src/assets/js/detailpage.js \ + src/assets/js/searchpage.js \ + src/assets/js/deletable.js \ + src/assets/js/polygons.js \ + src/assets/js/controller.js > dist/assets/js/nominatim-ui.js -rsync --quiet node_modules/jquery/dist/jquery.min.js dist/assets/js/ -rsync --quiet node_modules/leaflet/dist/leaflet.js dist/assets/js/ +rsync --quiet node_modules/jquery/dist/jquery.min.js dist/assets/js/ +rsync --quiet node_modules/leaflet/dist/leaflet.js dist/assets/js/ rsync --quiet node_modules/leaflet/dist/leaflet.js.map dist/assets/js/ -rsync --quiet node_modules/leaflet/dist/leaflet.css dist/assets/css/ -rsync --quiet node_modules/leaflet/dist/images/* dist/assets/css/images/ +rsync --quiet node_modules/leaflet/dist/leaflet.css dist/assets/css/ +rsync --quiet node_modules/leaflet/dist/images/* dist/assets/css/images/ -rsync --quiet node_modules/leaflet-minimap/dist/Control.MiniMap.min.js dist/assets/js/ +rsync --quiet node_modules/leaflet-minimap/dist/Control.MiniMap.min.js dist/assets/js/ rsync --quiet node_modules/leaflet-minimap/dist/Control.MiniMap.min.css dist/assets/css/ -rsync --quiet node_modules/leaflet-minimap/dist/images/* dist/assets/css/images/ +rsync --quiet node_modules/leaflet-minimap/dist/images/* dist/assets/css/images/ rsync --quiet node_modules/bootstrap/dist/js/bootstrap.bundle.min.js* dist/assets/js/ -rsync --quiet node_modules/bootstrap/dist/css/bootstrap.min.css dist/assets/css/ +rsync --quiet node_modules/bootstrap/dist/css/bootstrap.min.css dist/assets/css/ rsync --quiet node_modules/handlebars/dist/handlebars.min.js dist/assets/js/ -rsync --quiet node_modules/@ungap/url-search-params/min.js dist/assets/js/url-search-params.js -rsync --quiet src/templates/*.hbs dist/ +rsync --quiet node_modules/@ungap/url-search-params/min.js dist/assets/js/url-search-params.js rsync --quiet src/*.js dist/ { - sed -e 's/BODYID/search-page/' src/layout.html | grep -v '' | grep -v '' + cat src/layout.html | grep -v '' | grep -v '' echo '' - echo '' - echo '' -} > dist/search.html -{ - sed -e 's/BODYID/reverse-page/' src/layout.html | grep -v '' | grep -v '' echo '' - echo '' - echo '' -} > dist/reverse.html -{ - sed -e 's/BODYID/details-page/' src/layout.html | grep -v '' | grep -v '' echo '' + echo '' - echo '' - echo '' -} > dist/details.html -{ - sed -e 's/BODYID/deletable-page/' src/layout.html | grep -v '' | grep -v '' echo '' - echo '' - echo '' -} > dist/deletable.html -{ - sed -e 's/BODYID/polygons-page/' src/layout.html | grep -v '' | grep -v '' echo '' + echo '' echo '' -} > dist/polygons.html +} > dist/search.html + +cp dist/search.html dist/reverse.html +cp dist/search.html dist/details.html +cp dist/search.html dist/deletable.html +cp dist/search.html dist/polygons.html cp src/index.html dist/ diff --git a/dist/assets/css/common.css b/dist/assets/css/common.css index 5eabed9..ab814d7 100755 --- a/dist/assets/css/common.css +++ b/dist/assets/css/common.css @@ -50,6 +50,17 @@ footer p { margin: 1em; } +#loading { + display: none; + position: absolute; + top: 0; + width: 100%; + background-color: #eee; + z-index: 100; + padding: 10px; + text-align: center; +} + #error-overlay { text-align: center; font-style: italic; diff --git a/dist/assets/js/nominatim-ui.js b/dist/assets/js/nominatim-ui.js index 9fff0c7..faf6902 100644 --- a/dist/assets/js/nominatim-ui.js +++ b/dist/assets/js/nominatim-ui.js @@ -131,16 +131,19 @@ function hide_error() { } -$(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { - // console.log(thrownError); - // console.log(ajaxSettings); - var url = ajaxSettings.url; - show_error('Error fetching results from ' + url + ''); -}); - - jQuery(document).ready(function () { hide_error(); + + $(document).ajaxStart(function () { + $('#loading').fadeIn('fast'); + }).ajaxComplete(function () { + $('#loading').fadeOut('fast'); + }).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { + // console.log(thrownError); + // console.log(ajaxSettings); + var url = ajaxSettings.url; + show_error('Error fetching results from ' + url + ''); + }); }); // ********************************************************* // DETAILS PAGE @@ -198,8 +201,7 @@ function init_map_on_detail_page(lat, lon, geojson) { } -jQuery(document).ready(function () { - if (!$('#details-page').length) { return; } +function details_page_load() { var search_params = new URLSearchParams(window.location.search); // var place_id = search_params.get('place_id'); @@ -255,7 +257,7 @@ jQuery(document).ready(function () { alert('invalid input'); } }); -}); +} // ********************************************************* // FORWARD/REVERSE SEARCH PAGE @@ -550,12 +552,9 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l +function search_page_load() { -jQuery(document).ready(function () { - // - if (!$('#search-page,#reverse-page').length) { return; } - - var is_reverse_search = !!($('#reverse-page').length); + var is_reverse_search = window.location.pathname.match(/reverse/); var search_params = new URLSearchParams(window.location.search); @@ -710,13 +709,14 @@ jQuery(document).ready(function () { ); } } -}); +} + + // ********************************************************* // DELETABLE PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#deletable-page').length) { return; } +function deletable_page_load() { var api_request_params = { format: 'json' @@ -730,14 +730,13 @@ jQuery(document).ready(function () { update_data_date(); }); -}); +} // ********************************************************* // BROKEN POLYGON PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#polygons-page').length) { return; } - +function polygons_page_load() { + // var api_request_params = { format: 'json' }; @@ -750,4 +749,54 @@ jQuery(document).ready(function () { update_data_date(); }); +} +jQuery(document).ready(function () { + var myhistory = []; + + function parse_url_and_load_page() { + // 'search', 'reverse', 'details' + var pagename = window.location.pathname.replace('.html', '').replace(/^\//, ''); + + $('body').attr('id', pagename + '-page'); + + if (pagename === 'search' || pagename === 'reverse') { + search_page_load(); + } else if (pagename === 'details') { + details_page_load(); + } else if (pagename === 'deletable') { + deletable_page_load(); + } else if (pagename === 'polygons') { + polygons_page_load(); + } + } + + parse_url_and_load_page(); + + // load page after form submit + $(document).on('submit', 'form', function (e) { + e.preventDefault(); + + window.history.pushState(myhistory, '', '?' + $(this).serialize()); + + parse_url_and_load_page(); + }); + + // load page after click on relative URL + $(document).on('click', 'a', function (e) { + var target_url = $(this).attr('href'); + if (target_url && target_url.match(/^http/)) return; + if (target_url && !target_url.match(/\.html/)) return; + + e.preventDefault(); + + window.history.pushState(myhistory, '', target_url); + + parse_url_and_load_page(); + }); + + // deal with back-button and other user action + window.onpopstate = function () { + parse_url_and_load_page(); + }; }); + diff --git a/dist/deletable.hbs b/dist/deletable.hbs deleted file mode 100644 index 35ab9e0..0000000 --- a/dist/deletable.hbs +++ /dev/null @@ -1,39 +0,0 @@ -
-
-
-

Deletable

- -

- {{aPolygons.length}} objects have been deleted in OSM but are still in the Nominatim database. -

- - - - - - - - - - - - - {{#each aPolygons}} - - - - - - - - - - {{/each}} - -
Place idCountry CodeNameOSM idOSM typeClassType
{{detailsLink this place_id}}{{country_code}}{{name}}{{osmLink this}}{{osm_type}}{{class}}{{type}}
- - -
-
-
- + -
- You need Javascript enabled to view this page. -
+
@@ -32,6 +30,7 @@
+
loading...
Data from API request
Data last updated: @@ -116,6 +115,473 @@ + + + + + diff --git a/dist/details.html b/dist/details.html index 3d0c57e..aba9dbb 100644 --- a/dist/details.html +++ b/dist/details.html @@ -15,11 +15,9 @@ - + -
- You need Javascript enabled to view this page. -
+
@@ -32,6 +30,7 @@
+
loading...
Data from API request
Data last updated: @@ -116,6 +115,205 @@ + + + + diff --git a/dist/detailspage-index.hbs b/dist/detailspage-index.hbs deleted file mode 100644 index c81d525..0000000 --- a/dist/detailspage-index.hbs +++ /dev/null @@ -1,56 +0,0 @@ -
-
-
- -

Show details for place

- -
-

Search by place id

- -
- - -
-
- -
-

Search by OSM type and OSM id

- -
- - - - -
-
- -
-

Search by openstreetmap.org URL

- -
- - - - -
-
- -
-
-
\ No newline at end of file diff --git a/dist/detailspage.hbs b/dist/detailspage.hbs deleted file mode 100644 index 48ecde9..0000000 --- a/dist/detailspage.hbs +++ /dev/null @@ -1,209 +0,0 @@ - -{{#*inline "partial_details_one_row"}} - - - {{#if this.localname}} - {{this.localname}} - {{else}} - No Name - {{/if}} - - {{formatPlaceType this}} - {{osmLink this}} - {{this.rank_address}} - {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} - {{detailsPermaLink this 'details >'}} - -{{/inline}} - -{{#*inline "partial_details_keyword_one_row"}} - - {{formatKeywordToken this.token}} - {{#if this.id}} - word id: {{this.id}} - {{/if}} - -{{/inline}} - - -{{#*inline "partial_h2"}} -

{{this}}

-{{/inline}} - -{{#*inline "partial_h3"}} -

{{this}}

-{{/inline}} - -
-
-
-

- {{aPlace.localname}} - {{detailsPermaLink aPlace 'link to this page'}} -

-
-
- {{formatMapIcon aPlace}} -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - {{#if aPlace.calculated_importance}} - - - - - {{/if}} - - - - - - - - - - - - - - - - {{#if aPlace.calculated_wikipedia}} - - - - - {{/if}} - - - - - - - - - - - - -
Name - {{#each aPlace.names}} -
- {{this}} ({{@key}}) -
- {{/each}} -
Type{{aPlace.category}}:{{aPlace.type}}
Last Updated{{aPlace.indexed_date}}
Admin Level{{aPlace.admin_level}}
Rank{{formatSearchRank aPlace.rank_search}}
Importance - {{aPlace.calculated_importance}} - {{#unless aPlace.importance}} (estimated){{/unless}} -
Coverage{{coverageType aPlace}}
Centre Point (lat,lon) - {{aPlace.centroid.coordinates.[1]}},{{aPlace.centroid.coordinates.[0]}} -
OSM{{osmLink aPlace}} -
- Place Id - (on this server) - {{aPlace.place_id}}
Wikipedia Calculated{{wikipediaLink aPlace}}
Computed Postcode{{aPlace.calculated_postcode}}
Address Tags - {{#each aPlace.addresstags}} -
- {{this}} ({{@key}}) -
- {{/each}} -
Extra Tags - {{#each aPlace.extratags}} -
- {{this}} ({{@key}}) -
- {{/each}} -
-
-
-
-
-
-
-
-

Address

- - - - - - - - - - - - - - {{#if aPlace.address}} - {{#each aPlace.address}} - {{> partial_details_one_row}} - {{/each}} - {{/if}} - - {{#if aPlace.linked_places}} - {{> partial_h2 'Linked Places'}} - {{#each aPlace.linked_places}} - {{> partial_details_one_row}} - {{/each}} - {{/if}} - - {{#if aPlace.keywords}} - {{> partial_h2 'Name Keywords'}} - {{#each aPlace.keywords.name}} - {{> partial_details_keyword_one_row}} - {{/each}} - - {{> partial_h2 'Address Keywords'}} - {{#each aPlace.keywords.address}} - {{> partial_details_keyword_one_row}} - {{/each}} - {{/if}} - - {{> partial_h2 'Parent Of'}} - {{#if aPlace.hierarchy}} - - {{#each aPlace.hierarchy as |lines type|}} - {{> partial_h3 type}} - {{#each lines}} - {{> partial_details_one_row}} - {{/each}} - {{/each}} - {{else}} - - - - {{/if}} - {{tooManyHierarchyLinesWarning aPlace}} - -
Local nameTypeOSMAddress rankAdmin levelDistance
- display child places -
-
-
-
- diff --git a/dist/polygons.hbs b/dist/polygons.hbs deleted file mode 100644 index 9e74ef6..0000000 --- a/dist/polygons.hbs +++ /dev/null @@ -1,45 +0,0 @@ -
-
-
-

Broken polygons

- -

- Total number of broken polygons: {{aPolygons.length}}. -

- - - - - - - - - - - - - - - {{#each aPolygons}} - - - - - - - - - - - - {{/each}} - -
OSM typeOSM idClassTypeNameCountry CodeError messageUpdated 
{{osm_type}}{{osmLink this}}{{class}}{{type}}{{name}}{{country_code}}{{errormessage}}{{updated}} - josm -
- - -
-
-
- + -
- You need Javascript enabled to view this page. -
+
@@ -32,6 +30,7 @@
+
loading...
Data from API request
Data last updated: @@ -116,6 +115,514 @@ + + + + + + + + + + diff --git a/dist/reversepage.hbs b/dist/reversepage.hbs deleted file mode 100644 index ba80e74..0000000 --- a/dist/reversepage.hbs +++ /dev/null @@ -1,64 +0,0 @@ - -{{#*inline "partial_one_result"}} -
- {{formatMapIcon aResult}} - - {{aResult.display_name}} - {{formatLabel aResult}} -

{{aResult.lat}},{{aResult.lon}}

- - details -
-{{/inline}} - -
- -
- -
- {{#if aPlace}} - - {{else}} - - {{/if}} - -
-
-
- -
-
-
-
diff --git a/dist/search.html b/dist/search.html index e8aa46a..aba9dbb 100644 --- a/dist/search.html +++ b/dist/search.html @@ -15,11 +15,9 @@ - + -
- You need Javascript enabled to view this page. -
+
@@ -32,6 +30,7 @@
+
loading...
Data from API request
Data last updated: @@ -248,6 +247,428 @@
+ + + + + + diff --git a/dist/searchpage.hbs b/dist/searchpage.hbs deleted file mode 100644 index ce2fc47..0000000 --- a/dist/searchpage.hbs +++ /dev/null @@ -1,131 +0,0 @@ -{{#*inline "partial_one_result"}} -
- {{formatMapIcon aResult}} - - {{aResult.display_name}} - ({{formatLabel aResult}}) -

{{aResult.lat}},{{aResult.lon}}

- - details -
-{{/inline}} - -
- -
-
- -
-
- -
-
-
- -
- - {{#if sQuery}} - - - {{else}} - - - - {{/if}} - -
-
-
- -
-
-
-
diff --git a/src/assets/css/common.css b/src/assets/css/common.css index 5eabed9..ab814d7 100755 --- a/src/assets/css/common.css +++ b/src/assets/css/common.css @@ -50,6 +50,17 @@ footer p { margin: 1em; } +#loading { + display: none; + position: absolute; + top: 0; + width: 100%; + background-color: #eee; + z-index: 100; + padding: 10px; + text-align: center; +} + #error-overlay { text-align: center; font-style: italic; diff --git a/src/assets/js/base.js b/src/assets/js/base.js index c7ae6f9..4ff6b23 100644 --- a/src/assets/js/base.js +++ b/src/assets/js/base.js @@ -131,14 +131,17 @@ function hide_error() { } -$(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { - // console.log(thrownError); - // console.log(ajaxSettings); - var url = ajaxSettings.url; - show_error('Error fetching results from ' + url + ''); -}); - - jQuery(document).ready(function () { hide_error(); + + $(document).ajaxStart(function () { + $('#loading').fadeIn('fast'); + }).ajaxComplete(function () { + $('#loading').fadeOut('fast'); + }).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) { + // console.log(thrownError); + // console.log(ajaxSettings); + var url = ajaxSettings.url; + show_error('Error fetching results from ' + url + ''); + }); }); diff --git a/src/assets/js/controller.js b/src/assets/js/controller.js new file mode 100644 index 0000000..3c122ee --- /dev/null +++ b/src/assets/js/controller.js @@ -0,0 +1,50 @@ +jQuery(document).ready(function () { + var myhistory = []; + + function parse_url_and_load_page() { + // 'search', 'reverse', 'details' + var pagename = window.location.pathname.replace('.html', '').replace(/^\//, ''); + + $('body').attr('id', pagename + '-page'); + + if (pagename === 'search' || pagename === 'reverse') { + search_page_load(); + } else if (pagename === 'details') { + details_page_load(); + } else if (pagename === 'deletable') { + deletable_page_load(); + } else if (pagename === 'polygons') { + polygons_page_load(); + } + } + + parse_url_and_load_page(); + + // load page after form submit + $(document).on('submit', 'form', function (e) { + e.preventDefault(); + + window.history.pushState(myhistory, '', '?' + $(this).serialize()); + + parse_url_and_load_page(); + }); + + // load page after click on relative URL + $(document).on('click', 'a', function (e) { + var target_url = $(this).attr('href'); + if (target_url && target_url.match(/^http/)) return; + if (target_url && !target_url.match(/\.html/)) return; + + e.preventDefault(); + + window.history.pushState(myhistory, '', target_url); + + parse_url_and_load_page(); + }); + + // deal with back-button and other user action + window.onpopstate = function () { + parse_url_and_load_page(); + }; +}); + diff --git a/src/assets/js/deletable.js b/src/assets/js/deletable.js index 308b70c..1dc8f0e 100644 --- a/src/assets/js/deletable.js +++ b/src/assets/js/deletable.js @@ -2,8 +2,7 @@ // DELETABLE PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#deletable-page').length) { return; } +function deletable_page_load() { var api_request_params = { format: 'json' @@ -17,4 +16,4 @@ jQuery(document).ready(function () { update_data_date(); }); -}); +} diff --git a/src/assets/js/detailpage.js b/src/assets/js/detailpage.js index 919e19a..23447e9 100644 --- a/src/assets/js/detailpage.js +++ b/src/assets/js/detailpage.js @@ -54,8 +54,7 @@ function init_map_on_detail_page(lat, lon, geojson) { } -jQuery(document).ready(function () { - if (!$('#details-page').length) { return; } +function details_page_load() { var search_params = new URLSearchParams(window.location.search); // var place_id = search_params.get('place_id'); @@ -111,4 +110,4 @@ jQuery(document).ready(function () { alert('invalid input'); } }); -}); +} diff --git a/src/assets/js/polygons.js b/src/assets/js/polygons.js index 3ccaf11..9470649 100644 --- a/src/assets/js/polygons.js +++ b/src/assets/js/polygons.js @@ -2,9 +2,8 @@ // BROKEN POLYGON PAGE // ********************************************************* -jQuery(document).ready(function () { - if (!$('#polygons-page').length) { return; } - +function polygons_page_load() { + // var api_request_params = { format: 'json' }; @@ -17,4 +16,4 @@ jQuery(document).ready(function () { update_data_date(); }); -}); +} diff --git a/src/assets/js/searchpage.js b/src/assets/js/searchpage.js index a315338..be9c20a 100755 --- a/src/assets/js/searchpage.js +++ b/src/assets/js/searchpage.js @@ -292,12 +292,9 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l +function search_page_load() { -jQuery(document).ready(function () { - // - if (!$('#search-page,#reverse-page').length) { return; } - - var is_reverse_search = !!($('#reverse-page').length); + var is_reverse_search = window.location.pathname.match(/reverse/); var search_params = new URLSearchParams(window.location.search); @@ -452,4 +449,6 @@ jQuery(document).ready(function () { ); } } -}); +} + + diff --git a/src/layout.html b/src/layout.html index ce8fc70..836eddc 100644 --- a/src/layout.html +++ b/src/layout.html @@ -17,9 +17,7 @@ -
- You need Javascript enabled to view this page. -
+
@@ -32,6 +30,7 @@
+
loading...
Data from API request
Data last updated: -- 2.39.5