]> git.openstreetmap.org Git - rails.git/commitdiff
Rename association between map_bugs and map_bug_comment to comments
authorTom Hughes <tom@compton.nu>
Sat, 7 May 2011 23:22:32 +0000 (00:22 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 7 May 2011 23:22:32 +0000 (00:22 +0100)
app/controllers/map_bugs_controller.rb
app/models/map_bug.rb
app/models/notifier.rb
app/views/browse/bug.html.erb
app/views/map_bugs/_bug.rss.builder
app/views/map_bugs/_bug.xml.builder
app/views/map_bugs/my_bugs.html.erb

index 158bf435aa0837356e7b0beab36f0d20638795b5..6f645b13111453f95f3d7c40daf71769be6031e7 100644 (file)
@@ -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
index 440b64b78b3bd96b1af85b5339e0e8668f157196..b07ef2941d290cfce75363e1ce957ff118ccb69b 100644 (file)
@@ -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
index d3c975df98255cd6c0a0e8258a12d98bb211f218..26c236b7ad48f5550cae088a6644bc4a5b5d8093 100644 (file)
@@ -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
index 5c65b3e418226e46a49cf65acd5867496bdd72e3..9fd571abe6f07c4457821b9cd6ed6e7b764b5e4c 100644 (file)
@@ -2,14 +2,14 @@
   <tr>
     <td width="100%">
       <h2>
-               <% 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 %>
-               </h2>
+        <% 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 %>
+      </h2>
     </td>
     <td>
       <%= render :partial => "navigation" %>
   </tr>
   <tr valign="top">
     <td>
-               <table>
-                       <tr>
-                           <th><%= t 'browse.bug.created_at' %></th>
-                           <td><%= l @bug.date_created %></td>
-                       </tr>  
-                       
-                       <tr>
-                               <th><%= t 'browse.bug.edited_at' %></th>
-                               <td><%= l @bug.last_changed %></td>
-                       </tr>
-                       <% if @bug.status == "closed" %>
-                       <tr>
-                           <th><%= t 'browse.bug.closed_at' %></th>
-                           <td><%= l @bug.date_closed %></td>
-                       </tr>
-                       <% end %>
-                       <tr>
-                               <th><%= t 'browse.bug.opened_by' %></th>
-                               <% if @bug.map_bug_comment[0].user.nil? %>
-                                       <td> <%= @bug.map_bug_comment[0].commenter_name %> </td>
-                               <% else %>
-                                       <td><%= 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 %></td>                                      
-                               <% end %>
-                       </tr>
-                       <tr>
-                               <th><%= t 'browse.bug.description' %></th>
-                               <td><%= h(@bug.map_bug_comment[0].comment) %></td>
-                       </tr>
+      <table>
+        <tr>
+          <th><%= t 'browse.bug.created_at' %></th>
+          <td><%= l @bug.date_created %></td>
+        </tr>  
+       <tr>
+         <th><%= t 'browse.bug.edited_at' %></th>
+         <td><%= l @bug.last_changed %></td>
+       </tr>
+       <% if @bug.status == "closed" %>
+         <tr>
+           <th><%= t 'browse.bug.closed_at' %></th>
+           <td><%= l @bug.date_closed %></td>
+         </tr>
+       <% end %>
+       <tr>
+         <th><%= t 'browse.bug.opened_by' %></th>
+         <% if @bug.comments.first.user.nil? %>
+           <td> <%= @bug.comments.first.commenter_name %> </td>
+         <% else %>
+           <td><%= link_to h(@bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => @bug.comments.first.user.display_name %></td>                                  
+         <% end %>
+       </tr>
+       <tr>
+         <th><%= t 'browse.bug.description' %></th>
+         <td><%= h(@bug.comments.first.comment) %></td>
+       </tr>
+       <tr>
+         <th><%= t 'browse.node_details.coordinates' %></th>
+         <td><div class="geo"><%= link_to ("<span class='latitude'>#{number_with_delimiter(@bug.lat)}</span>, <span class='longitude'>#{number_with_delimiter(@bug.lon)}</span>"), {:controller => 'site', :action => 'index', :lat => h(@bug.lat), :lon => h(@bug.lon), :zoom => "18"} %></div></td>
+       </tr>
+    </table>
 
-                       <tr>
-                               <th><%= t 'browse.node_details.coordinates' %></th>
-                               <td><div class="geo"><%= link_to ("<span class='latitude'>#{number_with_delimiter(@bug.lat)}</span>, <span class='longitude'>#{number_with_delimiter(@bug.lon)}</span>"), {:controller => 'site', :action => 'index', :lat => h(@bug.lat), :lon => h(@bug.lon), :zoom => "18"} %></div></td>
-                               </tr>
+    <br />
 
-               </table>
-
-               <br>
-
-       <%if @bug.map_bug_comment.length > 1 %>
-
-               <table>
-                       <tr>
-                               <th width="20%"> <%= t 'browse.bug.comment_by' %></th> <th width="60%"> <%= t 'browse.bug.comment' %></th> <th width="20%"> <%= t 'browse.bug.date' %></th> 
-                       </tr>
-                       <% @bug.map_bug_comment[1..-1].each do |bug_comment| %>
-                               <tr>
-                                       
-                                       <td>
-                                               <% 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 %>
-                                       </td>
-                                       <td> <%= h(bug_comment.comment) %> </td>
-                                       <td> <%= l bug_comment.date_created %> </td>
-                               </tr>
-                       <% end %>
-               </table>
-
-       <% end %>
+    <% if @bug.comments.length > 1 %>
+      <table>
+        <tr>
+          <th width="20%"> <%= t 'browse.bug.comment_by' %></th>
+          <th width="60%"> <%= t 'browse.bug.comment' %></th>
+          <th width="20%"> <%= t 'browse.bug.date' %></th> 
+        </tr>
+        <% @bug.comments[1..-1].each do |bug_comment| %>
+          <tr>
+            <td>
+              <% 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 %>
+            </td>
+            <td> <%= h(bug_comment.comment) %> </td>
+            <td> <%= l bug_comment.date_created %> </td>
+          </tr>
+        <% end %>
+      </table>
+    <% end %>
        
-      <hr />
-      
+    <hr />
     </td>
+
     <%= render :partial => "map", :object => @bug %>
   </tr>
-</table>
\ No newline at end of file
+</table>
index 59367da67636b1325e808dc3802343ddcbadd89d..abfbc56d441f9a26bb49fb212c6cd40cd3e03ffd 100644 (file)
@@ -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("<br><br>"))
 
-  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)
index a25a588a2460b2426455ea72883556fa7b99d5b2..32c98721e41d7d2d603eef89e9a517b10645fb17 100644 (file)
@@ -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?
index 97e570060b23593b105770d89c8461c198e4af40..9802ae1b2d6da4cd38aac506619245fd851dad46 100644 (file)
@@ -4,42 +4,34 @@
 <%= render :partial => 'bugs_paging_nav' %>
 
 <table id="bug_list" cellpadding="3">
-       <tr>
-       <th></th>
-               <th><%= t'bugs.user.id' %></th>
-               <th><%= t'changeset.changesets.user' %></th>
-               <th><%= t'changeset.changesets.comment' %></th>
-       <th><%= t'changeset.changesets.saved_at' %></th>
-               <th><%= t'bugs.user.last_changed' %></th>
-       
-       
-       </tr>
+  <tr>
+    <th></th>
+    <th><%= t'bugs.user.id' %></th>
+    <th><%= t'changeset.changesets.user' %></th>
+    <th><%= t'changeset.changesets.comment' %></th>
+    <th><%= t'changeset.changesets.saved_at' %></th>
+    <th><%= t'bugs.user.last_changed' %></th>
+  </tr>
 <% @bugs.each do |bug| %>
-<% if bug.map_bug_comment[0].user == @user2 %>
-       <tr>
-<% else %>     
-       <tr bgcolor=#EEEEEE>
-<% end %>      
-               <td>
-                       <% if bug.status == "closed" %>
-                               <%= image_tag("closed_bug_marker.png", :alt => 'closed') %>
-                       <% else %>
-                               <%= image_tag("open_bug_marker.png", :alt => 'open') %>
-                       <% end %>
-               </td>
-               <td><%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %></td>
-               
-               <% if bug.map_bug_comment[0].user.nil? %> 
-                       <td> <%= bug.map_bug_comment[0].commenter_name %> </td> 
-               <% else %> 
-                       <td><%= 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 %></td>
-        <% end %>
-               <td> <%= htmlize bug.map_bug_comment[0].comment  %> </td>       
-               <td><%= l bug.date_created %></td>
-               <td><%= l bug.last_changed %></td>
-       </tr>
+  <tr<% if bug.comments[0].user != @user2 %> bgcolor="#EEEEEE"<% end %>>
+    <td>
+      <% if bug.status == "closed" %>
+        <%= image_tag("closed_bug_marker.png", :alt => 'closed') %>
+      <% else %>
+        <%= image_tag("open_bug_marker.png", :alt => 'open') %>
+      <% end %>
+    </td>
+    <td><%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %></td>
+    <% if bug.comments[0].user.nil? %> 
+      <td> <%= bug.comments[0].commenter_name %> </td> 
+    <% else %> 
+      <td><%= link_to h(bug.comments[0].user.display_name), :controller => "user", :action => "view", :display_name => bug.comments[0].user.display_name %></td>
+    <% end %>
+    <td> <%= htmlize bug.comments[0].comment  %> </td> 
+    <td><%= l bug.date_created %></td>
+    <td><%= l bug.last_changed %></td>
+  </tr>
 <% end %>
 </table>
 
-
 <%= render :partial => 'bugs_paging_nav' %>