# HG changeset patch
# User luisf
# Date 1313162495 -3600
# Node ID 9e866f13c984cb5faa06e9d25afa7a7bbce0f0ca
# Parent 658cfb4816182a643eb0f6e7e027193a4dd8e957
Author Autocomplete: Changes in the User/Authorship selection mechanism.
Separated the search box from the name field.
diff -r 658cfb481618 -r 9e866f13c984 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Aug 12 13:15:05 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Aug 12 16:21:35 2011 +0100
@@ -198,21 +198,24 @@
def autocomplete_for_author
@results = []
- authors_list = Author.like(params[:q]).find(:all, :limit => 100)
+ authorships_list = Authorship.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}\" users"
+ logger.debug "Query for \"#{params[:q]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users"
- # need to subtract both lists
- # give priority to the users
+ # need to subtract both lists; give priority to the users
users_list.each do |user|
@results << user
+ logger.error { "Added USER #{user.id} to the results list" }
end
- authors_list.each do |author|
- @results << author unless users_list.include?(author.user)
+ authorships_list.each do |authorship|
+ unless users_list.include?(authorship.author.user)
+ @results << authorship
+ logger.error { "Added AUTHORSHIP #{authorship.id} to the results list" }
+ end
end
-
+
render :layout => false
end
@@ -253,7 +256,7 @@
logger.error { "Cannot remove project from publication list" }
end
- logger.error { "CURRENT projectr name#{proj.name} and wanna delete #{@project.name}" }
+ logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
render(:update) {|page|
page.replace_html "list_projects", :partial => 'list_projects', :id => @publication
@@ -269,10 +272,6 @@
redirect_to :controller => :publications, :action => 'index', :project_id => @project
end
- def identify_author
-
- end
-
private
end
diff -r 658cfb481618 -r 9e866f13c984 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Aug 12 13:15:05 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Aug 12 16:21:35 2011 +0100
@@ -9,52 +9,71 @@
s
end
- def identify_author(author)
+ def generate_autofill_suggestions(item)
+
+ logger.error { "Generate Autofill Suggestions for #{item.class} #{item.id}" }
link_text = ''
suffix = ''
- user = nil
+
+ if item.respond_to? :name_on_paper
+ # if it walks like a duck, than it's an Authorship
+ Rails.logger.debug { "Identify Author (Authorship): class - #{item.class} id - #{item.id}" }
- if author.class == User
+ item_info = {
+ :name_on_paper => item.name_on_paper,
+ :author_user_id => item.author_id,
+ :is_user => '0',
+ :institution => item.institution,
+ :email => item.email
+ }
+
+ link_text = h(item.name_on_paper)
- Rails.logger.debug { "Identify Author: USER" }
+ else
+ Rails.logger.debug { "Identify Author (User): class - #{item.class} id - #{item.id}" }
# fc defined in the users_author_patch
- author_info = author.get_author_info
+ item_info = item.get_author_info
+
+ link_text = h(item.name)
+
+ end
+
+
+ suffix << '' + h(item_info[:institution])
+ suffix << ' ' + h(item_info[:is_user]) + ''
+
+ link_to_function(link_text, "update_author_info(this," + item_info.to_json + ")") + ' ' + suffix
+ end
- elsif author.class == Author
+ def choose_author_link(name, items)
+ s = ''
+ list = []
- Rails.logger.debug { "Identify Author: AUTHOR" }
+ items.sort.each do |item|
+ if item.respond_to? :name_on_paper
+ logger.error { "CHOOSE AUTHOR LINK - Authorship #{item.id}" }
+ list << item
+ else
+ logger.error { "CHOOSE AUTHOR LINK: USER #{item.id}" }
+
+ list << item
+ unless item.author.nil?
+ unless item.author.authorships.nil?
+ list << item.author.authorships
+ list.flatten!
+ end
+ end
+ end
+ end
- author_info = {
- :name_on_paper => author.name,
- :author_user_id => '',
- :is_user => '0',
- :institution => "",
- :email => ""
- }
-
- link_text = h(author.name)
-
- if author.user.nil?
- author_info[:author_user_id] = author.id
- # TODO: AUTHORSHIPS INFORMATION
-# else
-# author_info[:email] = author.user.mail
-# author_info[:institution] = author.user.institution_name
+ if list.length > 0
+ list.each do |element|
+ s << "#{generate_autofill_suggestions element}"
end
end
- suffix = '' + h(author_info[:institution]) + ''
-
- link_to_function(link_text, "update_author_info(this," + author_info.to_json + ")") + ' ' + suffix
- end
-
- def choose_author_link(name, authors_users)
- s = ''
- authors_users.sort.each do |author_user|
- s << "#{identify_author author_user}"
- end
s
end
diff -r 658cfb481618 -r 9e866f13c984 vendor/plugins/redmine_bibliography/app/models/authorship.rb
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Aug 12 13:15:05 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Aug 12 16:21:35 2011 +0100
@@ -7,8 +7,20 @@
accepts_nested_attributes_for :author
accepts_nested_attributes_for :publication
- attr_accessor :is_user, :author_user_id
+ attr_accessor :is_user, :author_user_id, :search_name
before_save :associate_author_user
+
+ named_scope :like, lambda {|q|
+ s = "%#{q.to_s.strip.downcase}%"
+ {:conditions => ["LOWER(name_on_paper) LIKE :s", {:s => s}],
+ :order => 'name_on_paper'
+ }
+ }
+
+
+ def <=>(authorship)
+ name_on_paper.downcase <=> authorship.name_on_paper.downcase
+ end
protected
def associate_author_user
diff -r 658cfb481618 -r 9e866f13c984 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Fri Aug 12 13:15:05 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Fri Aug 12 16:21:35 2011 +0100
@@ -2,16 +2,24 @@
<%= l("label_author_1") %>
+
+ <%= f.text_field :search_name, :size => 25 %>
+
+ <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id(f.object_name, :identify_author), :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, :with => 'q') %>
+
+ <%= link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %>
+
+ <%= h l("text_author_search") %>
+
+
+
+
+
+
+
<%= f.text_field :name_on_paper, :size => 25 %>
- <%= link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %>
<%= h l("text_author_name_on_paper") %>
-
- <%= observe_field( form_tag_id(f.object_name, :name_on_paper), :frequency => 0.5, :update => form_tag_id(f.object_name, :identify_author), :url => { :controller => 'publications', :action => 'autocomplete_for_author' }, :with => 'q')
- %>
-
-
-
<%= f.text_field :institution, :size => 35 %>
diff -r 658cfb481618 -r 9e866f13c984 vendor/plugins/redmine_bibliography/config/locales/en.yml
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml Fri Aug 12 13:15:05 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml Fri Aug 12 16:21:35 2011 +0100
@@ -26,6 +26,7 @@
label_add_me_as_author: "Add me as an author"
label_add_an_author: "Add an author"
label_add_another_author: "Add another author"
+ field_search_name: "Search author"
remove_author: "Remove this author"
@@ -42,7 +43,9 @@
text_author_email: "Author's email address as on the paper."
text_author_institution: "Author's institution name as on paper."
- text_author_name_on_paper: "Name of the author as it appears on paper. (In case it applies, please use the autocomplete suggestions.)"
+ text_author_name_on_paper: "Name of the author as it appears on paper."
+
+ text_author_search: "Search existing authors"
# authorships model
field_institution: "Institution"