# HG changeset patch # User luisf # Date 1313592625 -3600 # Node ID 1608b3cb50cddc07432b05e1f6dcd4696c6d90d6 # Parent c3c1091639ad8c0fc420a10a026aba1733c1e017 Fixed User and Authorships Search Query. New Publication: reordered some fields in the form; now correctly saving all authors. diff -r c3c1091639ad -r 1608b3cb50cd vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Aug 16 17:38:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Aug 17 15:50:25 2011 +0100 @@ -197,45 +197,34 @@ render :layout => false end - def autocomplete_for_author - #TODO: luisf. optimize this Query: possible? - + def autocomplete_for_author @results = [] object_id = params[:object_id] @object_name = "publications[authorships_attributes][#{object_id}][search_results]" - - logger.error { "OBJECT NAME #{@object_name}" } - - authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100) + + authorships_list = Authorship.like_unique(params[:q]).find(:all, :limit => 100) users_list = User.active.like(params[:q]).find(:all, :limit => 100) logger.debug "Query for \"#{params[:q]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users" - authorships_list.each do |authorship| - # NEED TO COMPARE AUTHORSHIPS FOR SIMILAR NAME/INST/EMAIL - @results << authorship - logger.error { "Added AUTHORSHIP #{authorship.id} to the results list" } + @results = users_list + + # TODO: can be optimized… + authorships_list.each do |authorship| + flag = true + + users_list.each do |user| + if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution + Rails.logger.debug { "Rejecting Authorship #{authorship.id}" } + flag = false + break + end + end + + @results << authorship if flag end - # need to subtract both lists; give priority to the users - flag = true - users_list.each do |user| - if user.author.nil? - @results << user - else - user.author.authorships.each do |auth| - if authorships_list.include?(auth) - flag = false - break - end - end - @results << user unless flag - end - end - -# @results.uniq! - render :layout => false end @@ -261,9 +250,9 @@ page[institution_field].value = item.institution page[yes_radio].checked = true - page[name_field].disabled = true - page[email_field].disabled = true - page[institution_field].disabled = true + page[name_field].readOnly = true + page[email_field].readOnly = true + page[institution_field].readOnly = true } } end diff -r c3c1091639ad -r 1608b3cb50cd vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Tue Aug 16 17:38:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Wed Aug 17 15:50:25 2011 +0100 @@ -10,9 +10,17 @@ attr_accessor :is_user, :author_user_id, :search_name, :identify_author, :search_results before_save :associate_author_user + named_scope :like_unique, lambda {|q| + s = "%#{q.to_s.strip.downcase}%" + {:conditions => ["LOWER(name_on_paper) LIKE :s OR LOWER(email) LIKE :s", {:s => s}], + :order => 'name_on_paper', + :group => "name_on_paper, institution, email" + } + } + named_scope :like, lambda {|q| s = "%#{q.to_s.strip.downcase}%" - {:conditions => ["LOWER(name_on_paper) LIKE :s", {:s => s}], + {:conditions => ["LOWER(name_on_paper) LIKE :s OR LOWER(email) LIKE :s", {:s => s}], :order => 'name_on_paper' } } @@ -31,6 +39,31 @@ protected def associate_author_user + case self.identify_author + when "no" + author = Author.new + author.save + self.author_id = author.id + else + selected = self.search_results + selected_classname = Kernel.const_get(selected.split('_')[0]) + selected_id = selected.split('_')[1] + object = selected_classname.find(selected_id) + if object.respond_to? :name_on_paper + # Authorship + self.author_id = object.author.id + else + # User + unless object.author.nil? + self.author_id = object.author.id + else + author = Author.new + object.author = author + object.save + self.author_id = object.author.id + end + end + end end end diff -r c3c1091639ad -r 1608b3cb50cd vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Tue Aug 16 17:38:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Wed Aug 17 15:50:25 2011 +0100 @@ -1,46 +1,39 @@
+

<%= l("label_author_1") %>

+ (<%= link_to l(:label_search_existing_author), {}, :onclick => 'Effect.toggle("' + form_tag_id( f.object_name, :search_author ).to_s + '", "appear", {duration:0.3}); return false;' %>) -

<%= 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, :search_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :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" %> -

- <%= 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, :search_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :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") %> -

- -

-

+
Is it this author?

- <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, - :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + - value" )} %> -

-
Is it this author?
-

- <%= f.radio_button :identify_author, "yes", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_yes %>
- <%= f.radio_button :identify_author, "correct", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_correct %>
- <%= f.radio_button :identify_author, "no", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_no %>
+ <%= f.radio_button :identify_author, "yes", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_yes %>
+ <%= f.radio_button :identify_author, "correct", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_correct %>
+ <%= f.radio_button :identify_author, "no", :onClick => "identify_author_status($(this).value, #{form_object_id(f.object_name) });" %><%= f.label :identify_author_no %>

-

-

- <%= f.text_field :name_on_paper, :size => 25 %> - <%= h l("text_author_name_on_paper") %>
- +

+ <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, + :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + + value" )} %> +
+
+ +

- <%= f.text_field :institution, :size => 35 %>
- <%= h l("text_author_institution") %>
- - <%= f.text_field :email, :size => 35 %>
- <%= h l("text_author_email") %>
- - <%= link_to_remove_fields l("remove_author"), f %> + <%= f.text_field :name_on_paper, :size => 25 %>
+ <%= h l("text_author_name_on_paper") %>
+ <%= f.text_field :institution, :size => 35 %>
+ <%= h l("text_author_institution") %>
+ <%= f.text_field :email, :size => 35 %>
+ <%= h l("text_author_email") %>

- -

+
+ <%= link_to_remove_fields l("remove_author"), f %>
diff -r c3c1091639ad -r 1608b3cb50cd vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Tue Aug 16 17:38:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Wed Aug 17 15:50:25 2011 +0100 @@ -19,24 +19,24 @@ switch(status) { case "yes": - name_field.disabled = true; - email_field.disabled = true; - institution_field.disabled = true; + name_field.readOnly = true; + email_field.readOnly = true; + institution_field.readOnly = true; break; case "no": name_field.value = ""; email_field.value = ""; institution_field.value = ""; - name_field.disabled = false; - email_field.disabled = false; - institution_field.disabled = false; + name_field.readOnly = false; + email_field.readOnly = false; + institution_field.readOnly = false; break; case "correct": - name_field.disabled = false; - email_field.disabled = false; - institution_field.disabled = false; + name_field.readOnly = false; + email_field.readOnly = false; + institution_field.readOnly = false; break; } } diff -r c3c1091639ad -r 1608b3cb50cd vendor/plugins/redmine_bibliography/config/locales/en.yml --- a/vendor/plugins/redmine_bibliography/config/locales/en.yml Tue Aug 16 17:38:30 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml Wed Aug 17 15:50:25 2011 +0100 @@ -29,6 +29,8 @@ label_add_another_author: "Add another author" field_search_name: "Search author" field_search_results: "Authors" + label_search_existing_author: "Search Author" + label_author_information: "Author Information" remove_author: "Remove this author"