# HG changeset patch
# User luisf
# Date 1342627074 -3600
# Node ID be4106d14a359c34b95d77cbe5bac57770ae1ea5
# Parent a0c9cc95bcf3f99644b8452e08bccbe73b7cd221
Parses a pasted bibtex entry and correctly adds its fields *except* the author names/institutions. Todo: Parse the author names/institutions and show the errors (flashing on the top of the page).
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Jul 18 16:57:54 2012 +0100
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
# vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb
+class BibtexParsingError < Exception; end
+
class PublicationsController < ApplicationController
unloadable
model_object Publication
- before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
+ before_filter :find_model_object, :except => [:parse_bibtex, :new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
def new
@@ -18,11 +20,56 @@
# and at least one author
# @publication.authorships.build.build_author
@author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
+ end
+ def parse_bibtex
+ find_project_by_project_id
+
+ @bibtex_paste = params[:bibtex_paste]
+
+ begin
+ bib = BibTeX.parse(@bibtex_paste)
+
+ if bib.errors.present? or bib[0].class == NilClass
+ raise BibtexParsingError, "Bibtex Parsing Error"
+ end
+
+ respond_to do |format|
+ format.js {
+ render(:update) {|page|
+ flash[:notice] = "Correctly parsed BibTeX entry"
+
+ bibtex_entry_no = BibtexEntryType.find_by_name(bib[0].type.to_s).id
+ page["publication_title"].value = bib[0][:title]
+ page["publication_bibtex_entry_attributes_entry_type"].value = bibtex_entry_no
+
+ BibtexEntryType.fields(bibtex_entry_no).each do |field|
+ page["publication_bibtex_entry_attributes_#{field}"].value = bib[0][field]
+ end
+ }
+ }
+ end
+
+ rescue BibtexParsingError => e
+ logger.error { "Bibtex Parsing Error #{bib.errors}" }
+
+ # todo: not showing... should be inside render?
+ flash[:error] = e.message
+
+ respond_to do |format|
+ format.js{
+ render(:update) {|page|
+ }
+ }
+ end
+
+ end
+
end
- def create
+
+ def create
@project = Project.find(params[:project_id])
@author_options = []
@@ -64,14 +111,12 @@
def get_bibtex_required_fields
- unless params[:value].empty?
- fields = BibtexEntryType.fields(params[:value])
- end
+ fields = BibtexEntryType.fields(params[:q])
respond_to do |format|
format.js {
render(:update) {|page|
- if params[:value].empty?
+ if params[:q].empty?
page << "hideOnLoad();"
else
page << "show_required_bibtex_fields(#{fields.to_json()});"
@@ -109,10 +154,8 @@
@author_options = []
- logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" }
-
if @publication.update_attributes(params[:publication])
- flash[:notice] = "Successfully updated Publication."
+ flash[:notice] = "Successfully Updated Publication."
if !params[:project_id].nil?
redirect_to :action => :show, :id => @publication, :project_id => params[:project_id]
@@ -224,6 +267,7 @@
logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
render :layout => false
end
+
def autocomplete_for_author
@results = []
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Wed Jul 18 16:57:54 2012 +0100
@@ -3,12 +3,17 @@
<%= f.collection_select :entry_type,
BibtexEntryType.find(:all).reject { |x| x.redundant? },
:id,
- :label,
- { :selected => @selected_bibtex_entry_type_id, :prompt => true },
- :onChange => remote_function( :url => { :controller => :publications, :action => :get_bibtex_required_fields}, :with => "'value=' + value" )
+ :label,
+ { :prompt => true }
%>
+
+<%= observe_field :publication_bibtex_entry_attributes_entry_type, :url => { :controller => :publications, :action => :get_bibtex_required_fields },
+ :frequency => 0.25,
+ :with => 'q'
+ %>
+
<%= f.text_field :year, :size => 4 %>
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Wed Jul 18 16:57:54 2012 +0100
@@ -2,8 +2,7 @@
<%= f.text_field :title, :required => true, :size => 70 %>
-
-
<%= l(:label_publication_other_details) %>
+
<%= l(:label_publication_other_details) %>
<% f.fields_for :bibtex_entry do |builder| -%>
<%= render :partial => 'bibtex_fields', :locals => { :f => builder} %>
@@ -14,18 +13,12 @@
<%= l(:text_external_url) %>
+
-
+<%= l(:authors) %>
+
+ <% f.fields_for :authorships do |builder| -%>
+ <%= render "authorship_fields", :f => builder %>
+ <%- end -%>
+ <%= link_to_add_author_fields l(:label_add_an_author), f, :authorships, params[:action] %>
-
-
-
<%= l(:authors) %>
-
- <% f.fields_for :authorships do |builder| -%>
- <%= render "authorship_fields", :f => builder %>
- <%- end -%>
- <%= link_to_add_author_fields l(:label_add_an_author), f, :authorships, params[:action] %>
-
-
-
-
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Wed Jul 18 16:57:54 2012 +0100
@@ -5,8 +5,21 @@
<%=l(:label_publication_new)%>
-<% form_for @publication, :url => { :project_id => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%>
- <%= render :partial => 'form', :locals => { :f => f } %>
-
- <%= f.submit %>
-<% end %>
+To create a publication you can either parse a BibTeX entry or enter the publication details manually.
+
+
+
+ <%- remote_form_for @publication, :url => { :project_id => @project, :action => :parse_bibtex } do |f| -%>
+ <%= text_area_tag :bibtex_paste, "Please paste your bibtex entry here", :rows => 6, :style => 'width:90%' %>
+
+ <%= f.submit "Parse BibTex" %>
+ <%- end -%>
+
+
+
+ <% form_for @publication, :url => { :project_id => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%>
+ <%= render :partial => 'form', :locals => { :f => f } %>
+
+ <%= f.submit %>
+ <% end %>
+
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Wed Jul 18 16:57:54 2012 +0100
@@ -5,9 +5,12 @@
Publication Info
<%=h show_cite_proc_entry(@publication)%>
-
- Bibtex Format
- <%=h print_bibtex_entry(@publication) %>
+
+
+
+ Bibtex Code
+ <%= text_area_tag :bibtex_code, h(print_bibtex_entry(@publication)), :readonly => true, :rows => 6, :style => 'width:90%' %>
+
@@ -28,10 +31,6 @@
<%= sortable_element("authorships", :url => { :controller => :publications, :action => :sort_author_order }, :handle => "handle") %>
<%- end -%>
-<%- if @publication.bibtex_entry != nil -%>
- <%= show_bibtex_fields(@publication.bibtex_entry) %>
-<%- end -%>
-
<% unless @publication.external_url.blank? %>
<%= l(:field_external_url) %>
diff -r a0c9cc95bcf3 -r be4106d14a35 vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css
--- a/vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Thu Jul 12 17:47:15 2012 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Wed Jul 18 16:57:54 2012 +0100
@@ -44,3 +44,5 @@
div#bibliography dd span.year { padding-left: 0.6em; }
div#bibliography h3 { background: url(../../../images/table_multiple.png) no-repeat 0% 50%; padding-left: 20px; }
+
+