]> git.openstreetmap.org Git - rails.git/commitdiff
Add "Go to Home Location" to every page, link it to account home page
authorAnton Khorev <tony29@yandex.ru>
Thu, 27 Jun 2024 00:37:13 +0000 (03:37 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 15 Feb 2025 16:02:30 +0000 (19:02 +0300)
app/assets/javascripts/index.js
app/views/layouts/_header.html.erb
app/views/layouts/map.html.erb
test/system/account_home_test.rb [new file with mode: 0644]

index fc8882a910300414f174e4068e9cda993b5cdb7d..9b825caad0aa77c76932cc3d0c163f6d4d66537c 100644 (file)
@@ -214,16 +214,6 @@ $(document).ready(function () {
     L.marker([params.mlat, params.mlon]).addTo(map);
   }
 
     L.marker([params.mlat, params.mlon]).addTo(map);
   }
 
-  $("#homeanchor").on("click", function (e) {
-    e.preventDefault();
-
-    var data = $(this).data(),
-        center = L.latLng(data.lat, data.lon);
-
-    map.setView(center, data.zoom);
-    L.marker(center, { icon: OSM.getUserIcon() }).addTo(map);
-  });
-
   function remoteEditHandler(bbox, object) {
     var remoteEditHost = "http://127.0.0.1:8111",
         osmHost = location.protocol + "//" + location.host,
   function remoteEditHandler(bbox, object) {
     var remoteEditHost = "http://127.0.0.1:8111",
         osmHost = location.protocol + "//" + location.host,
index aa524938181c32cdb210fdb1c1cb9168b056b58d..1f5856908abed577e1a18c580b94a7c679dfeb51 100644 (file)
@@ -88,7 +88,9 @@
           <%= link_to t("users.show.my settings"), edit_account_path, :class => "dropdown-item" %>
           <%= link_to t("users.show.my_preferences"), preferences_path, :class => "dropdown-item" %>
           <div class="dropdown-divider"></div>
           <%= link_to t("users.show.my settings"), edit_account_path, :class => "dropdown-item" %>
           <%= link_to t("users.show.my_preferences"), preferences_path, :class => "dropdown-item" %>
           <div class="dropdown-divider"></div>
-          <%= yield :greeting %>
+          <% if current_user.home_location? %>
+            <%= link_to t("layouts.home"), account_home_path, :class => "dropdown-item" %>
+          <% end %>
           <%= link_to t("layouts.logout"), logout_path(:referer => request.fullpath), :method => "post", :class => "geolink dropdown-item" %>
         </div>
       </div>
           <%= link_to t("layouts.logout"), logout_path(:referer => request.fullpath), :method => "post", :class => "geolink dropdown-item" %>
         </div>
       </div>
index e17ea4ed826bf2f9593973f766dd76f8ba54d4c0..72f6076b45850999df682013efd1b0e9e60b2aa5 100644 (file)
@@ -4,18 +4,6 @@
 
 <% content_for(:body_class) { "map-layout" } %>
 
 
 <% content_for(:body_class) { "map-layout" } %>
 
-<% if current_user&.home_location? %>
-  <% content_for :greeting do %>
-    <%= link_to t("layouts.home"),
-                "#",
-                :id => "homeanchor",
-                :class => "set_position dropdown-item",
-                :data => { :lat => current_user.home_lat,
-                           :lon => current_user.home_lon,
-                           :zoom => 15 } %>
-  <% end %>
-<% end %>
-
 <% content_for :header do %>
   <%= render :partial => "layouts/search", :locals => { :autofocus => false } %>
 <% end %>
 <% content_for :header do %>
   <%= render :partial => "layouts/search", :locals => { :autofocus => false } %>
 <% end %>
diff --git a/test/system/account_home_test.rb b/test/system/account_home_test.rb
new file mode 100644 (file)
index 0000000..0d0e106
--- /dev/null
@@ -0,0 +1,48 @@
+require "application_system_test_case"
+
+class AccountHomeTest < ApplicationSystemTestCase
+  test "Go to Home Location works on map layout pages" do
+    user = create(:user, :display_name => "test user", :home_lat => 60, :home_lon => 30)
+    sign_in_as(user)
+
+    visit root_path
+    assert_no_selector "img.leaflet-marker-icon"
+
+    click_on "test user"
+    click_on "Go to Home Location"
+    all "img.leaflet-marker-icon", :count => 1 do |marker|
+      assert_equal "My home location", marker["title"]
+    end
+
+    click_on "OpenStreetMap logo"
+    assert_no_selector "img.leaflet-marker-icon"
+  end
+
+  test "Go to Home Location works on non-map layout pages" do
+    user = create(:user, :display_name => "test user", :home_lat => 60, :home_lon => 30)
+    sign_in_as(user)
+
+    visit about_path
+    assert_no_selector "img.leaflet-marker-icon"
+
+    click_on "test user"
+    click_on "Go to Home Location"
+    all "img.leaflet-marker-icon", :count => 1 do |marker|
+      assert_equal "My home location", marker["title"]
+    end
+
+    click_on "OpenStreetMap logo"
+    assert_no_selector "img.leaflet-marker-icon"
+  end
+
+  test "Go to Home Location is not available for users without home location" do
+    user = create(:user, :display_name => "test user")
+    sign_in_as(user)
+
+    visit root_path
+    assert_no_selector "img.leaflet-marker-icon"
+
+    click_on "test user"
+    assert_no_link "Go to Home Location"
+  end
+end