Refine changeset browse behavior
authorJohn Firebaugh <john.firebaugh@gmail.com>
Tue, 19 Nov 2013 20:10:00 +0000 (12:10 -0800)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Tue, 19 Nov 2013 20:10:14 +0000 (12:10 -0800)
The general history view shows changesets in the current view
and updates when you move the map. The view for an individual
user, nearby users, or friends zooms the map to the extent of
the results, and doesn't change when you move the map.

app/assets/javascripts/index.js
app/assets/javascripts/index/history.js
app/controllers/changeset_controller.rb
app/views/changeset/list.html.erb
config/locales/en.yml

index 365d33e3abc76d30c392d5855b7a3c607472844d..ba1f08407d1587343bf5b6532faab2ff52a36e6b 100644 (file)
@@ -242,19 +242,18 @@ $(document).ready(function () {
     return page;
   };
 
-  var history = OSM.History(map),
-    note = OSM.Note(map);
+  var history = OSM.History(map);
 
   OSM.route = OSM.Router(map, {
     "/":                           OSM.Index(map),
     "/search":                     OSM.Search(map),
     "/export":                     OSM.Export(map),
-    "/history":                    history,
     "/new_note":                   OSM.NewNote(map),
+    "/history":                    history,
     "/user/:display_name/edits":   history,
     "/browse/friends":             history,
     "/browse/nearby":              history,
-    "/browse/note/:id":            note,
+    "/browse/note/:id":            OSM.Note(map),
     "/browse/:type/:id(/history)": OSM.Browse(map)
   });
 
index 75b02ec07066e1b484a2fa0d739e7bd0ad822cb8..cd012ee160275e896e73b6cdcc9dff263957f10d 100644 (file)
@@ -43,10 +43,16 @@ OSM.History = function(map) {
   }
 
   function loadData() {
+    var data = {};
+
+    if (window.location.pathname === '/history') {
+      data = {bbox: map.getBounds().wrap().toBBoxString()};
+    }
+
     $.ajax({
       url: window.location.pathname,
       method: "GET",
-      data: {bbox: map.getBounds().wrap().toBBoxString()},
+      data: data,
       success: function(html, status, xhr) {
         $('#sidebar_content .changesets').html(html);
         updateMap();
@@ -95,6 +101,11 @@ OSM.History = function(map) {
       rect.id = changeset.id;
       rect.addTo(group);
     }
+
+    if (window.location.pathname !== '/history') {
+      var bounds = group.getBounds();
+      if (bounds.isValid()) map.fitBounds(bounds);
+    }
   }
 
   page.pushstate = page.popstate = function(path) {
@@ -103,19 +114,22 @@ OSM.History = function(map) {
   };
 
   page.load = function() {
-    map
-      .on("moveend", loadData)
-      .addLayer(group);
+    map.addLayer(group);
+
+    if (window.location.pathname === '/history') {
+      map.on("moveend", loadData)
+    }
 
     loadData();
   };
 
   page.unload = function() {
-    map
-      .off("moveend", loadData)
-      .removeLayer(group);
+    map.removeLayer(group);
+
+    if (window.location.pathname === '/history') {
+      map.off("moveend", loadData)
+    }
 
-    group.clearLayers();
     $("#history_tab").removeClass("current");
   };
 
index 6a0ad40a7c02643a4cb096de6a24dc14ffd63d30..63f9f0f7d4745aceb943f1965ce39ffd60ee954e 100644 (file)
@@ -279,20 +279,14 @@ class ChangesetController < ApplicationController
         else
           changesets = changesets.where("false")
         end
-      end
-
-      if params[:friends] && @user
+      elsif params[:bbox]
+        changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
+      elsif params[:friends] && @user
         changesets = changesets.where(:user_id => @user.friend_users.public)
-      end
-
-      if params[:nearby] && @user
+      elsif params[:nearby] && @user
         changesets = changesets.where(:user_id => @user.nearby)
       end
 
-      if params[:bbox]
-        changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
-      end
-
       if params[:max_id]
         changesets = changesets.where("changesets.id <= ?", params[:max_id])
       end
index b0ccf67dc7f271aa5e853536c75cc39ccc4ac42f..68bdf1e23fcc7a3cc2f08d0027c8d6c556ebf54d 100644 (file)
@@ -6,8 +6,10 @@
     <%= link_to t('changeset.list.load_more'), url_for(params.merge(:max_id => @edits.last.id - 1)), :class => "button load_more" %>
     <%= image_tag "searching.gif", :class => "loader", :style => "display: none;" %>
   </div>
-<% elsif params[:max_id] %>
-  <div class="inner22"><%= t('changeset.list.no_more') %></div>
+<% elsif params[:bbox] %>
+  <div class="inner22"><%= t(params[:max_id] ? 'changeset.list.no_more_area' : 'changeset.list.empty_area') %></div>
+<% elsif params[:display_name] %>
+  <div class="inner22"><%= t(params[:max_id] ? 'changeset.list.no_more_user' : 'changeset.list.empty_user') %></div>
 <% else %>
-  <div class="inner22"><%= t('changeset.list.empty') %></div>
+  <div class="inner22"><%= t(params[:max_id] ? 'changeset.list.no_more' : 'changeset.list.empty') %></div>
 <% end %>
index b8a9fe31f9214004fec79f10ee84349139fc70d5..2bfe0c6523685383a48cab0818c8343808d23795 100644 (file)
@@ -214,8 +214,12 @@ en:
       title_user: "Changesets by %{user}"
       title_friend: "Changesets by your friends"
       title_nearby: "Changesets by nearby users"
-      empty: "No changesets in this area."
-      no_more: "No more changesets in this area."
+      empty: "No changesets found."
+      empty_area: "No changesets in this area."
+      empty_user: "No changesets by this user."
+      no_more: "No more changesets found."
+      no_more_area: "No more changesets in this area."
+      no_more_user: "No more changesets by this user."
       load_more: "Load more"
     timeout:
       sorry: "Sorry, the list of changesets you requested took too long to retrieve."