# HG changeset patch # User luisf # Date 1353951591 0 # Node ID 3d387b121e85521a1f7b943325a282db5df60586 # Parent cde00909adc80b88a5a6f3f4cb8e4d36dc9e9c20# Parent b9a9efe859073e65894fe1c7181d4557d59dfb6c Merge diff -r b9a9efe85907 -r 3d387b121e85 app/models/attachment.rb --- a/app/models/attachment.rb Mon Nov 26 15:48:19 2012 +0000 +++ b/app/models/attachment.rb Mon Nov 26 17:39:51 2012 +0000 @@ -69,7 +69,7 @@ end end end - + def file nil end @@ -168,7 +168,7 @@ end def self.latest_attach(attachments, filename) - attachments.sort_by(&:created_on).reverse.detect { + attachments.sort_by(&:created_on).reverse.detect { |att| att.filename.downcase == filename.downcase } end diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Nov 26 17:39:51 2012 +0000 @@ -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 @@ -20,6 +22,71 @@ @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_parse_success = true + + begin + bibtex_paste = params[:bibtex_paste] + bib = BibTeX.parse(bibtex_paste) + rescue + # todo: output errors to user + # bib.errors.present? + @bibtex_parse_success = false + # @bibtex_parsing_error = bib.errors[0].trace[4] + # logger.error { "BibTex Parsing Error: #{@bibtex_parsing_error}" } + logger.error { "BibTex Parsing Error" } + end + + respond_to do |format| + # todo: response for HTML + format.html{} + + if @bibtex_parse_success + # todo: should this code be here? + @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html + @bibtex_parsed_authors = bib[0].authors + logger.error { "Authors: #{@bibtex_parsed_authors}" } + end + format.js + + end + end + + +# respond_to do |format| +# format.js { +# render(:update) {|page| +# flash.now[: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 +# +# # for each author simulates a click and fills the author info +## bib[0].authors.each do |author| +## page["add_another_author"].click +## page.alert(bib[0].authors.length) +## page.alert(page["authors"].first.id) +## end +# +# +# +# } +# } +# end + +# rescue BibtexParsingError => e +# logger.error { "Bibtex Parsing Error #{bib.errors}" } + +# end + + + def create @project = Project.find(params[:project_id]) @@ -62,14 +129,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()});" @@ -107,7 +172,7 @@ @author_options = [] if @publication.update_attributes(params[:publication]) - flash[:notice] = "Successfully updated Publication." + flash[:notice] = "Successfully Updated Publication." # expires the previosly cached entries Rails.cache.delete "publication-#{@publication.id}-ieee" @@ -224,6 +289,7 @@ render :layout => false end + def autocomplete_for_author @results = [] diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Mon Nov 26 17:39:51 2012 +0000 @@ -4,6 +4,13 @@ module PublicationsHelper include AuthorshipsHelper + def create_publication_tabs + tabs = [ + {:name => 'bibtex', :partial => 'publications/new/bibtex', :label => :label_bibtex}, + {:name => 'default', :partial => 'publications/new/default', :label => :label_default} + ] + end + def link_to_publication(publication, options={}, html_options = nil) url = {:controller => 'publications', :action => 'show', :id => publication}.merge(options) link_to(h(publication.title), url, html_options) @@ -116,6 +123,7 @@ def print_ieee_format(publication) Rails.cache.fetch("publication-#{publication.id}-ieee") do + publication.print_entry(:ieee) end end diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -1,9 +1,4 @@ -<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> - - -
- - +
>

<%= f.text_field :search_name, :size => 25 %> @@ -12,10 +7,10 @@ <%# link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %>

- <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, - :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + - value" )} %> -

+ <%= f.select :search_results, options_for_select(@author_options), {}, {:size => 5, + :onChange => remote_function( :url => { :controller => :publications, :action => :get_user_info, :object_id => form_object_id(f.object_name) }, :with => "'value=' + + value" )} %> +

@@ -25,7 +20,7 @@

-
+

@@ -38,21 +33,18 @@

- - +

- - <%- if params[:action] == 'new' -%> - <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %> - <%- else -%> - <%= button_to_function l(:label_edit_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %> - <%- end -%> - + <%- if params[:action] == 'new' -%> + <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %> + <%- else -%> + <%= button_to_function l(:label_edit_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %> + <%- end -%> <%= link_to_remove_fields l("remove_author"), f %>

- -
+
+ + diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -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 b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -1,9 +1,9 @@ -<%= f.error_messages %> +<%= f.error_messages %> +<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>

<%= 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} %> @@ -19,18 +19,15 @@
<%= l(:text_doi) %>

+
-
- - -
-

<%= l(:authors) %>

+

<%= l(:authors) %>

- <% f.fields_for :authorships do |builder| -%> - <%= render "authorship_fields", :f => builder %> - <%- end -%> +
+ <% 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] %>
-
- - + \ No newline at end of file diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -0,0 +1,5 @@ + +

+ Author <%= h author %> +

+ diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -1,6 +1,6 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> - <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> + <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> <%= javascript_tag 'Event.observe(window, "load", function(e){show_required_bibtex_fields(' + @bibtype_fields.to_json + ')});' %> <% end %> diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -1,12 +1,23 @@ <% content_for :header_tags do %> - <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> - <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> + <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' -%> + <% end %> +<%= error_messages_for 'publication' %> +

<%=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.

+ + <%= render :partial => 'publications/new/bibtex' %> + + +

+ +
+ + <%= render :partial => 'publications/new/default' %> + + +
\ No newline at end of file diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -0,0 +1,11 @@ +
+ <%= text_area_tag :bibtex_paste, "Please paste your bibtex entry here" , :class => "wiki", :style => 'width:90%' -%> + +
+ + <%= link_to_remote "Parse BiBTeX", :url => { :project_id => @project, :action => :parse_bibtex}, :with => "'bibtex_paste=' + $('bibtex_paste').value" -%> +
+ +

Preview

+ +

Authors

\ No newline at end of file diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/new/_default.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_default.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -0,0 +1,10 @@ +<% form_for @publication, :url => { :project_id => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%> +
+
+ <%= render :partial => 'form', :locals => { :f => f } %> + +
+ <%= f.submit %> +
+
+<%- end -%> \ No newline at end of file diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Mon Nov 26 17:39:51 2012 +0000 @@ -0,0 +1,14 @@ +if @bibtex_parse_success + page.insert_html :bottom, :ieee_prev, @ieee_prev + page.insert_html :top, :content, '
Successfully Parsed BibTeX
' + + @bibtex_parsed_authors.each do |auth| + page.insert_html :bottom, :suggest_bibtex_authors, :partial => "suggest_author" , :locals => {:author => auth} + end + +else + page.insert_html :top, :content, '
Error parsing BibTeX.
' +end + + +flash.discard \ No newline at end of file diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Mon Nov 26 17:39:51 2012 +0000 @@ -1,3 +1,5 @@ +<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> +

<%=l(:label_publication_show)%>

diff -r b9a9efe85907 -r 3d387b121e85 vendor/plugins/redmine_bibliography/assets/javascripts/authors.js --- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Nov 26 15:48:19 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Mon Nov 26 17:39:51 2012 +0000 @@ -6,9 +6,9 @@ function add_author_fields(link, association, content, action) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g"); - $(link).insert({ - before: content.replace(regexp, new_id) - }); + + $('authors').insert(content.replace(regexp, new_id)); + if(action != "new"){ toggle_save_author(new_id, $(link)); };