Add way version pages

This commit is contained in:
Anton Khorev 2024-01-15 18:20:23 +03:00
parent 85c284aaa6
commit 2f222c49dd
9 changed files with 80 additions and 3 deletions

View file

@ -7,6 +7,7 @@ class Ability
can [:relation, :relation_history, :way, :way_history, :node, :node_history, can [:relation, :relation_history, :way, :way_history, :node, :node_history,
:changeset, :query], :browse :changeset, :query], :browse
can [:show], OldNode can [:show], OldNode
can [:show], OldWay
can [:show, :new], Note can [:show, :new], Note
can :search, :direction can :search, :direction
can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site

View file

@ -381,6 +381,7 @@ $(document).ready(function () {
"/node/:id(/history)": OSM.Browse(map, "node"), "/node/:id(/history)": OSM.Browse(map, "node"),
"/node/:id/history/:version": OSM.OldBrowse(), "/node/:id/history/:version": OSM.OldBrowse(),
"/way/:id(/history)": OSM.Browse(map, "way"), "/way/:id(/history)": OSM.Browse(map, "way"),
"/way/:id/history/:version": OSM.OldBrowse(),
"/relation/:id(/history)": OSM.Browse(map, "relation"), "/relation/:id(/history)": OSM.Browse(map, "relation"),
"/changeset/:id": OSM.Changeset(map), "/changeset/:id": OSM.Changeset(map),
"/query": OSM.Query(map) "/query": OSM.Query(map)

View file

@ -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

View file

@ -8,7 +8,7 @@
</div> </div>
<% else %> <% else %>
<div class="browse-section browse-way"> <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? %> <% unless way.containing_relation_members.empty? %>
<h4><%= t "browse.part_of" %></h4> <h4><%= t "browse.part_of" %></h4>
@ -27,10 +27,10 @@
<ul class="list-unstyled"> <ul class="list-unstyled">
<% way.way_nodes.each do |wn| %> <% way.way_nodes.each do |wn| %>
<li> <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 } %> <% related_ways = wn.node.ways.reject { |w| w.id == wn.way_id } %>
<% if related_ways.size > 0 then %> <% 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 %> <% end %>
</li> </li>
<% end %> <% end %>

View file

@ -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>

View file

@ -0,0 +1,5 @@
<% 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 %>

View file

@ -431,6 +431,9 @@ en:
old_nodes: old_nodes:
not_found: not_found:
sorry: "Sorry, node #%{id} version %{version} could not be 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."
changesets: changesets:
changeset_paging_nav: changeset_paging_nav:
showing_page: "Page %{page}" showing_page: "Page %{page}"

View file

@ -111,6 +111,7 @@ OpenStreetMap::Application.routes.draw do
# Data browsing # Data browsing
get "/way/:id" => "browse#way", :id => /\d+/, :as => :way get "/way/:id" => "browse#way", :id => /\d+/, :as => :way
get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history 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" => "browse#node", :id => /\d+/, :as => :node
get "/node/:id/history" => "browse#node_history", :id => /\d+/, :as => :node_history 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 resources :old_nodes, :path => "/node/:id/history", :id => /\d+/, :version => /\d+/, :param => :version, :only => :show

View file

@ -0,0 +1,40 @@
require "test_helper"
class OldWaysControllerTest < ActionDispatch::IntegrationTest
def test_routes
assert_routing(
{ :path => "/way/1/history/2", :method => :get },
{ :controller => "old_ways", :action => "show", :id => "1", :version => "2" }
)
end
def test_visible
way = create(:way, :with_history)
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_template :layout => "map"
end
def test_visible_with_shared_nodes
node = create(:node, :with_history)
way = create(:way, :with_history)
create(:way_node, :way => way, :node => node)
create(:old_way_node, :old_way => way.old_ways.first, :node => node)
sharing_way = create(:way, :with_history)
create(:way_node, :way => sharing_way, :node => node)
create(:old_way_node, :old_way => sharing_way.old_ways.first, :node => node)
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_template :layout => "map"
end
def test_not_found
get old_way_path(0, 0)
assert_response :not_found
assert_template "old_ways/not_found"
assert_template :layout => "map"
assert_select "#sidebar_content", /way #0 version 0 could not be found/
end
end