From 9dd230d0bc7de0cdf705f3cd4b3be07ae23c154b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 12 Nov 2013 13:05:27 -0800 Subject: [PATCH] Refactor browse templates --- app/controllers/browse_controller.rb | 45 +++++++------------ app/helpers/title_helper.rb | 4 +- ...{_node_details.html.erb => _node.html.erb} | 14 +++--- ...on_details.html.erb => _relation.html.erb} | 16 +++---- .../{_way_details.html.erb => _way.html.erb} | 16 +++---- app/views/browse/changeset.html.erb | 4 +- app/views/browse/feature.html.erb | 14 ++++++ app/views/browse/history.html.erb | 14 ++++++ app/views/browse/node.html.erb | 17 ------- app/views/browse/node_history.html.erb | 19 -------- app/views/browse/relation.html.erb | 17 ------- app/views/browse/relation_history.html.erb | 19 -------- app/views/browse/way.html.erb | 17 ------- app/views/browse/way_history.html.erb | 19 -------- config/locales/en.yml | 21 +++------ 15 files changed, 79 insertions(+), 177 deletions(-) rename app/views/browse/{_node_details.html.erb => _node.html.erb} (55%) rename app/views/browse/{_relation_details.html.erb => _relation.html.erb} (54%) rename app/views/browse/{_way_details.html.erb => _way.html.erb} (70%) create mode 100644 app/views/browse/feature.html.erb create mode 100644 app/views/browse/history.html.erb delete mode 100644 app/views/browse/node.html.erb delete mode 100644 app/views/browse/node_history.html.erb delete mode 100644 app/views/browse/relation.html.erb delete mode 100644 app/views/browse/relation_history.html.erb delete mode 100644 app/views/browse/way.html.erb delete mode 100644 app/views/browse/way_history.html.erb diff --git a/app/controllers/browse_controller.rb b/app/controllers/browse_controller.rb index 61982a940..377c7ced1 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -8,67 +8,58 @@ class BrowseController < ApplicationController def relation @type = "relation" - @relation = Relation.find(params[:id]) - @next = Relation.visible.where("id > ?", @relation.id).order(:id => :asc).first - @prev = Relation.visible.where("id < ?", @relation.id).order(:id => :desc).first + @feature = Relation.find(params[:id]) + render 'feature' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - + def relation_history @type = "relation" - @relation = Relation.find(params[:id]) + @feature = Relation.find(params[:id]) + render 'history' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - + def way @type = "way" - @way = Way.preload(:way_tags, :containing_relation_members, :changeset => :user, :nodes => [:node_tags, :ways => :way_tags]).find(params[:id]) - @next = Way.visible.where("id > ?", @way.id).order(:id => :asc).first - @prev = Way.visible.where("id < ?", @way.id).order(:id => :desc).first + @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => :user, :nodes => [:node_tags, :ways => :way_tags]).find(params[:id]) + render 'feature' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - + def way_history @type = "way" - @way = Way.preload(:way_tags, :old_ways => { :changeset => :user }).find(params[:id]) + @feature = Way.preload(:way_tags, :old_ways => { :changeset => :user }).find(params[:id]) + render 'feature' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end def node @type = "node" - @node = Node.find(params[:id]) - @next = Node.visible.where("id > ?", @node.id).order(:id => :asc).first - @prev = Node.visible.where("id < ?", @node.id).order(:id => :desc).first + @feature = Node.find(params[:id]) + render 'feature' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - + def node_history @type = "node" - @node = Node.find(params[:id]) + @feature = Node.find(params[:id]) + render 'history' rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end - + def changeset @type = "changeset" - @changeset = Changeset.find(params[:id]) @node_pages, @nodes = paginate(:old_nodes, :conditions => {:changeset_id => @changeset.id}, :per_page => 10, :parameter => 'node_page') @way_pages, @ways = paginate(:old_ways, :conditions => {:changeset_id => @changeset.id}, :per_page => 10, :parameter => 'way_page') @relation_pages, @relations = paginate(:old_relations, :conditions => {:changeset_id => @changeset.id}, :per_page => 10, :parameter => 'relation_page') - - @next = Changeset.where("id > ?", @changeset.id).order(:id => :asc).first - @prev = Changeset.where("id < ?", @changeset.id).order(:id => :desc).first - - if @changeset.user.data_public? - @next_by_user = @changeset.user.changesets.where("id > ?", @changeset.id).order(:id => :asc).first - @prev_by_user = @changeset.user.changesets.where("id < ?", @changeset.id).order(:id => :desc).first - end rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end @@ -76,8 +67,6 @@ class BrowseController < ApplicationController def note @type = "note" @note = Note.find(params[:id]) - @next = Note.visible.where("id > ?", @note.id).order(:id => :asc).first - @prev = Note.visible.where("id < ?", @note.id).order(:id => :desc).first rescue ActiveRecord::RecordNotFound render :action => "not_found", :status => :not_found end diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb index 181c12af8..c9b979ad5 100644 --- a/app/helpers/title_helper.rb +++ b/app/helpers/title_helper.rb @@ -1,9 +1,9 @@ module TitleHelper def set_title(title = false) if title - title = t('layouts.project_name.title') + ' | ' + title + title = t('layouts.project_name.title') + ' | ' + title else - title = t('layouts.project_name.title') + title = t('layouts.project_name.title') end response.headers["X-Page-Title"] = title @title = title diff --git a/app/views/browse/_node_details.html.erb b/app/views/browse/_node.html.erb similarity index 55% rename from app/views/browse/_node_details.html.erb rename to app/views/browse/_node.html.erb index d169f22ac..5b29865db 100644 --- a/app/views/browse/_node_details.html.erb +++ b/app/views/browse/_node.html.erb @@ -1,20 +1,20 @@
- <% if node_details.redacted? %> + <% if node.redacted? %> <%= t 'browse.redacted.message_html', :type => t('browse.redacted.type.node'), - :version => node_details.version, + :version => node.version, :redaction_link => link_to(t('browse.redacted.redaction', - :id => node_details.redaction.id), node_details.redaction) %> + :id => node.redaction.id), node.redaction) %> <% else %> - <%= render :partial => "common_details", :object => node_details %> + <%= render :partial => "common_details", :object => node %> - <% unless node_details.ways.empty? and node_details.containing_relation_members.empty? %> + <% unless node.ways.empty? and node.containing_relation_members.empty? %>

<%= t 'browse.part_of' %>

<% end %> <% end %> diff --git a/app/views/browse/_relation_details.html.erb b/app/views/browse/_relation.html.erb similarity index 54% rename from app/views/browse/_relation_details.html.erb rename to app/views/browse/_relation.html.erb index 41b9be432..e8f9a4f51 100644 --- a/app/views/browse/_relation_details.html.erb +++ b/app/views/browse/_relation.html.erb @@ -1,21 +1,21 @@
- <% if relation_details.redacted? %> + <% if relation.redacted? %> <%= t 'browse.redacted.message_html', :type => t('browse.redacted.type.relation'), - :version => relation_details.version, + :version => relation.version, :redaction_link => link_to(t('browse.redacted.redaction', - :id => relation_details.redaction.id), relation_details.redaction) %>< + :id => relation.redaction.id), relation.redaction) %>< <% else %> - <%= render :partial => "common_details", :object => relation_details %> + <%= render :partial => "common_details", :object => relation %> - <% unless relation_details.relation_members.empty? %> + <% unless relation.relation_members.empty? %>

<%= t'browse.relation.members' %>

-
    <%= render :partial => "relation_member", :collection => relation_details.relation_members %>
+
    <%= render :partial => "relation_member", :collection => relation.relation_members %>
<% end %> - <% unless relation_details.containing_relation_members.empty? %> + <% unless relation.containing_relation_members.empty? %>

<%= t'browse.part_of' %>

-
    <%= render :partial => "containing_relation", :collection => relation_details.containing_relation_members %>
+
    <%= render :partial => "containing_relation", :collection => relation.containing_relation_members %>
<% end %> <% end %>
diff --git a/app/views/browse/_way_details.html.erb b/app/views/browse/_way.html.erb similarity index 70% rename from app/views/browse/_way_details.html.erb rename to app/views/browse/_way.html.erb index dbb0030bf..9156d2399 100644 --- a/app/views/browse/_way_details.html.erb +++ b/app/views/browse/_way.html.erb @@ -1,17 +1,17 @@
- <% if way_details.redacted? %> + <% if way.redacted? %> <%= t 'browse.redacted.message_html', :type => t('browse.redacted.type.way'), - :version => way_details.version, + :version => way.version, :redaction_link => link_to(t('browse.redacted.redaction', - :id => way_details.redaction.id), way_details.redaction) %> + :id => way.redaction.id), way.redaction) %> <% else %> - <%= render :partial => "common_details", :object => way_details %> + <%= render :partial => "common_details", :object => way %> - <% unless way_details.way_nodes.empty? %> + <% unless way.way_nodes.empty? %>

<%= t'browse.way.nodes' %>

    - <% way_details.way_nodes.each do |wn| %> + <% way.way_nodes.each do |wn| %>
  • <%= link_to h(printable_name(wn.node)), { :action => "node", :id => wn.node_id.to_s }, :class => link_class('node', wn.node), :title => link_title(wn.node) %> <% related_ways = wn.node.ways.reject { |w| w.id == wn.way_id } %> @@ -23,10 +23,10 @@
<% end %> - <% unless way_details.containing_relation_members.empty? %> + <% unless way.containing_relation_members.empty? %>

<%= t'browse.part_of' %>

    - <%= render :partial => "containing_relation", :collection => way_details.containing_relation_members %> + <%= render :partial => "containing_relation", :collection => way.containing_relation_members %>
<% end %> <% end %> diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 8d4aa8afa..ee8948d9b 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -1,8 +1,8 @@ -<% set_title("#{t('browse.changeset.title')} | #{@changeset.id}") %> +<% set_title(t('browse.changeset.title', :id => @changeset.id)) %>

- <%= t 'browse.changeset.changeset', :id => @changeset.id %> + <%= t('browse.changeset.title', :id => @changeset.id) %>

diff --git a/app/views/browse/feature.html.erb b/app/views/browse/feature.html.erb new file mode 100644 index 000000000..1e0f118d8 --- /dev/null +++ b/app/views/browse/feature.html.erb @@ -0,0 +1,14 @@ +<% set_title(t("browse.#{@type}.title", :name => printable_name(@feature))) %> + +

+ + <%= t("browse.#{@type}.title", :name => printable_name(@feature)) %> +

+ +<%= render :partial => @type, :object => @feature %> + +
+ <%= link_to(t('browse.download_xml'), :controller => @type, :action => "read") %> + · + <%= link_to(t('browse.view_history'), :action => "#{@type}_history") %> +
diff --git a/app/views/browse/history.html.erb b/app/views/browse/history.html.erb new file mode 100644 index 000000000..fa483bfb0 --- /dev/null +++ b/app/views/browse/history.html.erb @@ -0,0 +1,14 @@ +<% set_title(t("browse.#{@type}.history_title", :name => printable_name(@feature))) %> + +

+ + <%= t("browse.#{@type}.history_title", :name => printable_name(@feature)) %> +

+ +<%= render :partial => @type, :collection => @feature.send("old_#{@type}s").reverse %> + +
+ <%= link_to(t('browse.download_xml'), :controller => "old_#{@type}", :action => "history") %> + · + <%= link_to(t('browse.view_details'), :action => @type) %> +
diff --git a/app/views/browse/node.html.erb b/app/views/browse/node.html.erb deleted file mode 100644 index 95c5c252e..000000000 --- a/app/views/browse/node.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% - @name = printable_name @node - set_title(t('browse.node.node') + ' | ' + @name) -%> - -

- - <%= t'browse.node.node_title', :node_name => @name %> -

- -<%= render :partial => "node_details", :object => @node %> - -
- <%= link_to(t('browse.download_xml'), :controller => "node", :action => "read") %> - · - <%= link_to(t('browse.view_history'), :action => "node_history") %> -
diff --git a/app/views/browse/node_history.html.erb b/app/views/browse/node_history.html.erb deleted file mode 100644 index 569b02891..000000000 --- a/app/views/browse/node_history.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% - @name = printable_name @node - set_title(t('browse.node.node_history') + ' | ' + @name) -%> - -

- - <%= raw t'browse.node.node_history_title', :node_name => link_to(h(@name), :action => "node", :id => @node.id) %> -

- -<% @node.old_nodes.reverse.each do |node| %> - <%= render :partial => "node_details", :object => node %> -<% end %> - -
- <%= link_to(t('browse.download_xml'), :controller => "old_node", :action => "history") %> - · - <%= link_to(t('browse.view_details'), :action => "node") %> -
diff --git a/app/views/browse/relation.html.erb b/app/views/browse/relation.html.erb deleted file mode 100644 index 39f642417..000000000 --- a/app/views/browse/relation.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% - @name = printable_name @relation - set_title(t('browse.relation.relation') + ' | ' + @name) -%> - -

- - <%= t'browse.relation.relation_title', :relation_name => @name %> -

- -<%= render :partial => "relation_details", :object => @relation %> - -
- <%= link_to(t('browse.download_xml'), :controller => "relation", :action => "read") %> - · - <%= link_to(t('browse.view_history'), :action => "relation_history") %> -
diff --git a/app/views/browse/relation_history.html.erb b/app/views/browse/relation_history.html.erb deleted file mode 100644 index 1656b36b9..000000000 --- a/app/views/browse/relation_history.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% - @name = printable_name @relation - set_title(t('browse.relation.relation_history') + ' | ' + @name) -%> - -

- - <%= raw t'browse.relation.relation_history_title', :relation_name => link_to(h(@name), :action => "relation", :id => @relation.id) %> -

- -<% @relation.old_relations.reverse.each do |relation| %> - <%= render :partial => "relation_details", :object => relation %> -<% end %> - -
- <%= link_to(t('browse.download_xml'), :controller => "old_relation", :action => "history") %> - · - <%= link_to(t('browse.view_details'), :action => "relation") %> -
diff --git a/app/views/browse/way.html.erb b/app/views/browse/way.html.erb deleted file mode 100644 index 56c57b210..000000000 --- a/app/views/browse/way.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<% - @name = printable_name @way - set_title(t('browse.way.way') + ' | ' + @name) -%> - -

- - <%= t'browse.way.way_title', :way_name => @name %> -

- -<%= render :partial => "way_details", :object => @way %> - -
- <%= link_to(t('browse.download_xml'), :controller => "way", :action => "read") %> - · - <%= link_to(t('browse.view_history'), :action => "way_history") %> -
diff --git a/app/views/browse/way_history.html.erb b/app/views/browse/way_history.html.erb deleted file mode 100644 index fcc825473..000000000 --- a/app/views/browse/way_history.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% - @name = printable_name @way - set_title(t('browse.way.way_history') + ' | ' + @name) -%> - -

- - <%= raw t'browse.way.way_history_title', :way_name => link_to(h(@name), :action => "way", :id => @way.id) %> -

- -<% @way.old_ways.reverse.each do |way| %> - <%= render :partial => "way_details", :object => way %> -<% end %> - -
- <%= link_to(t('browse.download_xml'), :controller => "old_way", :action => "history") %> - · - <%= link_to(t('browse.view_details'), :action => "way") %> -
diff --git a/config/locales/en.yml b/config/locales/en.yml index 6c147dbcb..4aeefd98a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -109,8 +109,7 @@ en: view_history: "View history" view_details: "View details" changeset: - title: "Changeset" - changeset: "Changeset %{id}" + title: "Changeset %{id}" belongs_to: "Author" node: "Nodes (%{count})" node_paginated: "Nodes (%{x}-%{y} of %{count})" @@ -124,24 +123,18 @@ en: title: "Changeset %{id}" title_comment: "Changeset %{id} - %{comment}" node: - node: "Node" - node_title: "Node: %{node_name}" - node_history: "Node History" - node_history_title: "Node History: %{node_name}" + title: "Node: %{name}" + history_title: "Node History: %{name}" way: - way: "Way" - way_title: "Way: %{way_name}" - way_history: "Way History" - way_history_title: "Way History: %{way_name}" + title: "Way: %{name}" + history_title: "Way History: %{name}" nodes: "Nodes" also_part_of: one: "part of way %{related_ways}" other: "part of ways %{related_ways}" relation: - relation: "Relation" - relation_title: "Relation: %{relation_name}" - relation_history: "Relation History" - relation_history_title: "Relation History: %{relation_name}" + title: "Relation: %{name}" + history_title: "Relation History: %{name}" members: "Members" relation_member: entry: "%{type} %{name}" -- 2.43.2