# HG changeset patch
# User luisf
# Date 1354891178 0
# Node ID 7d62d2f497c5dce7c3ee49708c8cfa2b4fce7ec5
# Parent e48a7a36491be5fa57242ac0eb0d35e861db42e0
adds all the necessary hidden fieds; associates authors, users and publications. Known issues associating publications, authors and users.
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Dec 06 21:45:34 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Dec 07 14:39:38 2012 +0000
@@ -45,8 +45,6 @@
end
-
-
def parse_bibtex
find_project_by_project_id
@bibtex_parse_success = true
@@ -99,10 +97,50 @@
def create_from_bibtex
find_project_by_project_id
- @publication = Publication.new(params[:publication])
- debugger
+ # todo: drop unknown parameters from params hash lf.07122012
+ @publication = Publication.new(:title => params[:pub][:title])
+ @publication.build_bibtex_entry(params[:pub][:bibtex_entry])
+ @publication.projects << @project unless @project.nil?
+ params[:pub][:authorships].each do |idx|
+ auth = idx[1]
+
+ authorship = Authorship.new :name_on_paper => auth[:name_on_paper]
+
+ unless auth[:parent].nil?
+ if auth[:parent] > -1
+ logger.error { "AUTH PRENT #{auth[:parent]}" }
+ parent_class, parent_id = auth[:parent].split "_"
+
+ if parent_class == "user"
+ user = User.find(id)
+ author = user.author ||= Author.create(:name => auth[:name_on_paper])
+ else
+ author = Author.find(id)
+ end
+
+ authorship.author_id = author.id
+ end
+ end
+
+
+
+ # todo: test success
+ authorship.save!
+
+ @publication.authorships << authorship
+ end
+
+ if @publication.save
+ @publication.notify_authors_publication_added(@project)
+
+ flash[:notice] = "Successfully created publication."
+ redirect_to :action => :show, :id => @publication, :project_id => @project
+ else
+ render :action => 'new', :project_id => @project
+ end
+
end
def create
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/models/authorship.rb
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Thu Dec 06 21:45:34 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Fri Dec 07 14:39:38 2012 +0000
@@ -1,18 +1,20 @@
class Authorship < ActiveRecord::Base
- unloadable
-
+ unloadable
+
belongs_to :author
belongs_to :publication
-
+
accepts_nested_attributes_for :author
accepts_nested_attributes_for :publication
validates_presence_of :name_on_paper
-
+
attr_accessor :is_user, :author_user_id, :search_name, :identify_author, :search_results
- before_save :associate_author_user
- named_scope :like_unique, lambda {|q|
+ # todo: too much logic here
+ # 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',
@@ -20,27 +22,27 @@
}
}
- named_scope :like, lambda {|q|
+ named_scope :like, 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'
}
}
-
+
def name
return self.name_on_paper
end
-
+
def <=>(authorship)
name.downcase <=> authorship.name.downcase
end
-
+
def mail
return self.email
end
-
- protected
- def associate_author_user
+
+ protected
+ def associate_author_user
case self.identify_author
when "no"
author = Author.new
@@ -66,6 +68,6 @@
self.author_id = object.author.id
end
end
- end
+ end
end
end
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_from_bibtex.html.erb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_from_bibtex.html.erb Fri Dec 07 14:39:38 2012 +0000
@@ -0,0 +1,1 @@
+ <%= hidden_field_tag "pub[authorships][#{index}][name_on_paper]", auth[0] -%>
\ No newline at end of file
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/views/publications/_hidden_bibtex_field.html.erb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_hidden_bibtex_field.html.erb Fri Dec 07 14:39:38 2012 +0000
@@ -0,0 +1,1 @@
+<%= hidden_field_tag "pub[bibtex_entry][#{fieldname}]", value -%>
\ No newline at end of file
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Thu Dec 06 21:45:34 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Fri Dec 07 14:39:38 2012 +0000
@@ -7,13 +7,13 @@
<%- suggestions[1][:authors].each do |auth| -%>
- <%= create_author_suggestion_radio("author_#{index}", auth) -%>
+ <%= create_author_suggestion_radio("pub[authorships][#{index}][parent]", auth) -%>
<%- end -%>
<%- suggestions[1][:users].each do |usr| -%>
- <%= create_user_suggestion_radio("author_#{index}", usr) -%>
+ <%= create_user_suggestion_radio("pub[authorship][#{index}][parent]", usr) -%>
<%- end -%>
- <%= radio_button_tag("author_#{index}", nil, false) -%><%= l(:none_of_above) %>
+ <%= radio_button_tag("pub][authorship][#{index}][parent]", "-1", false) -%><%= l(:none_of_above) %>
<%- end -%>
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Thu Dec 06 21:45:34 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Fri Dec 07 14:39:38 2012 +0000
@@ -13,16 +13,13 @@
Preview and correct
-
Preview
-
-
+
+
- <%= hidden_field_tag "pub_bibtex_title" -%>
- <%= hidden_field_tag "pub_bibtex_entry_type" -%>
- <%= hidden_field_tag "pub_bibtex_year" -%>
+ <%= hidden_field_tag "pub[title]" -%>
<%= f.submit %>
diff -r e48a7a36491b -r 7d62d2f497c5 vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs
--- a/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Thu Dec 06 21:45:34 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Fri Dec 07 14:39:38 2012 +0000
@@ -2,14 +2,19 @@
page.insert_html :bottom, :ieee_prev, @ieee_prev
page.insert_html :top, :content, 'Successfully Parsed BibTeX
'
+ # todo - use authors.each?? instead
@suggested_authors.each_with_index do |auth, idx|
- page.insert_html :bottom, :suggest_bibtex_authors, :partial => "suggest_author", :locals => {:suggestions => auth, :index => idx}
+ page.insert_html :bottom, :publication_authors, :partial => "authorship_from_bibtex", :locals => {:auth => auth, :index => idx}
+
+ page.insert_html :bottom, :publication_authors, :partial => "suggest_author", :locals => {:suggestions => auth, :index => idx}
end
- page[:pub_bibtex_title].value = @publication.title
+ # fills the publication's hidden fields
+ page[:pub_title].value = @publication.title
@publication.bibtex_entry.attributes.each do |k,v|
- page["pub_bibtex_#{k}"].value = v.to_s unless v.nil?
+ page.insert_html :bottom, :publication_info, :partial => "hidden_bibtex_field", :locals => {:fieldname => k, :value => v} unless v.nil?
+
end
else