From: Tom Hughes Date: Fri, 9 Mar 2012 12:54:19 +0000 (+0000) Subject: Get the per-user note list view working again X-Git-Tag: live~5677^2~110 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/6de8c2e6b30485683a9d3aa3e21c4b256fe399bd Get the per-user note list view working again --- diff --git a/app/controllers/note_controller.rb b/app/controllers/note_controller.rb index 32acea89f..1eb0350fd 100644 --- a/app/controllers/note_controller.rb +++ b/app/controllers/note_controller.rb @@ -237,42 +237,24 @@ class NoteController < ApplicationController end end + ## + # Display a list of notes by a specified user 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] + render :template => 'user/no_such_user', :status => :not_found - return 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 diff --git a/app/models/user.rb b/app/models/user.rb index 0c9e76d54..51bc52f3c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 :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] diff --git a/app/views/note/mine.html.erb b/app/views/note/mine.html.erb index d81824324..50c15cd9d 100644 --- a/app/views/note/mine.html.erb +++ b/app/views/note/mine.html.erb @@ -1,5 +1,5 @@

<%= @heading %>

-

<%= @description %>

+

<%= raw @description %>

<%= render :partial => 'notes_paging_nav' %> @@ -12,7 +12,7 @@ <%= t'changeset.changesets.saved_at' %> <%= t'note.mine.last_changed' %> -<% @notes.each do |note| %> +<% @notes.each do |note| -%> bgcolor="#EEEEEE"<% end %>> <% if note.status == "closed" %> @@ -31,7 +31,7 @@ <%= l note.created_at %> <%= l note.updated_at %> -<% end %> +<% end -%> <%= render :partial => 'notes_paging_nav' %>