changeset 1105:468967d012aa bibplugin_bibtex

Dev commit - fails when saving the temporary publication (no authors).
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 05 Dec 2012 16:52:43 +0000
parents c018d0c89c94
children b5c396ea06e4
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs
diffstat 5 files changed, 96 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Dec 04 18:15:17 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Dec 05 16:52:43 2012 +0000
@@ -19,13 +19,34 @@
 
     # and at least one author
     # @publication.authorships.build.build_author
+    # todo - do we still need this? --lf.20121205
     @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
   end
 
+  # the argument is a ruby-bibtex parsed entry
+  def create_bibtex_entry(bibtex)
+
+    bibtex.fields.keys.map do |field|
+      case field.to_s
+      when "title"
+        @publication.title = bibtex[field]
+      when "author"
+        bibtex.authors.each do |auth|
+          logger.error { "AUTHOR #{auth}" }
+        end
+      else
+        @publication.bibtex_entry[field] = bibtex[field]
+      end
+    end
+  end
+
   def parse_bibtex
     find_project_by_project_id
     @bibtex_parse_success = true
 
+    @publication = Publication.new
+    @publication.build_bibtex_entry
+
     begin
       bibtex_paste = params[:bibtex_paste]
       bib = BibTeX.parse(bibtex_paste)
@@ -42,24 +63,32 @@
     @suggested_authors = {}
 
     respond_to do |format|
-        # todo: response for HTML
-        format.html{}
-
         if @bibtex_parse_success
           # todo: should this code be here?
+
+          # creates the entry
+          create_bibtex_entry(bib[0])
+          logger.error { "Bibtex Entry #{@bibtex_entry}" }
+
+
           @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
           bibtex_parsed_authors = bib[0].authors
 
-          # todo: need to create a bibtex object
-          ## and add it to the session hash
-
-
           # creates stucture with author suggestions
           bibtex_parsed_authors.each do |auth|
             @suggested_authors[auth] = suggest_authors(auth.last)
+
+            @publication.authorships.new :name_on_paper => auth
+            logger.error { "Added Authorship: #{auth}" }
           end
+
+          # can temporarily save
+          # note that the publication still needs reviewing
+          @publication.save!
         end
 
+
+        # todo: response for HTML
         format.js
     end
   end
@@ -71,7 +100,6 @@
 
   end
 
-
   def create
     @project = Project.find(params[:project_id])
 
@@ -163,7 +191,6 @@
     end
   end
 
-
   def show
     find_project_by_project_id unless params[:project_id].nil?
 
@@ -176,24 +203,6 @@
     end
   end
 
-  # the argument is a ruby-bibtex parsed entry
-  def create_bibtex_entry(bibtex)
-    @bibtex_entry = BibtexEntry.new
-
-    bibtex.fields.keys.map do |field|
-      case field.to_s
-      when "title"
-        @publication.title = d[field]
-      when "author"
-        authors.each do |auth|
-          logger.warning { "AUTHOR #{author}" }
-        end
-      else
-        @bibtex_entry[field] = d[field]
-      end
-    end
-  end
-
   def autocomplete_for_project
     @publication = Publication.find(params[:id])
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Tue Dec 04 18:15:17 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb	Wed Dec 05 16:52:43 2012 +0000
@@ -1,8 +1,8 @@
 <p>
   <label for="bibtex_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label>
-	<%= f.collection_select :entry_type, 
-	        BibtexEntryType.find(:all).reject { |x| x.redundant? }, 
-	        :id, 
+	<%= f.collection_select :entry_type,
+	        BibtexEntryType.find(:all).reject { |x| x.redundant? },
+	        :id,
 	        :label,
 	        { :prompt => true }
 	%>
@@ -14,72 +14,72 @@
      :with => 'q'
      %>
 
-<p class="bibtex hol"> 
-  <%= f.text_field :year, :size => 4 %> 
+<p class="bibtex hol">
+  <%= f.text_field :year, :size => 4 %>
 </p>
-<p class="bibtex hol"> 
-  <%= f.text_field :month, :size => 4%> 
+<p class="bibtex hol">
+  <%= f.text_field :month, :size => 4%>
 </p>
-<p class="bibtex hol">  
-  <%= f.text_field :chapter, :size => 15%>  
-</p>  
-<p class="bibtex hol"> 
-  <%= f.text_field :editor, :size => 33  %>  
-</p>  
-<p class="bibtex hol"> 
-  <%= f.text_field :booktitle, :size => 33  %>  
-</p>  
-<p class="bibtex hol"> 
-  <%= f.text_field :publisher,:size => 33  %>  
-</p>  
-<p class="bibtex hol"> 
-  <%= f.text_field :pages, :size => 12 %>  
+<p class="bibtex hol">
+  <%= f.text_field :chapter, :size => 15%>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
+  <%= f.text_field :editor, :size => 33  %>
+</p>
+<p class="bibtex hol">
+  <%= f.text_field :booktitle, :size => 33  %>
+</p>
+<p class="bibtex hol">
+  <%= f.text_field :publisher,:size => 33  %>
+</p>
+<p class="bibtex hol">
+  <%= f.text_field :pages, :size => 12 %>
+</p>
+<p class="bibtex hol">
  <%= f.text_field :address %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :annote %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :crossref %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :edition %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :eprint %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :howpublished %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :journal %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :key %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :note %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :number %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :organization %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :school %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :series %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :type %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :url %>
 </p>
-<p class="bibtex hol"> 
+<p class="bibtex hol">
  <%= f.text_field :volume %>
 </p>
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb	Tue Dec 04 18:15:17 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb	Wed Dec 05 16:52:43 2012 +0000
@@ -1,16 +1,19 @@
-
+<% logger.error { "suggestions #{suggestions}//" } %>
 <% logger.error { "index #{index}//" } %>
 
-<p>
-  Suggestions for Author: <%= h(suggestions[0]) -%>
-<br />
-  <%- suggestions[1][:authors].each do |auth| -%>
-    <%= create_author_suggestion_radio("author_#{index}", auth) -%>
-  <%- end -%>
-<br />
-  <%- suggestions[1][:users].each do |usr| -%>
-    <%= create_user_suggestion_radio("author_#{index}", usr) -%>
-  <%- end -%>
-<br />
-</p>
+<%- if suggestions[1][:authors].count + suggestions[1][:users].count > 0 -%>
+  <p>
+    Could the author "<%= h(suggestions[0]) -%>" be one of the following?
+    <br />
 
+    <%- suggestions[1][:authors].each do |auth| -%>
+      <%= create_author_suggestion_radio("author_#{index}", auth) -%>
+    <%- end -%>
+    <br />
+    <%- suggestions[1][:users].each do |usr| -%>
+      <%= create_user_suggestion_radio("author_#{index}", usr) -%>
+    <%- end -%>
+    <%= radio_button_tag("author_#{index}", nil, false) -%><%= l(:none_of_above) %>
+    <br />
+  </p>
+<%- end -%>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb	Tue Dec 04 18:15:17 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb	Wed Dec 05 16:52:43 2012 +0000
@@ -18,6 +18,10 @@
     <div class="box" id="suggest_bibtex_authors"><h3>Authors</h3></div>
   </div>
 
+  <div id="publication_info">
+    <%= hidden_field_tag "publication_id" %>
+  </div>
+
   <%= f.submit %>
 
 <%- end -%>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs	Tue Dec 04 18:15:17 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs	Wed Dec 05 16:52:43 2012 +0000
@@ -3,9 +3,11 @@
   page.insert_html :top, :content, '<div class="flash notice">Successfully Parsed BibTeX</div>'
 
   @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, :suggest_bibtex_authors, :partial => "suggest_author", :locals => {:suggestions => auth, :index => idx}
   end
 
+  page.replace_html :publication_id, @publication.id
+
 else
   page.insert_html :top, :content, '<div class="flash error">Error parsing BibTeX.</div>'
 end