From 88524547953f87a087f97c0b7dbf398835347d82 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 8 May 2011 00:22:32 +0100 Subject: [PATCH] Rename association between map_bugs and map_bug_comment to comments --- app/controllers/map_bugs_controller.rb | 18 ++-- app/models/map_bug.rb | 7 +- app/models/notifier.rb | 10 +- app/views/browse/bug.html.erb | 136 ++++++++++++------------- app/views/map_bugs/_bug.rss.builder | 6 +- app/views/map_bugs/_bug.xml.builder | 2 +- app/views/map_bugs/my_bugs.html.erb | 60 +++++------ 7 files changed, 114 insertions(+), 125 deletions(-) diff --git a/app/controllers/map_bugs_controller.rb b/app/controllers/map_bugs_controller.rb index 158bf435a..6f645b131 100644 --- a/app/controllers/map_bugs_controller.rb +++ b/app/controllers/map_bugs_controller.rb @@ -39,14 +39,14 @@ class MapBugsController < ApplicationController check_boundaries(@min_lon, @min_lat, @max_lon, @max_lat, :false) - @bugs = MapBug.find_by_area_no_quadtile(@min_lat, @min_lon, @max_lat, @max_lon, :include => :map_bug_comment, :order => "last_changed DESC", :limit => limit, :conditions => conditions) + @bugs = MapBug.find_by_area_no_quadtile(@min_lat, @min_lon, @max_lat, @max_lon, :include => :comments, :order => "last_changed DESC", :limit => limit, :conditions => conditions) respond_to do |format| format.html {render :template => 'map_bugs/get_bugs.js', :content_type => "text/javascript"} format.rss {render :template => 'map_bugs/get_bugs.rss'} format.js format.xml {render :template => 'map_bugs/get_bugs.xml'} - format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) } + format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :comments => { :only => [:commenter_name, :date_created, :comment]}}) } format.gpx {render :template => 'map_bugs/get_bugs.gpx'} end end @@ -159,7 +159,7 @@ class MapBugsController < ApplicationController respond_to do |format| format.rss format.xml - format.json { render :json => @bug.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) } + format.json { render :json => @bug.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :comments => { :only => [:commenter_name, :date_created, :comment]}}) } format.gpx end end @@ -186,7 +186,7 @@ class MapBugsController < ApplicationController #TODO: There should be a better way to do this. CloseConditions are ignored at the moment - bugs2 = MapBug.find(:all, :limit => limit, :order => "last_changed DESC", :joins => :map_bug_comment, :include => :map_bug_comment, + bugs2 = MapBug.find(:all, :limit => limit, :order => "last_changed DESC", :joins => :comments, :include => :comments, :conditions => conditions) @bugs = bugs2.uniq respond_to do |format| @@ -194,7 +194,7 @@ class MapBugsController < ApplicationController format.rss {render :template => 'map_bugs/get_bugs.rss'} format.js format.xml {render :template => 'map_bugs/get_bugs.xml'} - format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) } + format.json { render :json => @bugs.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :comments => { :only => [:commenter_name, :date_created, :comment]}}) } format.gpx {render :template => 'map_bugs/get_bugs.gpx'} end end @@ -229,8 +229,8 @@ class MapBugsController < ApplicationController @page_size = 10 @bugs = MapBug.find(:all, - :include => [:map_bug_comment, {:map_bug_comment => :user}], - :joins => :map_bug_comment, + :include => [:comments, {:comments => :user}], + :joins => :comments, :order => "last_changed DESC", :conditions => conditions, :offset => (@page - 1) * @page_size, @@ -292,7 +292,7 @@ private def add_comment(bug, comment, name,event) t = Time.now.getutc - bug_comment = bug.map_bug_comment.create(:date_created => t, :visible => true, :event => event) + bug_comment = bug.comments.create(:date_created => t, :visible => true, :event => event) bug_comment.comment = comment unless comment == :nil if @user bug_comment.commenter_id = @user.id @@ -306,7 +306,7 @@ private bug.save sent_to = Set.new - bug.map_bug_comment.each do | cmt | + bug.comments.each do | cmt | if cmt.user unless sent_to.include?(cmt.user) Notifier.deliver_bug_comment_notification(bug_comment, cmt.user) unless cmt.user == @user diff --git a/app/models/map_bug.rb b/app/models/map_bug.rb index 440b64b78..b07ef2941 100644 --- a/app/models/map_bug.rb +++ b/app/models/map_bug.rb @@ -1,7 +1,10 @@ class MapBug < ActiveRecord::Base include GeoRecord - has_many :map_bug_comment, :foreign_key => :bug_id, :order => :date_created, :conditions => "visible = true and comment is not null" + has_many :comments, :class_name => "MapBugComment", + :foreign_key => :bug_id, + :order => :date_created, + :conditions => "visible = true and comment is not null" validates_presence_of :id, :on => :update validates_uniqueness_of :id @@ -35,7 +38,7 @@ class MapBug < ActiveRecord::Base def flatten_comment(separator_char, upto_timestamp = :nil) resp = "" comment_no = 1 - self.map_bug_comment.each do |comment| + self.comments.each do |comment| next if upto_timestamp != :nil and comment.date_created > upto_timestamp resp += (comment_no == 1 ? "" : separator_char) resp += comment.comment if comment.comment diff --git a/app/models/notifier.rb b/app/models/notifier.rb index d3c975df9..26c236b7a 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -97,11 +97,9 @@ class Notifier < ActionMailer::Base def bug_comment_notification(bug_comment, recipient) common_headers recipient - commenter_name = bug_comment.user.display_name if bug_comment.user - commenter_name = bug_comment.commenter_name unless bug_comment.user - owner = (recipient == bug_comment.map_bug.map_bug_comment[0].user); - subject I18n.t('notifier.map_bug_plain.subject_own', :commenter => commenter_name) if owner - subject I18n.t('notifier.map_bug_plain.subject_other', :commenter => commenter_name) unless owner + owner = (recipient == bug_comment.map_bug.comments.first.user); + subject I18n.t('notifier.map_bug_plain.subject_own', :commenter => bug_comment.commenter_name) if owner + subject I18n.t('notifier.map_bug_plain.subject_other', :commenter => bug_comment.commenter_name) unless owner body :bugurl => url_for(:host => SERVER_URL, :controller => "browse", @@ -110,7 +108,7 @@ class Notifier < ActionMailer::Base :place => bug_comment.map_bug.nearby_place, :comment => bug_comment.comment, :owner => owner, - :commenter => commenter_name + :commenter => bug_comment.commenter_name end private diff --git a/app/views/browse/bug.html.erb b/app/views/browse/bug.html.erb index 5c65b3e41..9fd571abe 100644 --- a/app/views/browse/bug.html.erb +++ b/app/views/browse/bug.html.erb @@ -2,14 +2,14 @@

- <% if @bug.status == "closed" %> - <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> - <%= t'browse.bug.closed_title', :bug_name => @bug.id %> - <% else %> - <%= image_tag("open_bug_marker.png", :alt => 'open') %> - <%= t'browse.bug.open_title', :bug_name => @bug.id %> - <% end %> -

+ <% if @bug.status == "closed" %> + <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> + <%= t 'browse.bug.closed_title', :bug_name => @bug.id %> + <% else %> + <%= image_tag("open_bug_marker.png", :alt => 'open') %> + <%= t 'browse.bug.open_title', :bug_name => @bug.id %> + <% end %> + <%= render :partial => "navigation" %> @@ -17,71 +17,67 @@ - - - - - - - - - - - <% if @bug.status == "closed" %> - - - - - <% end %> - - - <% if @bug.map_bug_comment[0].user.nil? %> - - <% else %> - - <% end %> - - - - - +
<%= t 'browse.bug.created_at' %><%= l @bug.date_created %>
<%= t 'browse.bug.edited_at' %><%= l @bug.last_changed %>
<%= t 'browse.bug.closed_at' %><%= l @bug.date_closed %>
<%= t 'browse.bug.opened_by' %> <%= @bug.map_bug_comment[0].commenter_name %> <%= link_to h(@bug.map_bug_comment[0].user.display_name), :controller => "user", :action => "view", :display_name => @bug.map_bug_comment[0].user.display_name %>
<%= t 'browse.bug.description' %><%= h(@bug.map_bug_comment[0].comment) %>
+ + + + + + + + + <% if @bug.status == "closed" %> + + + + + <% end %> + + + <% if @bug.comments.first.user.nil? %> + + <% else %> + + <% end %> + + + + + + + + + +
<%= t 'browse.bug.created_at' %><%= l @bug.date_created %>
<%= t 'browse.bug.edited_at' %><%= l @bug.last_changed %>
<%= t 'browse.bug.closed_at' %><%= l @bug.date_closed %>
<%= t 'browse.bug.opened_by' %> <%= @bug.comments.first.commenter_name %> <%= link_to h(@bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => @bug.comments.first.user.display_name %>
<%= t 'browse.bug.description' %><%= h(@bug.comments.first.comment) %>
<%= t 'browse.node_details.coordinates' %>
<%= link_to ("#{number_with_delimiter(@bug.lat)}, #{number_with_delimiter(@bug.lon)}"), {:controller => 'site', :action => 'index', :lat => h(@bug.lat), :lon => h(@bug.lon), :zoom => "18"} %>
- - <%= t 'browse.node_details.coordinates' %> -
<%= link_to ("#{number_with_delimiter(@bug.lat)}, #{number_with_delimiter(@bug.lon)}"), {:controller => 'site', :action => 'index', :lat => h(@bug.lat), :lon => h(@bug.lon), :zoom => "18"} %>
- +
- - -
- - <%if @bug.map_bug_comment.length > 1 %> - - - - - - <% @bug.map_bug_comment[1..-1].each do |bug_comment| %> - - - - - - - <% end %> -
<%= t 'browse.bug.comment_by' %> <%= t 'browse.bug.comment' %> <%= t 'browse.bug.date' %>
- <% if bug_comment.user.nil? %> - <%= bug_comment.commenter_name %> - <% else %> - <%= link_to h(bug_comment.user.display_name), :controller => "user", :action => "view", :display_name => bug_comment.user.display_name %> - <% end %> - <%= h(bug_comment.comment) %> <%= l bug_comment.date_created %>
- - <% end %> + <% if @bug.comments.length > 1 %> + + + + + + + <% @bug.comments[1..-1].each do |bug_comment| %> + + + + + + <% end %> +
<%= t 'browse.bug.comment_by' %> <%= t 'browse.bug.comment' %> <%= t 'browse.bug.date' %>
+ <% if bug_comment.user.nil? %> + <%= bug_comment.commenter_name %> + <% else %> + <%= link_to h(bug_comment.user.display_name), :controller => "user", :action => "view", :display_name => bug_comment.user.display_name %> + <% end %> + <%= h(bug_comment.comment) %> <%= l bug_comment.date_created %>
+ <% end %> -
- +
+ <%= render :partial => "map", :object => @bug %> - \ No newline at end of file + diff --git a/app/views/map_bugs/_bug.rss.builder b/app/views/map_bugs/_bug.rss.builder index 59367da67..abfbc56d4 100644 --- a/app/views/map_bugs/_bug.rss.builder +++ b/app/views/map_bugs/_bug.rss.builder @@ -1,7 +1,7 @@ xml.item do if bug.status == "closed" xml.title t('bugs.rss.closed', :place => bug.nearby_place) - elsif bug.map_bug_comment.length > 1 + elsif bug.comments.length > 1 xml.title t('bugs.rss.comment', :place => bug.nearby_place) else xml.title t('bugs.rss.new', :place => bug.nearby_place) @@ -11,8 +11,8 @@ xml.item do xml.guid url_for(:controller => "map_bugs", :action => "read", :id => bug.id, :only_path => false) xml.description htmlize(bug.flatten_comment("

")) - unless bug.map_bug_comment.empty? - xml.author bug.map_bug_comment[-1].commenter_name + unless bug.comments.empty? + xml.author bug.comments[-1].commenter_name end xml.pubDate bug.last_changed.to_s(:rfc822) diff --git a/app/views/map_bugs/_bug.xml.builder b/app/views/map_bugs/_bug.xml.builder index a25a588a2..32c98721e 100644 --- a/app/views/map_bugs/_bug.xml.builder +++ b/app/views/map_bugs/_bug.xml.builder @@ -9,7 +9,7 @@ xml.bug("lon" => bug.lon, "lat" => bug.lat) do end xml.comments do - bug.map_bug_comment.each do |comment| + bug.comments.each do |comment| xml.comment do xml.date comment.date_created xml.uid comment.commenter_id unless comment.commenter_id.nil? diff --git a/app/views/map_bugs/my_bugs.html.erb b/app/views/map_bugs/my_bugs.html.erb index 97e570060..9802ae1b2 100644 --- a/app/views/map_bugs/my_bugs.html.erb +++ b/app/views/map_bugs/my_bugs.html.erb @@ -4,42 +4,34 @@ <%= render :partial => 'bugs_paging_nav' %> - - - - - - - - - - + + + + + + + + <% @bugs.each do |bug| %> -<% if bug.map_bug_comment[0].user == @user2 %> - -<% else %> - -<% end %> - - - - <% if bug.map_bug_comment[0].user.nil? %> - - <% else %> - - <% end %> - - - - + bgcolor="#EEEEEE"<% end %>> + + + <% if bug.comments[0].user.nil? %> + + <% else %> + + <% end %> + + + + <% end %>
<%= t'bugs.user.id' %><%= t'changeset.changesets.user' %><%= t'changeset.changesets.comment' %><%= t'changeset.changesets.saved_at' %><%= t'bugs.user.last_changed' %>
<%= t'bugs.user.id' %><%= t'changeset.changesets.user' %><%= t'changeset.changesets.comment' %><%= t'changeset.changesets.saved_at' %><%= t'bugs.user.last_changed' %>
- <% if bug.status == "closed" %> - <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> - <% else %> - <%= image_tag("open_bug_marker.png", :alt => 'open') %> - <% end %> - <%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %> <%= bug.map_bug_comment[0].commenter_name %> <%= link_to h(bug.map_bug_comment[0].user.display_name), :controller => "user", :action => "view", :display_name => bug.map_bug_comment[0].user.display_name %> <%= htmlize bug.map_bug_comment[0].comment %> <%= l bug.date_created %><%= l bug.last_changed %>
+ <% if bug.status == "closed" %> + <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> + <% else %> + <%= image_tag("open_bug_marker.png", :alt => 'open') %> + <% end %> + <%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %> <%= bug.comments[0].commenter_name %> <%= link_to h(bug.comments[0].user.display_name), :controller => "user", :action => "view", :display_name => bug.comments[0].user.display_name %> <%= htmlize bug.comments[0].comment %> <%= l bug.date_created %><%= l bug.last_changed %>
- <%= render :partial => 'bugs_paging_nav' %> -- 2.43.2