Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home Location page #4926

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//= require index/directions
//= require index/changeset
//= require index/query
//= require index/home
//= require router
//= require qs/dist/qs

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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") {
Expand Down
38 changes: 38 additions & 0 deletions app/assets/javascripts/index/home.js
Original file line number Diff line number Diff line change
@@ -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(
$("<div class='m-2 alert alert-warning'>").text(
I18n.t("javascripts.home.not_set")
)
);
}
};

page.unload = function () {
clearMarker();
$("#browse_status").empty();
};

return page;
};
13 changes: 13 additions & 0 deletions app/controllers/accounts/homes_controller.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/views/accounts/homes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% content_for(:content_class) { "overlay-sidebar" } %>
4 changes: 3 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
<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>
Expand Down
12 changes: 0 additions & 12 deletions app/views/layouts/map.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
scope :module => :accounts do
resource :terms, :only => [:show, :update]
resource :deletion, :only => :show
resource :home, :only => :show
end
end

Expand Down
57 changes: 57 additions & 0 deletions test/system/account_home_test.rb
Original file line number Diff line number Diff line change
@@ -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
Loading