From 2f222c49dd60ea505f2c1631efa02fbd9f0f5667 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 15 Jan 2024 18:20:23 +0300 Subject: [PATCH] Add way version pages --- app/abilities/ability.rb | 1 + app/assets/javascripts/index.js | 1 + app/controllers/old_ways_controller.rb | 19 ++++++++++ app/views/browse/_way.html.erb | 6 +-- app/views/old_ways/not_found.html.erb | 7 ++++ app/views/old_ways/show.html.erb | 5 +++ config/locales/en.yml | 3 ++ config/routes.rb | 1 + test/controllers/old_ways_controller_test.rb | 40 ++++++++++++++++++++ 9 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 app/controllers/old_ways_controller.rb create mode 100644 app/views/old_ways/not_found.html.erb create mode 100644 app/views/old_ways/show.html.erb create mode 100644 test/controllers/old_ways_controller_test.rb diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index b601e66f0..643465c54 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -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 diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 621054caf..bb471490a 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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 index 000000000..d18121e6f --- /dev/null +++ b/app/controllers/old_ways_controller.rb @@ -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 diff --git a/app/views/browse/_way.html.erb b/app/views/browse/_way.html.erb index 4fdcd035e..26403f3fd 100644 --- a/app/views/browse/_way.html.erb +++ b/app/views/browse/_way.html.erb @@ -8,7 +8,7 @@ <% else %>
- <%= render :partial => "common_details", :object => way %> + <%= render :partial => "browse/common_details", :object => way %> <% unless way.containing_relation_members.empty? %>

<%= t "browse.part_of" %>

@@ -27,10 +27,10 @@