# HG changeset patch # User luisf # Date 1313412901 -3600 # Node ID 68c6b060385ce2b1c90cc6a1ce07aa9664961193 # Parent 9e866f13c984cb5faa06e9d25afa7a7bbce0f0ca development commit: still users/authors management diff -r 9e866f13c984 -r 68c6b060385c vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Aug 12 16:21:35 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Aug 15 13:55:01 2011 +0100 @@ -20,6 +20,9 @@ @project_id = params[:project_id] @current_user = User.current + + @options = [] + @results = [] end @@ -196,6 +199,8 @@ end def autocomplete_for_author + #TODO: luisf. optimize this Query: possible? + @results = [] authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100) @@ -203,19 +208,30 @@ 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" } + end + # need to subtract both lists; give priority to the users + flag = true users_list.each do |user| - @results << user - logger.error { "Added USER #{user.id} to the results list" } - end - - authorships_list.each do |authorship| - unless users_list.include?(authorship.author.user) - @results << authorship - logger.error { "Added AUTHORSHIP #{authorship.id} to the results list" } + 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 diff -r 9e866f13c984 -r 68c6b060385c vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Aug 12 16:21:35 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Aug 15 13:55:01 2011 +0100 @@ -47,10 +47,14 @@ link_to_function(link_text, "update_author_info(this," + item_info.to_json + ")") + ' ' + suffix end - def choose_author_link(name, items) - s = '' + def choose_author_link(items) + # called by autocomplete_for_author (publications' action/view) + # creates the select list based on the results array + # results is an array with both Users and Authorships objects + + s = '' list = [] - + items.sort.each do |item| if item.respond_to? :name_on_paper logger.error { "CHOOSE AUTHOR LINK - Authorship #{item.id}" } @@ -74,7 +78,23 @@ end end - s + @options = [] + @results.each do |result| + @options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"] + end + + if @results.size > 0 + s = select_tag('country', options_for_select(@options), :size => 3) + s << observe_field( 'country', :on => 'click', :function => "alert('Element changed')", :with => 'q') + + s << radio_button_tag("publication[authorship_attributes]", "category", "rails") + s << radio_button_tag("post", "category", "java") + s << radio_button_tag("post", "category", "java") + + else + s = "No Authors found that match your search… sorry!" + end + end def link_to_remove_fields(name, f) diff -r 9e866f13c984 -r 68c6b060385c vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Aug 12 16:21:35 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Aug 15 13:55:01 2011 +0100 @@ -7,7 +7,7 @@ accepts_nested_attributes_for :author accepts_nested_attributes_for :publication - attr_accessor :is_user, :author_user_id, :search_name + attr_accessor :is_user, :author_user_id, :search_name, :add_this_author, :correct_author_info, :ignore_author before_save :associate_author_user named_scope :like, lambda {|q| @@ -17,9 +17,16 @@ } } + def name + return self.name_on_paper + end def <=>(authorship) - name_on_paper.downcase <=> authorship.name_on_paper.downcase + name.downcase <=> authorship.name.downcase + end + + def mail + return self.email end protected diff -r 9e866f13c984 -r 68c6b060385c vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Fri Aug 12 16:21:35 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Mon Aug 15 13:55:01 2011 +0100 @@ -13,10 +13,13 @@

-

+
+ <%= f.radio_button :add_this_author, false %> + <%= f.radio_button :add_this_author, false %> + <%= f.radio_button :add_this_author, true %>

- +

<%= f.text_field :name_on_paper, :size => 25 %> <%= h l("text_author_name_on_paper") %>
diff -r 9e866f13c984 -r 68c6b060385c vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Fri Aug 12 16:21:35 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Mon Aug 15 13:55:01 2011 +0100 @@ -1,5 +1,4 @@ -

+