From c5d0923efd3addedf075592895d2fef3f8796e5e Mon Sep 17 00:00:00 2001 From: marc tobias Date: Tue, 1 Sep 2020 18:50:10 +0200 Subject: [PATCH] detailsURL helper which replaces detailsLink and detailsPermaLink --- dist/deletable.html | 12 ++++------ dist/details.html | 12 ++++------ dist/handlebar_helpers.js | 45 +++++++++++++++-------------------- dist/polygons.html | 12 ++++------ dist/reverse.html | 12 ++++------ dist/search.html | 12 ++++------ src/handlebar_helpers.js | 45 +++++++++++++++-------------------- src/templates/deletable.hbs | 2 +- src/templates/detailspage.hbs | 4 ++-- src/templates/reversepage.hbs | 3 +-- src/templates/searchpage.hbs | 3 +-- 11 files changed, 68 insertions(+), 94 deletions(-) diff --git a/dist/deletable.html b/dist/deletable.html index a3348a1..6ecc5fd 100644 --- a/dist/deletable.html +++ b/dist/deletable.html @@ -127,8 +127,7 @@ ({{formatLabel aResult}})

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

- details + details {{/inline}} @@ -261,8 +260,7 @@ {{formatLabel aResult}}

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

- details + details {{/inline}} @@ -333,7 +331,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -360,7 +358,7 @@

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

@@ -608,7 +606,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/dist/details.html b/dist/details.html index a3348a1..6ecc5fd 100644 --- a/dist/details.html +++ b/dist/details.html @@ -127,8 +127,7 @@ ({{formatLabel aResult}})

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

- details + details
{{/inline}} @@ -261,8 +260,7 @@ {{formatLabel aResult}}

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

- details + details {{/inline}} @@ -333,7 +331,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -360,7 +358,7 @@

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

@@ -608,7 +606,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/dist/handlebar_helpers.js b/dist/handlebar_helpers.js index 3ece852..36deacd 100644 --- a/dist/handlebar_helpers.js +++ b/dist/handlebar_helpers.js @@ -13,6 +13,13 @@ function formatOSMType(sType, bExcludeExternal) { return ''; } +function formatShortOSMType(sType) { + if (sType === 'node') return 'N'; + if (sType === 'way') return 'W'; + if (sType === 'relation') return 'R'; + return ''; +} + function getIcon(aPlace) { // equivalent to PHP Nominatim::ClassTypes::getIcon // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise @@ -115,10 +122,7 @@ Handlebars.registerHelper({ return formatOSMType(sType, bExcludeExternal); }, shortOSMType: function (sType) { - if (sType === 'node') return 'N'; - if (sType === 'way') return 'W'; - if (sType === 'relation') return 'R'; - return ''; + return formatShortOSMType(sType); }, // { osm_type: 'R', osm_id: 12345 } // relation 12345' + sTitle + '' ); }, - // { osm_type: 'R', osm_id: 12345 } - // details - detailsLink: function (aFeature, sTitle) { - if (!aFeature) return ''; - if (!aFeature.place_id) return ''; - - var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >'); - - return new Handlebars.SafeString( - '' + sTitleEscaped + '' - ); - }, - detailsPermaLink: function (aFeature, sTitle) { + // 'details.html?osmtype=R&osmid=2181874&class=boundary' + detailsURL: function (aFeature) { if (!aFeature) return ''; - var sOSMType = formatOSMType(aFeature.osm_type, false); + var sOSMType = aFeature.osm_type; + if (sOSMType && sOSMType.length !== 1) { + sOSMType = formatShortOSMType(aFeature.osm_type, false); // node => N + } if (!sOSMType) return ''; - var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id); - - var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id; - if (aFeature.category) { + var sURL = 'details.html?osmtype=' + sOSMType + '&osmid=' + aFeature.osm_id; + if (aFeature.class) { + sURL = sURL + '&class=' + aFeature.class; + } else if (aFeature.category) { sURL = sURL + '&class=' + aFeature.category; } - - return new Handlebars.SafeString( - '' + sTitleEscaped + '' - ); + return sURL; }, formatPlaceType: function (aPlace) { var sOut = aPlace.class + ':' + aPlace.type; diff --git a/dist/polygons.html b/dist/polygons.html index a3348a1..6ecc5fd 100644 --- a/dist/polygons.html +++ b/dist/polygons.html @@ -127,8 +127,7 @@ ({{formatLabel aResult}})

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

- details + details
{{/inline}} @@ -261,8 +260,7 @@ {{formatLabel aResult}}

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

- details + details {{/inline}} @@ -333,7 +331,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -360,7 +358,7 @@

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

@@ -608,7 +606,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/dist/reverse.html b/dist/reverse.html index a3348a1..6ecc5fd 100644 --- a/dist/reverse.html +++ b/dist/reverse.html @@ -127,8 +127,7 @@ ({{formatLabel aResult}})

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

- details + details
{{/inline}} @@ -261,8 +260,7 @@ {{formatLabel aResult}}

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

- details + details {{/inline}} @@ -333,7 +331,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -360,7 +358,7 @@

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

@@ -608,7 +606,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/dist/search.html b/dist/search.html index a3348a1..6ecc5fd 100644 --- a/dist/search.html +++ b/dist/search.html @@ -127,8 +127,7 @@ ({{formatLabel aResult}})

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

- details + details
{{/inline}} @@ -261,8 +260,7 @@ {{formatLabel aResult}}

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

- details + details {{/inline}} @@ -333,7 +331,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -360,7 +358,7 @@

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

@@ -608,7 +606,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/src/handlebar_helpers.js b/src/handlebar_helpers.js index 3ece852..36deacd 100644 --- a/src/handlebar_helpers.js +++ b/src/handlebar_helpers.js @@ -13,6 +13,13 @@ function formatOSMType(sType, bExcludeExternal) { return ''; } +function formatShortOSMType(sType) { + if (sType === 'node') return 'N'; + if (sType === 'way') return 'W'; + if (sType === 'relation') return 'R'; + return ''; +} + function getIcon(aPlace) { // equivalent to PHP Nominatim::ClassTypes::getIcon // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise @@ -115,10 +122,7 @@ Handlebars.registerHelper({ return formatOSMType(sType, bExcludeExternal); }, shortOSMType: function (sType) { - if (sType === 'node') return 'N'; - if (sType === 'way') return 'W'; - if (sType === 'relation') return 'R'; - return ''; + return formatShortOSMType(sType); }, // { osm_type: 'R', osm_id: 12345 } // relation 12345' + sTitle + '' ); }, - // { osm_type: 'R', osm_id: 12345 } - // details - detailsLink: function (aFeature, sTitle) { - if (!aFeature) return ''; - if (!aFeature.place_id) return ''; - - var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >'); - - return new Handlebars.SafeString( - '' + sTitleEscaped + '' - ); - }, - detailsPermaLink: function (aFeature, sTitle) { + // 'details.html?osmtype=R&osmid=2181874&class=boundary' + detailsURL: function (aFeature) { if (!aFeature) return ''; - var sOSMType = formatOSMType(aFeature.osm_type, false); + var sOSMType = aFeature.osm_type; + if (sOSMType && sOSMType.length !== 1) { + sOSMType = formatShortOSMType(aFeature.osm_type, false); // node => N + } if (!sOSMType) return ''; - var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id); - - var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id; - if (aFeature.category) { + var sURL = 'details.html?osmtype=' + sOSMType + '&osmid=' + aFeature.osm_id; + if (aFeature.class) { + sURL = sURL + '&class=' + aFeature.class; + } else if (aFeature.category) { sURL = sURL + '&class=' + aFeature.category; } - - return new Handlebars.SafeString( - '' + sTitleEscaped + '' - ); + return sURL; }, formatPlaceType: function (aPlace) { var sOut = aPlace.class + ':' + aPlace.type; diff --git a/src/templates/deletable.hbs b/src/templates/deletable.hbs index 35ab9e0..e193d30 100644 --- a/src/templates/deletable.hbs +++ b/src/templates/deletable.hbs @@ -20,7 +20,7 @@ {{#each aPolygons}} - {{detailsLink this place_id}} + {{this.place_id}} {{country_code}} {{name}} {{osmLink this}} diff --git a/src/templates/detailspage.hbs b/src/templates/detailspage.hbs index bbc2914..8fcda7c 100644 --- a/src/templates/detailspage.hbs +++ b/src/templates/detailspage.hbs @@ -13,7 +13,7 @@ {{this.rank_address}} {{formatAdminLevel this.admin_level}} {{formatDistance this.distance bDistanceInMeters}} - {{detailsPermaLink this 'details >'}} + details {{/inline}} @@ -40,7 +40,7 @@
diff --git a/src/templates/reversepage.hbs b/src/templates/reversepage.hbs index e5a9d68..e1a93f4 100644 --- a/src/templates/reversepage.hbs +++ b/src/templates/reversepage.hbs @@ -7,8 +7,7 @@ {{formatLabel aResult}}

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

- details + details
{{/inline}} diff --git a/src/templates/searchpage.hbs b/src/templates/searchpage.hbs index 65cfa28..4e675be 100644 --- a/src/templates/searchpage.hbs +++ b/src/templates/searchpage.hbs @@ -6,8 +6,7 @@ ({{formatLabel aResult}})

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

- details + details
{{/inline}} -- 2.39.5