From 00123f05ba0b0c7a41ae3888cd33b68f13e1d662 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 16 Jan 2024 02:55:18 +0300 Subject: [PATCH] Add relation version pages --- app/abilities/ability.rb | 1 + app/assets/javascripts/index.js | 1 + app/controllers/old_relations_controller.rb | 19 ++++++++++ app/views/browse/_relation.html.erb | 4 +-- app/views/browse/_relation_member.html.erb | 2 +- app/views/old_relations/not_found.html.erb | 7 ++++ app/views/old_relations/show.html.erb | 5 +++ config/locales/en.yml | 3 ++ config/routes.rb | 1 + .../old_relations_controller_test.rb | 35 +++++++++++++++++++ 10 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 app/controllers/old_relations_controller.rb create mode 100644 app/views/old_relations/not_found.html.erb create mode 100644 app/views/old_relations/show.html.erb create mode 100644 test/controllers/old_relations_controller_test.rb diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 643465c54..4a4eee390 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -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 diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index bb471490a..8ffa05c53 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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 index 000000000..9dda82021 --- /dev/null +++ b/app/controllers/old_relations_controller.rb @@ -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 diff --git a/app/views/browse/_relation.html.erb b/app/views/browse/_relation.html.erb index 8db40c8c7..c513ea6d1 100644 --- a/app/views/browse/_relation.html.erb +++ b/app/views/browse/_relation.html.erb @@ -8,7 +8,7 @@ <% else %>
- <%= render :partial => "common_details", :object => relation %> + <%= render :partial => "browse/common_details", :object => relation %> <% unless relation.containing_relation_members.empty? %>

<%= t "browse.part_of" %>

@@ -25,7 +25,7 @@
> <%= t ".members_count", :count => relation.relation_members.count %>
    - <%= render :partial => "relation_member", :collection => relation.relation_members %> + <%= render :partial => "browse/relation_member", :collection => relation.relation_members %>
<% end %> diff --git a/app/views/browse/_relation_member.html.erb b/app/views/browse/_relation_member.html.erb index 5c96dadaf..5e52c04e8 100644 --- a/app/views/browse/_relation_member.html.erb +++ b/app/views/browse/_relation_member.html.erb @@ -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}" %>
  • <%= 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 index 000000000..1ee5d9d3f --- /dev/null +++ b/app/views/old_relations/not_found.html.erb @@ -0,0 +1,7 @@ +<% set_title(t("browse.not_found.title")) %> + +<%= render "sidebar_header", :title => t("browse.not_found.title") %> + +
    +

    <%= t ".sorry", :id => params[:id], :version => params[:version] %>

    +
    diff --git a/app/views/old_relations/show.html.erb b/app/views/old_relations/show.html.erb new file mode 100644 index 000000000..360011ca2 --- /dev/null +++ b/app/views/old_relations/show.html.erb @@ -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 %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e819aaa9c..069efb4a4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}" diff --git a/config/routes.rb b/config/routes.rb index b2a9918b3..09afe8fd9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 index 000000000..87ee50db4 --- /dev/null +++ b/test/controllers/old_relations_controller_test.rb @@ -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 -- 2.39.5