# HG changeset patch # User Chris Cannam # Date 1311596228 -3600 # Node ID ceca8eb1ac6ec1cce1a9f5620964a6bd4a77ff81 # Parent 6a141ac4772ec51b3158b2d5c046527d316dfd1a# Parent 3be6bc3c2a17f23d94e7878b3c9381a905824a29 Merge from branch "feature_36" diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- 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 diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- 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 diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/app/models/authorship.rb --- 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 diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- 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 @@ - <%= 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" %>
<%= f.label :author_search, l(:label_project_search) %>
@@ -30,7 +30,7 @@
<%= f.text_field :email %>
<%= h l("text_author_email") %>
- <%= f.hidden_field :author_id %>
+ <%= f.hidden_field :user_id %>
<%= link_to_remove_fields l("remove_author"), f %>
diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.rhtml
--- 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 %>
diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/assets/javascripts/authors.js
--- 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];
}
)
diff -r 6a141ac4772e -r ceca8eb1ac6e vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb
--- 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