]> git.openstreetmap.org Git - rails.git/commitdiff
Get the per-user note list view working again
authorTom Hughes <tom@compton.nu>
Fri, 9 Mar 2012 12:54:19 +0000 (12:54 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 9 Mar 2012 12:54:19 +0000 (12:54 +0000)
app/controllers/note_controller.rb
app/models/user.rb
app/views/note/mine.html.erb

index 32acea89f48175a846a4c903e321750601754021..1eb0350fd721f69549803f740687dafc3690c1d2 100644 (file)
@@ -237,42 +237,24 @@ class NoteController < ApplicationController
     end
   end
 
     end
   end
 
+  ##
+  # Display a list of notes by a specified user
   def mine
     if params[:display_name] 
   def mine
     if params[:display_name] 
-      @user2 = User.find_by_display_name(params[:display_name], :conditions => { :status => ["active", "confirmed"] }) 
-      if @user2  
-        if @user2.data_public? or @user2 == @user 
-          conditions = ['note_comments.author_id = ?', @user2.id] 
-        else 
-          conditions = ['false'] 
-        end 
-      else #if request.format == :html 
+      if @this_user = User.active.find_by_display_name(params[:display_name])
+        @title =  t 'note.mine.title', :user => @this_user.display_name 
+        @heading =  t 'note.mine.heading', :user => @this_user.display_name 
+        @description = t 'note.mine.description', :user => render_to_string(:partial => "user", :object => @this_user)
+        @page = (params[:page] || 1).to_i 
+        @page_size = 10
+        @notes = @this_user.notes.order("updated_at DESC").offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author)
+      else
         @title = t 'user.no_such_user.title' 
         @not_found_user = params[:display_name] 
         @title = t 'user.no_such_user.title' 
         @not_found_user = params[:display_name] 
+
         render :template => 'user/no_such_user', :status => :not_found 
         render :template => 'user/no_such_user', :status => :not_found 
-        return
       end 
     end
       end 
     end
-
-    if @user2 
-      user_link = render_to_string :partial => "user", :object => @user2 
-    end 
-    
-    @title =  t 'note.mine.title', :user => @user2.display_name 
-    @heading =  t 'note.mine.heading', :user => @user2.display_name 
-    @description = t 'note.mine.description', :user => user_link
-    
-    @page = (params[:page] || 1).to_i 
-    @page_size = 10
-
-    @notes = Note.find(:all, 
-                       :include => [:comments, {:comments => :author}],
-                       :joins => :comments,
-                       :order => "updated_at DESC",
-                       :conditions => conditions,
-                       :offset => (@page - 1) * @page_size, 
-                       :limit => @page_size).uniq
   end
 
 private 
   end
 
 private 
index 0c9e76d54999685bd920542c4daf0aa42d64cbf6..51bc52f3c0cc994974cb234141e797266dbf7b3c 100644 (file)
@@ -12,6 +12,8 @@ class User < ActiveRecord::Base
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :changesets, :order => 'created_at DESC'
   has_many :tokens, :class_name => "UserToken"
   has_many :preferences, :class_name => "UserPreference"
   has_many :changesets, :order => 'created_at DESC'
+  has_many :note_comments, :foreign_key => :author_id
+  has_many :notes, :through => :note_comments
 
   has_many :client_applications
   has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
 
   has_many :client_applications
   has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
index d818243247c6b96cab8d369495c7bf98e280fe76..50c15cd9d3f1678cc150b8e1702fcb032d2bc631 100644 (file)
@@ -1,5 +1,5 @@
 <h1><%= @heading %></h1>
 <h1><%= @heading %></h1>
-<p><%= @description %></p>
+<p><%= raw @description %></p>
 
 <%= render :partial => 'notes_paging_nav' %>
 
 
 <%= render :partial => 'notes_paging_nav' %>
 
@@ -12,7 +12,7 @@
     <th><%= t'changeset.changesets.saved_at' %></th>
     <th><%= t'note.mine.last_changed' %></th>
   </tr>
     <th><%= t'changeset.changesets.saved_at' %></th>
     <th><%= t'note.mine.last_changed' %></th>
   </tr>
-<% @notes.each do |note| %>
+<% @notes.each do |note| -%>
   <tr<% if note.author != @user2 %> bgcolor="#EEEEEE"<% end %>>
     <td>
       <% if note.status == "closed" %>
   <tr<% if note.author != @user2 %> bgcolor="#EEEEEE"<% end %>>
     <td>
       <% if note.status == "closed" %>
@@ -31,7 +31,7 @@
     <td><%= l note.created_at %></td>
     <td><%= l note.updated_at %></td>
   </tr>
     <td><%= l note.created_at %></td>
     <td><%= l note.updated_at %></td>
   </tr>
-<% end %>
+<% end -%>
 </table>
 
 <%= render :partial => 'notes_paging_nav' %>
 </table>
 
 <%= render :partial => 'notes_paging_nav' %>