Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/4480'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jan 23, 2024
2 parents 6163b01 + 8f1ffeb commit 2acf8cb
Show file tree
Hide file tree
Showing 24 changed files with 509 additions and 22 deletions.
3 changes: 3 additions & 0 deletions app/abilities/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Ability
def initialize(user)
can [:relation, :relation_history, :way, :way_history, :node, :node_history,
:changeset, :query], :browse
can [:show], OldNode
can [:show], OldWay
can [:show], OldRelation
can [:show, :new], Note
can :search, :direction
can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
Expand Down
13 changes: 13 additions & 0 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@ $(document).ready(function () {
return page;
};

OSM.OldBrowse = function () {
var page = {};

page.pushstate = page.popstate = function (path) {
OSM.loadSidebarContent(path);
};

return page;
};

var history = OSM.History(map);

OSM.router = OSM.Router(map, {
Expand All @@ -369,8 +379,11 @@ $(document).ready(function () {
"/user/:display_name/history": history,
"/note/:id": OSM.Note(map),
"/node/:id(/history)": OSM.Browse(map, "node"),
"/node/:id/history/:version": OSM.OldBrowse(),
"/way/:id(/history)": OSM.Browse(map, "way"),
"/way/:id/history/:version": OSM.OldBrowse(),
"/relation/:id(/history)": OSM.Browse(map, "relation"),
"/relation/:id/history/:version": OSM.OldBrowse(),
"/changeset/:id": OSM.Changeset(map),
"/query": OSM.Query(map)
});
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/old_nodes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class OldNodesController < ApplicationController
layout :map_layout

before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth

authorize_resource

around_action :web_timeout

def show
@type = "node"
@feature = OldNode.preload(:old_tags, :changeset => [:changeset_tags, :user]).find([params[:id], params[:version]])
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
end
19 changes: 19 additions & 0 deletions app/controllers/old_relations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class OldRelationsController < ApplicationController
layout :map_layout

before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth

authorize_resource

around_action :web_timeout

def show
@type = "relation"
@feature = OldRelation.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_members => :member).find([params[:id], params[:version]])
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
end
19 changes: 19 additions & 0 deletions app/controllers/old_ways_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class OldWaysController < ApplicationController
layout :map_layout

before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth

authorize_resource

around_action :web_timeout

def show
@type = "way"
@feature = OldWay.preload(:old_tags, :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] }).find([params[:id], params[:version]])
rescue ActiveRecord::RecordNotFound
render :action => "not_found", :status => :not_found
end
end
6 changes: 3 additions & 3 deletions app/views/browse/_common_details.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h4>
<%= t "browse.version" %>
#<%= common_details.version %>
#<%= link_to_unless_current common_details.version, :controller => "old_#{@type.pluralize}", :action => :show, :version => common_details.version %>
</h4>

<p class="fst-italic">
Expand All @@ -19,7 +19,7 @@
</li>
<li>
<%= t "browse.in_changeset" %>
#<%= link_to common_details.changeset_id, :action => :changeset, :id => common_details.changeset_id %>
#<%= link_to common_details.changeset_id, changeset_path(common_details.changeset) %>
</li>

<% if @type == "node" and common_details.visible? %>
Expand All @@ -33,4 +33,4 @@
<% end %>
</ul>

<%= render :partial => "tag_details", :object => common_details.tags %>
<%= render :partial => "browse/tag_details", :object => common_details.tags %>
6 changes: 3 additions & 3 deletions app/views/browse/_node.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<% else %>
<div class="browse-section browse-node">
<%= render :partial => "common_details", :object => node %>
<%= render :partial => "browse/common_details", :object => node %>
<% unless node.ways.empty? and node.containing_relation_members.empty? %>
<h4><%= t "browse.part_of" %></h4>
Expand All @@ -17,7 +17,7 @@
<summary><%= t "browse.part_of_ways", :count => node.ways.uniq.count %></summary>
<ul class="list-unstyled">
<% node.ways.uniq.each do |way| %>
<li><%= link_to printable_name(way), { :action => "way", :id => way.id.to_s }, { :class => link_class("way", way), :title => link_title(way) } %></li>
<li><%= link_to printable_name(way), way_path(way), { :class => link_class("way", way), :title => link_title(way) } %></li>
<% end %>
</ul>
</details>
Expand All @@ -26,7 +26,7 @@
<details <%= "open" if node.containing_relation_members.count < 10 %>>
<summary><%= t "browse.part_of_relations", :count => node.containing_relation_members.uniq.count %></summary>
<ul class="list-unstyled">
<%= render :partial => "containing_relation", :collection => node.containing_relation_members.uniq %>
<%= render :partial => "browse/containing_relation", :collection => node.containing_relation_members.uniq %>
</ul>
</details>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/browse/_relation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<% else %>
<div class="browse-section browse-relation">
<%= render :partial => "common_details", :object => relation %>
<%= render :partial => "browse/common_details", :object => relation %>
<% unless relation.containing_relation_members.empty? %>
<h4><%= t "browse.part_of" %></h4>
Expand All @@ -25,7 +25,7 @@
<details <%= "open" if relation.relation_members.count < 10 %>>
<summary><%= t ".members_count", :count => relation.relation_members.count %></summary>
<ul class="list-unstyled">
<%= render :partial => "relation_member", :collection => relation.relation_members %>
<%= render :partial => "browse/relation_member", :collection => relation.relation_members %>
</ul>
</details>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/browse/_relation_member.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% member_class = link_class(relation_member.member_type.downcase, relation_member.member)
linked_name = link_to printable_name(relation_member.member), { :action => relation_member.member_type.downcase, :id => relation_member.member_id.to_s }, { :title => link_title(relation_member.member), :rel => link_follow(relation_member.member) }
linked_name = link_to printable_name(relation_member.member), { :controller => :browse, :action => relation_member.member_type.downcase, :id => relation_member.member_id.to_s }, { :title => link_title(relation_member.member), :rel => link_follow(relation_member.member) }
type_str = t ".type.#{relation_member.member_type.downcase}" %>
<li class="<%= member_class %>">
<%= if relation_member.member_role.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/views/browse/_tag_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h4><%= t ".tags" %></h4>
<div class='mb-3 border border-grey rounded overflow-hidden'>
<table class='mb-0 browse-tag-list table align-middle text-break'>
<%= render :partial => "tag", :collection => tag_details.sort %>
<%= render :partial => "browse/tag", :collection => tag_details.sort %>
</table>
</div>
<% end %>
6 changes: 3 additions & 3 deletions app/views/browse/_way.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
<% else %>
<div class="browse-section browse-way">
<%= render :partial => "common_details", :object => way %>
<%= render :partial => "browse/common_details", :object => way %>
<% unless way.containing_relation_members.empty? %>
<h4><%= t "browse.part_of" %></h4>
Expand All @@ -27,10 +27,10 @@
<ul class="list-unstyled">
<% way.way_nodes.each do |wn| %>
<li>
<%= link_to printable_name(wn.node), { :action => "node", :id => wn.node_id.to_s }, { :class => link_class("node", wn.node), :title => link_title(wn.node), :rel => link_follow(wn.node) } %>
<%= link_to printable_name(wn.node), node_path(wn.node), { :class => link_class("node", wn.node), :title => link_title(wn.node), :rel => link_follow(wn.node) } %>
<% related_ways = wn.node.ways.reject { |w| w.id == wn.way_id } %>
<% if related_ways.size > 0 then %>
(<%= t ".also_part_of_html", :count => related_ways.size, :related_ways => to_sentence(related_ways.map { |w| link_to(printable_name(w), { :action => "way", :id => w.id.to_s }, { :class => link_class("way", w), :title => link_title(w) }) }) %>)
(<%= t ".also_part_of_html", :count => related_ways.size, :related_ways => to_sentence(related_ways.map { |w| link_to(printable_name(w), way_path(w), { :class => link_class("way", w), :title => link_title(w) }) }) %>)
<% end %>
</li>
<% end %>
Expand Down
15 changes: 12 additions & 3 deletions app/views/browse/feature.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@
<%= render :partial => @type, :object => @feature %>
<div class='secondary-actions'>
<% if @feature.visible? %>
<% if @feature.visible? %>
<div class='secondary-actions'>
<%= link_to(t("browse.download_xml"), :controller => "api/#{@type.pluralize}", :action => :show) %>
</div>
<% end %>
<div class='secondary-actions'>
<% if @feature.version > 1 %>
<%= link_to "<< #{t('browse.version')} #1", :controller => "old_#{@type.pluralize}", :action => :show, :version => 1 %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), :action => "#{@type}_history" %>
<% if @feature.version > 1 %>
&middot;
<%= link_to "#{t('browse.version')} ##{@feature.version} >>", :controller => "old_#{@type.pluralize}", :action => :show, :version => @feature.version %>
<% end %>
<%= link_to(t("browse.view_history"), :action => "#{@type}_history") %>
</div>
7 changes: 7 additions & 0 deletions app/views/old_nodes/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% set_title(t("browse.not_found.title")) %>
<%= render "sidebar_header", :title => t("browse.not_found.title") %>

<div>
<p><%= t ".sorry", :id => params[:id], :version => params[:version] %></p>
</div>
25 changes: 25 additions & 0 deletions app/views/old_nodes/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% set_title t("browse.node.title_html", :name => printable_name(@feature)) %>
<%= render "sidebar_header", :title => t("browse.node.title_html", :name => printable_name(@feature)) %>
<%= render :partial => "browse/node", :object => @feature %>

<div class='secondary-actions'>
<% unless @feature.redacted? %>
<%= link_to t("browse.download_xml"), node_version_path(*@feature.id) %>
&middot;
<% end %>
<%= link_to t("browse.view_details"), node_path(@feature.node_id) %>
</div>

<div class='secondary-actions'>
<% if @feature.version > 1 %>
<%= link_to "<< #{t('browse.version')} ##{@feature.version - 1}", old_node_path(@feature.node_id, @feature.version - 1) %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), node_history_path(@feature.node_id) %>
<% if @feature.version < @feature.current_node.version %>
&middot;
<%= link_to "#{t('browse.version')} ##{@feature.version + 1} >>", old_node_path(@feature.node_id, @feature.version + 1) %>
<% end %>
</div>
7 changes: 7 additions & 0 deletions app/views/old_relations/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% set_title(t("browse.not_found.title")) %>
<%= render "sidebar_header", :title => t("browse.not_found.title") %>

<div>
<p><%= t ".sorry", :id => params[:id], :version => params[:version] %></p>
</div>
25 changes: 25 additions & 0 deletions app/views/old_relations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% set_title t("browse.relation.title_html", :name => printable_name(@feature)) %>
<%= render "sidebar_header", :title => t("browse.relation.title_html", :name => printable_name(@feature)) %>
<%= render :partial => "browse/relation", :object => @feature %>

<div class='secondary-actions'>
<% unless @feature.redacted? %>
<%= link_to t("browse.download_xml"), relation_version_path(*@feature.id) %>
&middot;
<% end %>
<%= link_to t("browse.view_details"), relation_path(@feature.relation_id) %>
</div>

<div class='secondary-actions'>
<% if @feature.version > 1 %>
<%= link_to "<< #{t('browse.version')} ##{@feature.version - 1}", old_relation_path(@feature.relation_id, @feature.version - 1) %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), relation_history_path(@feature.relation_id) %>
<% if @feature.version < @feature.current_relation.version %>
&middot;
<%= link_to "#{t('browse.version')} ##{@feature.version + 1} >>", old_relation_path(@feature.relation_id, @feature.version + 1) %>
<% end %>
</div>
7 changes: 7 additions & 0 deletions app/views/old_ways/not_found.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% set_title(t("browse.not_found.title")) %>
<%= render "sidebar_header", :title => t("browse.not_found.title") %>

<div>
<p><%= t ".sorry", :id => params[:id], :version => params[:version] %></p>
</div>
25 changes: 25 additions & 0 deletions app/views/old_ways/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<% set_title t("browse.way.title_html", :name => printable_name(@feature)) %>
<%= render "sidebar_header", :title => t("browse.way.title_html", :name => printable_name(@feature)) %>
<%= render :partial => "browse/way", :object => @feature %>

<div class='secondary-actions'>
<% unless @feature.redacted? %>
<%= link_to t("browse.download_xml"), way_version_path(*@feature.id) %>
&middot;
<% end %>
<%= link_to t("browse.view_details"), way_path(@feature.way_id) %>
</div>

<div class='secondary-actions'>
<% if @feature.version > 1 %>
<%= link_to "<< #{t('browse.version')} ##{@feature.version - 1}", old_way_path(@feature.way_id, @feature.version - 1) %>
&middot;
<% end %>
<%= link_to t("browse.view_history"), way_history_path(@feature.way_id) %>
<% if @feature.version < @feature.current_way.version %>
&middot;
<%= link_to "#{t('browse.version')} ##{@feature.version + 1} >>", old_way_path(@feature.way_id, @feature.version + 1) %>
<% end %>
</div>
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,15 @@ en:
introduction: "Click on the map to find nearby features."
nearby: "Nearby features"
enclosing: "Enclosing features"
old_nodes:
not_found:
sorry: "Sorry, node #%{id} version %{version} could not be found."
old_ways:
not_found:
sorry: "Sorry, way #%{id} version %{version} could not be found."
old_relations:
not_found:
sorry: "Sorry, relation #%{id} version %{version} could not be found."
changesets:
changeset_paging_nav:
showing_page: "Page %{page}"
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@
# Data browsing
get "/way/:id" => "browse#way", :id => /\d+/, :as => :way
get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history
resources :old_ways, :path => "/way/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "/node/:id" => "browse#node", :id => /\d+/, :as => :node
get "/node/:id/history" => "browse#node_history", :id => /\d+/, :as => :node_history
resources :old_nodes, :path => "/node/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "/relation/:id" => "browse#relation", :id => /\d+/, :as => :relation
get "/relation/:id/history" => "browse#relation_history", :id => /\d+/, :as => :relation_history
resources :old_relations, :path => "/relation/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show
get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/
get "/changeset/:id/comments/feed" => "changeset_comments#index", :as => :changeset_comments_feed, :id => /\d*/, :defaults => { :format => "rss" }
resources :notes, :path => "note", :only => [:show, :new]
Expand Down
Loading

0 comments on commit 2acf8cb

Please sign in to comment.