From: Anton Khorev Date: Thu, 27 Jun 2024 00:37:13 +0000 (+0300) Subject: Add "Go to Home Location" to every page, link it to account home page X-Git-Tag: live~132^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5c019cd2eef41a4e75a2640f19f674431cf67733?hp=-c Add "Go to Home Location" to every page, link it to account home page --- 5c019cd2eef41a4e75a2640f19f674431cf67733 diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index fc8882a91..9b825caad 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -214,16 +214,6 @@ $(document).ready(function () { 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, diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index aa5249381..1f5856908 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -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" %> - <%= 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" %> diff --git a/app/views/layouts/map.html.erb b/app/views/layouts/map.html.erb index e17ea4ed8..72f6076b4 100644 --- a/app/views/layouts/map.html.erb +++ b/app/views/layouts/map.html.erb @@ -4,18 +4,6 @@ <% 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 %> diff --git a/test/system/account_home_test.rb b/test/system/account_home_test.rb new file mode 100644 index 000000000..0d0e10615 --- /dev/null +++ b/test/system/account_home_test.rb @@ -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