Mercurial > hg > soundsoftware-site
changeset 522:ceca8eb1ac6e cannam_integration
Merge from branch "feature_36"
author | Chris Cannam |
---|---|
date | Mon, 25 Jul 2011 13:17:08 +0100 |
parents | 6a141ac4772e (current diff) 3be6bc3c2a17 (diff) |
children | 7c7199e1f174 |
files | |
diffstat | 7 files changed, 68 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Jul 25 13:17:08 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,13 +16,19 @@ @project_id = params[:project_id] @current_user = User.current + end - end def create @publication = Publication.new(params[:publication]) @project = Project.find(params[:project_id]) + logger.error { "PARAMS publication" } + logger.error { params[:publication] } + + # array with the user ids + @users = [] + @publication.projects << @project if @publication.save @@ -193,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 Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Jul 25 13:17:08 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 Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Jul 25 13:17:08 2011 +0100 @@ -12,5 +12,14 @@ def author_search=(string) end + + # setter and getter for virtual attribute :user_id + def user_id + end + def user_id=(uid) + 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/_authorship_fields.rhtml Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Mon Jul 25 13:17:08 2011 +0100 @@ -6,7 +6,7 @@ <legend><%= "Identify Authors in the system…" %></legend> - <%= link_to_function "Add Me as Author", "update_author_info(this," + User.current.to_json + ")", :class => 'icon icon-add', :id => "add_me_as_author" %> + <%= link_to_function "Add Me as Author", "update_author_info(this," + User.current.get_author_info.to_json + ")", :class => 'icon icon-add', :id => "add_me_as_author" %> <p> <%= f.label :author_search, l(:label_project_search) %> @@ -30,7 +30,7 @@ <%= f.text_field :email %><br /> <em><%= h l("text_author_email") %></em><br /> - <%= f.hidden_field :author_id %> + <%= f.hidden_field :user_id %> <%= link_to_remove_fields l("remove_author"), f %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml Mon Jul 25 13:17:08 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/assets/javascripts/authors.js Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Jul 25 13:17:08 2011 +0100 @@ -12,9 +12,12 @@ } function update_author_info(link, author_info){ + $(link).up('div').up('div').select('input[id^=publication_authorships_attributes]').each( function(e){ - key = e.name.split("[").last().trim().sub(']',''); + key = e.name.split("[").last().trim().sub(']',''); + + // test for undefined e.value = author_info[key]; } )
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Mon Jul 25 13:16:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb Mon Jul 25 13:17:08 2011 +0100 @@ -7,7 +7,8 @@ extend ClassMethods base.class_eval do - has_one :publication + has_one :publication + end end #self.included @@ -15,15 +16,37 @@ end module InstanceMethods - def get_author_name - if self.author - self.author.name + + def get_author_info + info = { + :name_on_paper => "", + :email => "", + :institution => "", + :user_id => self.id + } + + unless self.author.nil? + logger.error { "We've got author" } + info[:name_on_paper] = self.author.name + + if self.author.authorships.length > 0 + info[:email] = self.author.authorships.first.email + info[:institution] = self.author.authorships.first.institution + end + else - "No Name" + logger.error { "No author" } + + info[:name_on_paper] = "No Name" + info[:email] = self.mail + if self.ssamr_user_detail + info[:institution] = self.ssamr_user_detail.institution + else + info[:institution] = "No institution" + end end - end - - def get_author_info + + return info end end #InstanceMethods