From 85c284aaa6e9ba8488de9d488f17fda4cd565d9c Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sun, 14 Jan 2024 02:05:36 +0300 Subject: [PATCH] Add node version pages --- app/abilities/ability.rb | 1 + app/assets/javascripts/index.js | 11 ++++++++ app/controllers/old_nodes_controller.rb | 19 ++++++++++++++ app/views/browse/_common_details.html.erb | 4 +-- app/views/browse/_node.html.erb | 6 ++--- app/views/browse/_tag_details.html.erb | 2 +- app/views/old_nodes/not_found.html.erb | 7 +++++ app/views/old_nodes/show.html.erb | 5 ++++ config/locales/en.yml | 3 +++ config/routes.rb | 1 + test/controllers/old_nodes_controller_test.rb | 26 +++++++++++++++++++ 11 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 app/controllers/old_nodes_controller.rb create mode 100644 app/views/old_nodes/not_found.html.erb create mode 100644 app/views/old_nodes/show.html.erb create mode 100644 test/controllers/old_nodes_controller_test.rb diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index c7080595c..b601e66f0 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -6,6 +6,7 @@ class Ability def initialize(user) can [:relation, :relation_history, :way, :way_history, :node, :node_history, :changeset, :query], :browse + can [:show], OldNode 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 706647ef5..621054caf 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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, { @@ -369,6 +379,7 @@ $(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"), "/relation/:id(/history)": OSM.Browse(map, "relation"), "/changeset/:id": OSM.Changeset(map), diff --git a/app/controllers/old_nodes_controller.rb b/app/controllers/old_nodes_controller.rb new file mode 100644 index 000000000..a5b9cf563 --- /dev/null +++ b/app/controllers/old_nodes_controller.rb @@ -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 diff --git a/app/views/browse/_common_details.html.erb b/app/views/browse/_common_details.html.erb index 4726799e7..b28e72c75 100644 --- a/app/views/browse/_common_details.html.erb +++ b/app/views/browse/_common_details.html.erb @@ -19,7 +19,7 @@
  • <%= 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) %>
  • <% if @type == "node" and common_details.visible? %> @@ -33,4 +33,4 @@ <% end %> -<%= render :partial => "tag_details", :object => common_details.tags %> +<%= render :partial => "browse/tag_details", :object => common_details.tags %> diff --git a/app/views/browse/_node.html.erb b/app/views/browse/_node.html.erb index 152223ae7..cc8597292 100644 --- a/app/views/browse/_node.html.erb +++ b/app/views/browse/_node.html.erb @@ -8,7 +8,7 @@ <% else %>
    - <%= render :partial => "common_details", :object => node %> + <%= render :partial => "browse/common_details", :object => node %> <% unless node.ways.empty? and node.containing_relation_members.empty? %>

    <%= t "browse.part_of" %>

    @@ -17,7 +17,7 @@ <%= t "browse.part_of_ways", :count => node.ways.uniq.count %> @@ -26,7 +26,7 @@
    > <%= t "browse.part_of_relations", :count => node.containing_relation_members.uniq.count %>
      - <%= render :partial => "containing_relation", :collection => node.containing_relation_members.uniq %> + <%= render :partial => "browse/containing_relation", :collection => node.containing_relation_members.uniq %>
    <% end %> diff --git a/app/views/browse/_tag_details.html.erb b/app/views/browse/_tag_details.html.erb index 9129ddaf5..cc08fe16a 100644 --- a/app/views/browse/_tag_details.html.erb +++ b/app/views/browse/_tag_details.html.erb @@ -2,7 +2,7 @@

    <%= t ".tags" %>

    - <%= render :partial => "tag", :collection => tag_details.sort %> + <%= render :partial => "browse/tag", :collection => tag_details.sort %>
    <% end %> diff --git a/app/views/old_nodes/not_found.html.erb b/app/views/old_nodes/not_found.html.erb new file mode 100644 index 000000000..1ee5d9d3f --- /dev/null +++ b/app/views/old_nodes/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_nodes/show.html.erb b/app/views/old_nodes/show.html.erb new file mode 100644 index 000000000..d3d09892e --- /dev/null +++ b/app/views/old_nodes/show.html.erb @@ -0,0 +1,5 @@ +<% 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 %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a2347d4bc..6df0260cd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -428,6 +428,9 @@ 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." changesets: changeset_paging_nav: showing_page: "Page %{page}" diff --git a/config/routes.rb b/config/routes.rb index a38f8450f..29c260c9e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,6 +113,7 @@ OpenStreetMap::Application.routes.draw do get "/way/:id/history" => "browse#way_history", :id => /\d+/, :as => :way_history 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 get "/changeset/:id" => "browse#changeset", :as => :changeset, :id => /\d+/ diff --git a/test/controllers/old_nodes_controller_test.rb b/test/controllers/old_nodes_controller_test.rb new file mode 100644 index 000000000..80b8da946 --- /dev/null +++ b/test/controllers/old_nodes_controller_test.rb @@ -0,0 +1,26 @@ +require "test_helper" + +class OldNodesControllerTest < ActionDispatch::IntegrationTest + def test_routes + assert_routing( + { :path => "/node/1/history/2", :method => :get }, + { :controller => "old_nodes", :action => "show", :id => "1", :version => "2" } + ) + end + + def test_visible + node = create(:node, :with_history) + get old_node_path(node, 1) + assert_response :success + assert_template "old_nodes/show" + assert_template :layout => "map" + end + + def test_not_found + get old_node_path(0, 0) + assert_response :not_found + assert_template "old_nodes/not_found" + assert_template :layout => "map" + assert_select "#sidebar_content", /node #0 version 0 could not be found/ + end +end -- 2.45.1