diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb
index 9516a30126..30346d39d0 100644
--- a/app/abilities/ability.rb
+++ b/app/abilities/ability.rb
@@ -30,7 +30,7 @@ def initialize(user)
if user&.active?
can :welcome, :site
- can :read, :deletion
+ can :read, [:deletion, :account_home]
if Settings.status != "database_offline"
can [:subscribe, :unsubscribe], Changeset
diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js
index 56495b31a3..efdef7891d 100644
--- a/app/assets/javascripts/index.js
+++ b/app/assets/javascripts/index.js
@@ -21,6 +21,7 @@
//= require index/directions
//= require index/changeset
//= require index/query
+//= require index/home
//= require router
//= require qs/dist/qs
@@ -226,16 +227,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,
@@ -368,7 +359,8 @@ $(document).ready(function () {
"/relation/:id(/history)": OSM.Browse(map, "relation"),
"/relation/:id/history/:version": OSM.OldBrowse(),
"/changeset/:id": OSM.Changeset(map),
- "/query": OSM.Query(map)
+ "/query": OSM.Query(map),
+ "/account/home": OSM.Home(map)
});
if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
diff --git a/app/assets/javascripts/index/home.js b/app/assets/javascripts/index/home.js
new file mode 100644
index 0000000000..daed04e982
--- /dev/null
+++ b/app/assets/javascripts/index/home.js
@@ -0,0 +1,38 @@
+OSM.Home = function (map) {
+ var marker;
+
+ function clearMarker() {
+ if (marker) map.removeLayer(marker);
+ marker = null;
+ }
+
+ var page = {};
+
+ page.pushstate = page.popstate = page.load = function () {
+ map.setSidebarOverlaid(true);
+ clearMarker();
+
+ if (OSM.home) {
+ OSM.router.withoutMoveListener(function () {
+ map.setView(OSM.home, 15, { reset: true });
+ });
+ marker = L.marker(OSM.home, {
+ icon: OSM.getUserIcon(),
+ title: I18n.t("javascripts.home.marker_title")
+ }).addTo(map);
+ } else {
+ $("#browse_status").html(
+ $("
").text(
+ I18n.t("javascripts.home.not_set")
+ )
+ );
+ }
+ };
+
+ page.unload = function () {
+ clearMarker();
+ $("#browse_status").empty();
+ };
+
+ return page;
+};
diff --git a/app/controllers/accounts/homes_controller.rb b/app/controllers/accounts/homes_controller.rb
new file mode 100644
index 0000000000..e31cce7461
--- /dev/null
+++ b/app/controllers/accounts/homes_controller.rb
@@ -0,0 +1,13 @@
+module Accounts
+ class HomesController < ApplicationController
+ layout :map_layout
+
+ before_action :authorize_web
+ before_action :set_locale
+ before_action :require_oauth
+
+ authorize_resource :class => :account_home
+
+ def show; end
+ end
+end
diff --git a/app/views/accounts/homes/show.html.erb b/app/views/accounts/homes/show.html.erb
new file mode 100644
index 0000000000..ea6ee70884
--- /dev/null
+++ b/app/views/accounts/homes/show.html.erb
@@ -0,0 +1 @@
+<% content_for(:content_class) { "overlay-sidebar" } %>
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb
index 45e23fc2b9..592787316d 100644
--- a/app/views/layouts/_header.html.erb
+++ b/app/views/layouts/_header.html.erb
@@ -104,7 +104,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 e17ea4ed82..72f6076b45 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/config/locales/en.yml b/config/locales/en.yml
index 32b0bc6bcc..7ee8393867 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3283,6 +3283,9 @@ en:
show_address: Show address
query_features: Query features
centre_map: Centre map here
+ home:
+ marker_title: My home location
+ not_set: Home location is not set for your account
redactions:
edit:
heading: "Edit Redaction"
diff --git a/config/routes.rb b/config/routes.rb
index 9cb3a63edc..f826bd112e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -280,6 +280,7 @@
scope :module => :accounts do
resource :terms, :only => [:show, :update]
resource :deletion, :only => :show
+ resource :home, :only => :show
end
end
diff --git a/test/system/account_home_test.rb b/test/system/account_home_test.rb
new file mode 100644
index 0000000000..813c45ec8d
--- /dev/null
+++ b/test/system/account_home_test.rb
@@ -0,0 +1,57 @@
+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
+
+ test "account home page shows a warning when visited by users without home location" do
+ user = create(:user, :display_name => "test user")
+ sign_in_as(user)
+
+ visit account_home_path
+ assert_no_selector "img.leaflet-marker-icon"
+ assert_text "Home location is not set"
+ end
+end