]> git.openstreetmap.org Git - rails.git/commitdiff
Add relation version pages
authorAnton Khorev <tony29@yandex.ru>
Mon, 15 Jan 2024 23:55:18 +0000 (02:55 +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_relations_controller.rb [new file with mode: 0644]
app/views/browse/_relation.html.erb
app/views/browse/_relation_member.html.erb
app/views/old_relations/not_found.html.erb [new file with mode: 0644]
app/views/old_relations/show.html.erb [new file with mode: 0644]
config/locales/en.yml
config/routes.rb
test/controllers/old_relations_controller_test.rb [new file with mode: 0644]

index 643465c5423126d5dfa03f96154637cb93de3107..4a4eee3901def8b8544719e0066e01a57117c8c4 100644 (file)
@@ -8,6 +8,7 @@ class Ability
          :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
index bb471490a26451b87d99be7045c1b1ec92b60320..8ffa05c53e41ebcf88b58acd19e77f36950cf334 100644 (file)
@@ -383,6 +383,7 @@ $(document).ready(function () {
     "/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)
   });
diff --git a/app/controllers/old_relations_controller.rb b/app/controllers/old_relations_controller.rb
new file mode 100644 (file)
index 0000000..9dda820
--- /dev/null
@@ -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
index 8db40c8c74a954fc797eb9889eb6feac429a93a8..c513ea6d1eba6fd666dfea5c017e268341ec4513 100644 (file)
@@ -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>
@@ -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 %>
index 5c96dadaf84d9a31e97cc61c112dcb52ebdf4ad5..5e52c04e89e269ba4183200627e767d79f527c01 100644 (file)
@@ -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?
diff --git a/app/views/old_relations/not_found.html.erb b/app/views/old_relations/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_relations/show.html.erb b/app/views/old_relations/show.html.erb
new file mode 100644 (file)
index 0000000..360011c
--- /dev/null
@@ -0,0 +1,5 @@
+<% 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 %>
index e819aaa9cad34446dc9511a8cb9a52b96369470b..069efb4a4f8cf3a5ee70e5db22110dcc62239f5e 100644 (file)
@@ -434,6 +434,9 @@ en:
   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}"
index b2a9918b37dd8799d6aae3f4ab3d66932abac6a6..09afe8fd928926139b8b80c93f26bd531c535522 100644 (file)
@@ -117,6 +117,7 @@ OpenStreetMap::Application.routes.draw do
   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]
diff --git a/test/controllers/old_relations_controller_test.rb b/test/controllers/old_relations_controller_test.rb
new file mode 100644 (file)
index 0000000..87ee50d
--- /dev/null
@@ -0,0 +1,35 @@
+require "test_helper"
+
+class OldRelationsControllerTest < ActionDispatch::IntegrationTest
+  def test_routes
+    assert_routing(
+      { :path => "/relation/1/history/2", :method => :get },
+      { :controller => "old_relations", :action => "show", :id => "1", :version => "2" }
+    )
+  end
+
+  def test_visible
+    relation = create(:relation, :with_history)
+    get old_relation_path(relation, 1)
+    assert_response :success
+    assert_template "old_relations/show"
+    assert_template :layout => "map"
+  end
+
+  def test_visible_with_members
+    relation = create(:relation, :with_history)
+    create(:old_relation_member, :old_relation => relation.old_relations.first)
+    get old_relation_path(relation, 1)
+    assert_response :success
+    assert_template "old_relations/show"
+    assert_template :layout => "map"
+  end
+
+  def test_not_found
+    get old_relation_path(0, 0)
+    assert_response :not_found
+    assert_template "old_relations/not_found"
+    assert_template :layout => "map"
+    assert_select "#sidebar_content", /relation #0 version 0 could not be found/
+  end
+end