# HG changeset patch # User luisf # Date 1342111635 -3600 # Node ID a0c9cc95bcf3f99644b8452e08bccbe73b7cd221 # Parent 75351d69e2ba7271b193569831a367c9a5ee5f02 Now parses a publication using the BibTex-ruby parser and displays both the "text" format and the bibtex format. diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Jul 12 17:47:15 2012 +0100 @@ -3,18 +3,18 @@ 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_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ] - + def new find_project_by_project_id @publication = Publication.new - + # we'll always want a new publication to have its bibtex entry @publication.build_bibtex_entry - + # 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}"]] @@ -29,10 +29,10 @@ @publication = Publication.new(params[:publication]) @publication.projects << @project unless @project.nil? - + if @publication.save @publication.notify_authors_publication_added(@project) - + flash[:notice] = "Successfully created publication." redirect_to :action => :show, :id => @publication, :project_id => @project else @@ -52,7 +52,7 @@ def new_from_bibfile @publication.current_step = session[:publication_step] - + # contents of the paste text area bibtex_entry = params[:bibtex_entry] @@ -78,7 +78,7 @@ end } } - + end end @@ -94,13 +94,13 @@ def edit find_project_by_project_id unless params[:project_id].nil? - + @edit_view = true; @publication = Publication.find(params[:id]) @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type @author_options = [] - + @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id) end @@ -124,9 +124,10 @@ end end + def show find_project_by_project_id unless params[:project_id].nil? - + if @publication.nil? @publications = Publication.all render "index", :alert => 'The publication was not found!' @@ -191,16 +192,17 @@ authors.each_with_index.map do |authorname, idx| author = Author.new(:name => authorname) if author.save! + # todo: catch the errors... puts "SAVED" else puts "NOT SAVED" end author.authorships.create!( - :publication => @publication, - :institution => institution, - :email => email, - :order => idx) + :publication => @publication, + :institution => institution, + :email => email, + :order => idx) end end @@ -211,13 +213,13 @@ def import @publication = Publication.new - - + + end - + def autocomplete_for_project @publication = Publication.find(params[:id]) - + @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results" render :layout => false @@ -225,22 +227,22 @@ def autocomplete_for_author @results = [] - + object_id = params[:object_id] @object_name = "publications[authorships_attributes][#{object_id}][search_results]" - + # cc 20110909 -- revert to like instead of like_unique -- see #289 authorships_list = Authorship.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 \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users" - + @results = users_list # TODO: can be optimized… authorships_list.each do |authorship| flag = true - + users_list.each do |user| if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution Rails.logger.debug { "Rejecting Authorship #{authorship.id}" } @@ -254,8 +256,7 @@ render :layout => false end - - + def get_user_info object_id = params[:object_id] value = params[:value] @@ -266,9 +267,9 @@ name_field = "publication_authorships_attributes_#{object_id}_name_on_paper".to_sym email_field = "publication_authorships_attributes_#{object_id}_email".to_sym institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym - + yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym - + respond_to do |format| format.js { render(:update) {|page| @@ -296,7 +297,7 @@ @projects = Project.find(params[:publication][:project_ids]) @publication.projects << @projects @project = Project.find(params[:project_id]) - + # TODO luisf should also respond to HTML??? respond_to do |format| format.html { redirect_to :back } @@ -308,8 +309,8 @@ } end end - - + + def remove_project @project = Project.find(params[:project_id]) proj = Project.find(params[:remove_project_id]) @@ -321,19 +322,19 @@ else logger.error { "Cannot remove project from publication list" } end - + logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" } - + render(:update) {|page| page.replace_html "list_projects", :partial => 'list_projects', :id => @publication } end - + def destroy find_project_by_project_id - + @publication.destroy - + flash[:notice] = "Successfully deleted Publication." redirect_to :controller => :publications, :action => 'index', :project_id => @project end diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Jul 12 17:47:15 2012 +0100 @@ -114,26 +114,14 @@ s end - def show_cite_proc_entry(publication) - s = "" - - # code that should be moved either to the model or to the controller - - book = BibTeX::Entry.new + def show_cite_proc_entry(publication) + # code that should be moved either to the model or to the controller? - publication.bibtex_entry.attributes.keys.sort.each do |key| - value = publication.bibtex_entry.attributes[key].to_s - next if key == 'id' or key == 'publication_id' or value == "" - - if key == "entry_type" - book[key.to_sym] = publication.bibtex_entry.entry_type_label - else - book[key.to_sym] = value - end - - end + publication.print_entry(:ieee) + end - s << CiteProc.process(book.to_citeproc) + def print_bibtex_entry(publication) + publication.print_entry(:bibtex) end diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/models/author.rb --- a/vendor/plugins/redmine_bibliography/app/models/author.rb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/author.rb Thu Jul 12 17:47:15 2012 +0100 @@ -1,4 +1,6 @@ class Author < ActiveRecord::Base + unloadable + has_many :authorships, :dependent => :destroy has_many :publications, :through => :authorships diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb --- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Thu Jul 12 17:47:15 2012 +0100 @@ -1,4 +1,5 @@ class BibtexEntryType < ActiveRecord::Base + unloadable @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ], diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/models/publication.rb --- a/vendor/plugins/redmine_bibliography/app/models/publication.rb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb Thu Jul 12 17:47:15 2012 +0100 @@ -57,7 +57,34 @@ end end + def print_bibtex_author_names + # this authors are correctly sorted because the authorships model + # already outputs the author names ASC by auth_order + self.authorships.map{|a| a.name_on_paper}.join(' and ') + end - - + def print_entry(style) + bib = BibTeX::Entry.new + + bib.author = self.print_bibtex_author_names + bib.title = self.title + + + self.bibtex_entry.attributes.keys.sort.each do |key| + value = self.bibtex_entry.attributes[key].to_s + next if key == 'id' or key == 'publication_id' or value == "" + + if key == "entry_type" + bib.type = self.bibtex_entry.entry_type_label + else + bib[key.to_sym] = value + end + end + + if style == :ieee + CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html + else + bib.to_s :include => :meta_content + end + end end diff -r 75351d69e2ba -r a0c9cc95bcf3 vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Wed Jul 11 18:03:03 2012 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Jul 12 17:47:15 2012 +0100 @@ -3,10 +3,14 @@

<%=l(:label_publication_show)%>

+

Publication Info

+ <%=h show_cite_proc_entry(@publication)%> + +

Bibtex Format

+ <%=h print_bibtex_entry(@publication) %> +
-<%= @publication.title %> - -<%=h show_cite_proc_entry(@publication)%> +

<%= l(:authors) %>