Mercurial > hg > soundsoftware-site
changeset 592:68c6b060385c feature_36
development commit: still users/authors management
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 15 Aug 2011 13:55:01 +0100 |
parents | 9e866f13c984 |
children | 7234e0a90c62 |
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/_authorship_fields.rhtml vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml |
diffstat | 5 files changed, 64 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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 = "<em>No Authors found that match your search… sorry!</em>" + end + end def link_to_remove_fields(name, f)
--- 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
--- 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 @@ </p> <p> - <div id="<%= form_tag_id(f.object_name, :identify_author) %>"> + <div id="<%= form_tag_id( f.object_name, :identify_author ) %>"> + <%= f.radio_button :add_this_author, false %> + <%= f.radio_button :add_this_author, false %> + <%= f.radio_button :add_this_author, true %> </div> </p> - + <p> <%= f.text_field :name_on_paper, :size => 25 %> <em><%= h l("text_author_name_on_paper") %></em><br />
--- 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 @@ -<ul> <% if params[:q] && params[:q].length > 1 %> - <%= choose_author_link 'publication[author_ids][]', @results %> + <%= choose_author_link @results %> <% end %> -</ul> +