]> git.openstreetmap.org Git - rails.git/commitdiff
Select which key entries to show on the client
authorTom Hughes <tom@compton.nu>
Fri, 31 Aug 2012 09:29:32 +0000 (10:29 +0100)
committerTom Hughes <tom@compton.nu>
Fri, 31 Aug 2012 09:29:32 +0000 (10:29 +0100)
Rather than requesting a new key every time the zoom or layer
changes, serve up all the entries initially with appropriate
annotations to allow the client to decide which ones to show.

app/assets/javascripts/key.js
app/views/site/key.html.erb
config/routes.rb
test/functional/site_controller_test.rb

index d22738aaab85149b9b3f893ab11d644dbaaec565..daff6eee6981f63fc10c11d03c59fd6309b6ac72 100644 (file)
@@ -4,13 +4,25 @@ $(document).ready(function () {
         title = $(this).text();
 
     function updateMapKey() {
-      $("#sidebar_content").load(url, {
-        layer: map.baseLayer.keyid,
-        zoom: map.getZoom()
+      var mapLayer = map.baseLayer.keyid,
+          mapZoom = map.getZoom();
+
+      $(".mapkey-table-entry").each(function () {
+        var entryLayer = $(this).attr("data-layer"),
+            entryZoomMin = parseInt($(this).attr("data-zoom-min")),
+            entryZoomMax = parseInt($(this).attr("data-zoom-max"));
+
+        if (mapLayer == entryLayer &&
+            mapZoom >= entryZoomMin && mapZoom <= entryZoomMax) {
+          $(this).show();
+        } else {
+          $(this).hide();
+        }
       });
     }
 
-    updateMapKey();
+    $("#sidebar_content").load(url, updateMapKey);
+
     openSidebar({ title: title });
 
     $("#sidebar").one("closed", function () {
index ed36c0186ccdf96e59334e0a30fa76f9a110ac6c..d401b4c34b32f4dc0d35668a01824a69d583d1c3 100644 (file)
@@ -1,19 +1,15 @@
 <div id="mapkey">
   <table class="mapkey-table">
     <% YAML.load_file("#{Rails.root}/config/key.yml").each do |name,data| %>
-      <% if params[:layer] == name %>
-        <% data.each do |entry| %>
-          <% if params[:zoom].to_i >= entry['min_zoom'] && params[:zoom].to_i <= entry['max_zoom'] %>
-            <tr>
-              <td class="mapkey-table-key">
-                <%= image_tag "key/#{name}/#{entry['image']}" %>
-              </td>
-              <td class="mapkey-table-value">
-                <%= [*t("site.key.table.entry.#{entry['name']}")].to_sentence %>
-              </td>
-            </tr>
-          <% end %>
-        <% end %>
+      <% data.each do |entry| %>
+        <tr class="mapkey-table-entry" data-layer="<%= name %>" data-zoom-min="<%= entry['min_zoom'] %>" data-zoom-max="<%= entry['max_zoom'] %>">
+          <td class="mapkey-table-key">
+            <%= image_tag "key/#{name}/#{entry['image']}" %>
+          </td>
+          <td class="mapkey-table-value">
+            <%= [*t("site.key.table.entry.#{entry['name']}")].to_sentence %>
+          </td>
+        </tr>
       <% end %>
     <% end %>
   </table>
index 1ef0c31af4fe978de32d5679a0ff64619478277a..955c5706f924677588d225e5cc7c8b90674f3b79 100644 (file)
@@ -106,7 +106,7 @@ OpenStreetMap::Application.routes.draw do
   match '/login' => 'user#login', :via => [:get, :post]
   match '/logout' => 'user#logout', :via => [:get, :post]
   match '/offline' => 'site#offline', :via => :get
-  match '/key' => 'site#key', :via => :post
+  match '/key' => 'site#key', :via => :get
   match '/user/new' => 'user#new', :via => :get
   match '/user/terms' => 'user#terms', :via => [:get, :post]
   match '/user/save' => 'user#save', :via => :post
index 86445e551a4e0480e3feb0e5a8a41ed9d0949ba3..55dff2d96563a5ad25b1c7733a549669f2f1f4fe 100644 (file)
@@ -47,7 +47,7 @@ class SiteControllerTest < ActionController::TestCase
       { :controller => "site", :action => "offline" }
     )
     assert_routing(
-      { :path => "/key", :method => :post },
+      { :path => "/key", :method => :get },
       { :controller => "site", :action => "key" }
     )
     assert_routing(