Mercurial > hg > soundsoftware-site
changeset 519:3be6bc3c2a17 feature_36
Correctly searches and sends the parameters for both users and authors.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Fri, 15 Jul 2011 17:21:05 +0100 |
parents | b24091590b63 |
children | ceca8eb1ac6e 1248a47e81b3 |
files | vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/models/authorship.rb vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb |
diffstat | 5 files changed, 25 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Jul 14 17:10:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Jul 15 17:21:05 2011 +0100 @@ -4,8 +4,7 @@ unloadable before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author] - - + def new @publication = Publication.new @@ -17,8 +16,8 @@ @project_id = params[:project_id] @current_user = User.current + end - end def create @publication = Publication.new(params[:publication]) @@ -27,6 +26,9 @@ logger.error { "PARAMS publication" } logger.error { params[:publication] } + # array with the user ids + @users = [] + @publication.projects << @project if @publication.save @@ -196,20 +198,23 @@ end def autocomplete_for_author - @authors = [] + @results = [] authors_list = Author.like(params[:q]).find(:all, :limit => 100) users_list = User.active.like(params[:q]).find(:all, :limit => 100) - logger.debug "Query for \"#{params[:q]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\"" + logger.debug "Query for \"#{params[:q]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users" # need to subtract both lists - # give priority to the users + # give priority to the users + users_list.each do |user| + @results << user + end - authors_list.each do |author| - @authors << author unless author.user_id.nil? + authors_list.each do |author| + @results << author unless users_list.include?(author.user_id) end - + render :layout => false end
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Jul 14 17:10:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Jul 15 17:21:05 2011 +0100 @@ -10,7 +10,7 @@ end def identify_author(author) - if author.class == User + if author.class == User author_info = { :name_on_paper => author.name, :user_id => author.id @@ -29,10 +29,10 @@ link_to_function(author.name, "update_author_info(this," + author_info.to_json + ")") end - def choose_author_link(name, authors) + def choose_author_link(name, authors_users) s = '' - authors.sort.each do |author| - s << "#{identify_author author}\n" + authors_users.sort.each do |author_user| + s << "#{identify_author author_user}\n" end s end
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Thu Jul 14 17:10:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Jul 15 17:21:05 2011 +0100 @@ -14,16 +14,12 @@ end # setter and getter for virtual attribute :user_id - def user_id - logger.error { "USER ID SETTER" } - logger.error { self } - logger.error { "END USER ID SETTER" } - + def user_id end def user_id=(uid) - # process the user id - # test for undefined - + if User.find(uid).author.nil? + User.find(uid).author = Author.new :name => User.find(uid).name + end end end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Thu Jul 14 17:10:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Fri Jul 15 17:21:05 2011 +0100 @@ -1,3 +1,3 @@ <% if params[:q] && params[:q].length > 1 %> - <%= choose_author_link 'publication[author_ids][]', @authors %> + <%= choose_author_link 'publication[author_ids][]', @results %> <% end %>
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Thu Jul 14 17:10:24 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Fri Jul 15 17:21:05 2011 +0100 @@ -7,7 +7,8 @@ extend ClassMethods base.class_eval do - has_one :publication + has_one :publication + end end #self.included