]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
detailsURL helper which replaces detailsLink and detailsPermaLink
authormarc tobias <mtmail@gmx.net>
Tue, 1 Sep 2020 16:50:10 +0000 (18:50 +0200)
committermarc tobias <mtmail@gmx.net>
Tue, 1 Sep 2020 16:50:10 +0000 (18:50 +0200)
dist/deletable.html
dist/details.html
dist/handlebar_helpers.js
dist/polygons.html
dist/reverse.html
dist/search.html
src/handlebar_helpers.js
src/templates/deletable.hbs
src/templates/detailspage.hbs
src/templates/reversepage.hbs
src/templates/searchpage.hbs

index a3348a1e56849dc82b812b1effa7b63c33e72b22..6ecc5fd04c72b9359520cafd628eb534d7959e65 100644 (file)
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index a3348a1e56849dc82b812b1effa7b63c33e72b22..6ecc5fd04c72b9359520cafd628eb534d7959e65 100644 (file)
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index 3ece852a9d0fa13788ee40e5e41707e11c670cd3..36deacd808d35f8aa435a4707cdd6dcdec608710 100644 (file)
@@ -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 }
   // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
@@ -145,34 +149,23 @@ Handlebars.registerHelper({
       '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
     );
   },
-  // { osm_type: 'R', osm_id: 12345 }
-  // <a href="details.html?place_id=12345">details</a>
-  detailsLink: function (aFeature, sTitle) {
-    if (!aFeature) return '';
-    if (!aFeature.place_id) return '';
-
-    var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
-
-    return new Handlebars.SafeString(
-      '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
-    );
-  },
-  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(
-      '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
-    );
+    return sURL;
   },
   formatPlaceType: function (aPlace) {
     var sOut = aPlace.class + ':' + aPlace.type;
index a3348a1e56849dc82b812b1effa7b63c33e72b22..6ecc5fd04c72b9359520cafd628eb534d7959e65 100644 (file)
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index a3348a1e56849dc82b812b1effa7b63c33e72b22..6ecc5fd04c72b9359520cafd628eb534d7959e65 100644 (file)
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index a3348a1e56849dc82b812b1effa7b63c33e72b22..6ecc5fd04c72b9359520cafd628eb534d7959e65 100644 (file)
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index 3ece852a9d0fa13788ee40e5e41707e11c670cd3..36deacd808d35f8aa435a4707cdd6dcdec608710 100644 (file)
@@ -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 }
   // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
@@ -145,34 +149,23 @@ Handlebars.registerHelper({
       '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
     );
   },
-  // { osm_type: 'R', osm_id: 12345 }
-  // <a href="details.html?place_id=12345">details</a>
-  detailsLink: function (aFeature, sTitle) {
-    if (!aFeature) return '';
-    if (!aFeature.place_id) return '';
-
-    var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
-
-    return new Handlebars.SafeString(
-      '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
-    );
-  },
-  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(
-      '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
-    );
+    return sURL;
   },
   formatPlaceType: function (aPlace) {
     var sOut = aPlace.class + ':' + aPlace.type;
index 35ab9e0e446faffc0161fcb0c7b63c76157b1dfd..e193d3030d715ac7ff5c00514db35aaa688898fb 100644 (file)
@@ -20,7 +20,7 @@
         <tbody>
           {{#each aPolygons}}
           <tr>
-            <td>{{detailsLink this place_id}}</td>
+            <td><a href="{{detailsURL this}}">{{this.place_id}}</a></td>
             <td>{{country_code}}</td>
             <td>{{name}}</td>
             <td>{{osmLink this}}</td>
index bbc29146e1a26b78b544036c18cddbf6e64ace0d..8fcda7cc82ae8fd1006f254cc5652c90bd1f063a 100644 (file)
@@ -13,7 +13,7 @@
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
     <td>{{formatDistance this.distance bDistanceInMeters}}</td>
-    <td>{{detailsPermaLink this 'details >'}}</td>
+    <td><a href="{{detailsURL this}}">details</td>
   </tr>
 {{/inline}}
 
@@ -40,7 +40,7 @@
     <div class="col-sm-10">
       <h1>
         {{aPlace.localname}}
-        <small>{{detailsPermaLink aPlace 'link to this page'}}</small>
+        <small><a href="{{detailsURL aPlace}}">link to this page</a></small>
       </h1>
     </div>
     <div class="col-sm-2 text-right">
index e5a9d683a5391aff494631d6168de02a4d22ee8c..e1a93f462a2ca1ed744157384e7f84602f09be75 100644 (file)
@@ -7,8 +7,7 @@
     <span class="type">{{formatLabel aResult}}</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}
 
index 65cfa28f245e39cda91b5c9becf34b34a0a8769f..4e675be3a0239a7228b47faff64cb12d73cd9055 100644 (file)
@@ -6,8 +6,7 @@
     <span class="type">({{formatLabel aResult}})</span>
     <p class="coords">{{aResult.lat}},{{aResult.lon}}</p>  
 
-    <a class="details btn btn-outline-secondary btn-sm"
-       href="details.html?osmtype={{shortOSMType aResult.osm_type}}&osmid={{aResult.osm_id}}">details</a>
+    <a class="details btn btn-outline-secondary btn-sm" href="{{detailsURL aResult}}">details</a>
   </div>
 {{/inline}}