]> git.openstreetmap.org Git - rails.git/commitdiff
Add way version pages
authorAnton Khorev <tony29@yandex.ru>
Mon, 15 Jan 2024 15:20:23 +0000 (18:20 +0300)
committerAnton Khorev <tony29@yandex.ru>
Tue, 23 Jan 2024 19:08:39 +0000 (22:08 +0300)
app/abilities/ability.rb
app/assets/javascripts/index.js
app/controllers/old_ways_controller.rb [new file with mode: 0644]
app/views/browse/_way.html.erb
app/views/old_ways/not_found.html.erb [new file with mode: 0644]
app/views/old_ways/show.html.erb [new file with mode: 0644]
config/locales/en.yml
config/routes.rb
test/controllers/old_ways_controller_test.rb [new file with mode: 0644]

index b601e66f045130bc958219e04b2a28af887b52c5..643465c5423126d5dfa03f96154637cb93de3107 100644 (file)
@@ -7,6 +7,7 @@ class Ability
     can [:relation, :relation_history, :way, :way_history, :node, :node_history,
          :changeset, :query], :browse
     can [:show], OldNode
+    can [:show], OldWay
     can [:show, :new], Note
     can :search, :direction
     can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site
index 621054caf6a01c312fc9b6ae3e6402671cb13b90..bb471490a26451b87d99be7045c1b1ec92b60320 100644 (file)
@@ -381,6 +381,7 @@ $(document).ready(function () {
     "/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"),
     "/changeset/:id": OSM.Changeset(map),
     "/query": OSM.Query(map)
diff --git a/app/controllers/old_ways_controller.rb b/app/controllers/old_ways_controller.rb
new file mode 100644 (file)
index 0000000..d18121e
--- /dev/null
@@ -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
index 4fdcd035ecf5c75296f624d124557531683ce952..26403f3fdcff27a52ed10664e67ac55929ec2320 100644 (file)
@@ -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>
         <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 %>
diff --git a/app/views/old_ways/not_found.html.erb b/app/views/old_ways/not_found.html.erb
new file mode 100644 (file)
index 0000000..1ee5d9d
--- /dev/null
@@ -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>
diff --git a/app/views/old_ways/show.html.erb b/app/views/old_ways/show.html.erb
new file mode 100644 (file)
index 0000000..fa69871
--- /dev/null
@@ -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 %>
index 6df0260cddc926914483b09d03b158fc4ae6965f..e819aaa9cad34446dc9511a8cb9a52b96369470b 100644 (file)
@@ -431,6 +431,9 @@ en:
   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."
   changesets:
     changeset_paging_nav:
       showing_page: "Page %{page}"
index 29c260c9eefe09245f4d8a6bacc194856b26f6a3..b2a9918b37dd8799d6aae3f4ab3d66932abac6a6 100644 (file)
@@ -111,6 +111,7 @@ OpenStreetMap::Application.routes.draw do
   # 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
diff --git a/test/controllers/old_ways_controller_test.rb b/test/controllers/old_ways_controller_test.rb
new file mode 100644 (file)
index 0000000..897bdba
--- /dev/null
@@ -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