Mercurial > hg > soundsoftware-site
changeset 1099:c60d957342b0 bibplugin_bibtex
Merge
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 29 Nov 2012 14:42:16 +0000 |
parents | 116346b9cab4 (diff) c5dc7c772de3 (current diff) |
children | 0a4e71b11bd6 |
files | |
diffstat | 14 files changed, 210 insertions(+), 139 deletions(-) [+] |
line wrap: on
line diff
--- a/app/models/attachment.rb Thu Nov 29 14:41:31 2012 +0000 +++ b/app/models/attachment.rb Thu Nov 29 14:42:16 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
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Nov 29 14:42:16 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,46 @@ @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 + + # suggest likely authors/users from database + @suggested_authors = {} + + 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 + + bibtex_parsed_authors.each do |auth| + @suggested_authors[auth] = suggest_authors(auth) + end + + logger.error { "Suggested Authors: #{@suggested_authors}" } + + end + format.js + end + end + + def create @project = Project.find(params[:project_id]) @@ -48,28 +90,14 @@ end end - def new_from_bibfile - @publication.current_step = session[:publication_step] - - # contents of the paste text area - bibtex_entry = params[:bibtex_entry] - - # method for creating "pasted" bibtex entries - if bibtex_entry - parse_bibtex_list bibtex_entry - end - end 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()});" @@ -80,6 +108,7 @@ end end + def add_author if (request.xhr?) render :text => User.find(params[:user_id]).name @@ -90,6 +119,7 @@ end end + def edit find_project_by_project_id unless params[:project_id].nil? @@ -107,7 +137,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" @@ -142,21 +172,6 @@ return authors_entry.split(" and ") end - # parses a list of bibtex - def parse_bibtex_list(bibtex_list) - bibliography = BibTeX.parse bibtex_list - - no_entries = bibliography.data.length - - # parses the bibtex entries - bibliography.data.map do |d| - - if d.class == BibTeX::Entry - create_bibtex_entry d - end - end - end - def create_bibtex_entry(d) @publication = Publication.new @bentry = BibtexEntry.new @@ -185,37 +200,25 @@ # what is this for??? # @created_publications << @publication.id - # need to save all authors - # and establish the author-publication association - # via the authorships table + # Saves all authors, creating the author-publication association via the authorships authors.each_with_index.map do |authorname, idx| author = Author.new(:name => authorname) if author.save! + author.authorships.create!( + :publication => @publication, + :institution => institution, + :email => email, + :order => idx) + # todo: catch the errors... - puts "SAVED" + logger.info { "Author #{author.name} correctly created." } else - puts "NOT SAVED" + logger.error { "Error: author #{authorname} not correctly saved when creating publication with ID=#{@publication.id}." } + end - - author.authorships.create!( - :publication => @publication, - :institution => institution, - :email => email, - :order => idx) end end - # parses the bibtex file - def parse_bibtex_file - - end - - def import - @publication = Publication.new - - - end - def autocomplete_for_project @publication = Publication.find(params[:id]) @@ -224,34 +227,43 @@ render :layout => false end + # returns a list of authors + def suggest_authors(authorname) + firstname = authorname.first + lastname = authorname.last + + # todo: improve name searching algorithm -- lf.20121127 + authorships = Authorship.like(lastname).find(:all, :limit => 100) + + logger.error { "Authorships #{authorships}<-" } + + unless authorships.empty? + authors = authorships.collect {|a| a.author} + authors.uniq! + + # @users is a list of suggested users + # authors = authors.reject { |a| @users.include?(a.user) } + end + + end + 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" + authorships_list = Authorship.like(params[:q]).find(:all, :limit => 100) - @results = users_list + # list with authorships that are associated with users + authorships_with_users = authorships_list.reject { |a| a.author.user.nil? } - # 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}" } - flag = false - break - end - end - - @results << authorship if flag - end + # authorships not associated with a user + orphan_authorships = authorships_list - authorships_with_users + authorships_with_users.map! { |a| a.author.user } + @results = (users_list + authorships_with_users).uniq! + orphan_authorships render :layout => false end
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Nov 29 14:42:16 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) @@ -26,17 +33,17 @@ # creates the select list based on the results array # results is an array with both Users and Authorships objects - @author_options = [] - @results.each do |result| + if @results.size > 0 + author_options = @results.map do |result| + logger.error { "DEBUG --> #{result}" } + email_bit = result.mail.partition('@')[2] - if email_bit != "": - email_bit = "(@#{email_bit})" - end - @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] + email_bit = "(@#{email_bit})" unless email_bit == "" + + ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] end - if @results.size > 0 - s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) + s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) s << observe_field( form_tag_id(object_name, :author_search_results), :on => 'click', :function => "alert('Element changed')", :with => 'q') else s = "<em>No Authors found that match your search… sorry!</em>" @@ -116,6 +123,7 @@ def print_ieee_format(publication) Rails.cache.fetch("publication-#{publication.id}-ieee") do + publication.print_entry(:ieee) end end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -1,32 +1,32 @@ -<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> - - -<div id="authors" class="fields"> -<!-- <h4><%= l("label_author_1") %></h4> --> - +<fieldset> <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> > <p> <%= f.text_field :search_name, :size => 25 %> - <%= observe_field( form_tag_id(f.object_name, :search_name), :frequency => 0.5, :update => form_tag_id( f.object_name, :search_results), :url => { :controller => 'publications', :action => 'autocomplete_for_author', :object_name => form_object_id(f.object_name) }, :with => 'q' ) %> + <%= observe_field form_tag_id(f.object_name, :search_name), + :frequency => 0.5, + :update => form_tag_id( f.object_name, :search_results), + :url => { :controller => 'publications', :action => 'autocomplete_for_author', + :object_name => form_object_id(f.object_name) }, + :with => "'q=' + encodeURIComponent(value)" %> </p> <%# link_to_function l(:label_author_is_me), "update_author_info(this," + User.current.get_author_info.to_json + ")", :id => "add_me_as_author" %> - <p> - <%= 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" )} %> - </p> + <p> + <%= 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" )} %> + </p> <p style="margin-bottom: -2.5em; padding-bottom; 0"><label><%= l(:identify_author_question) %></label></p> <p class="author_identify"> <label class='inline'><%= radio_button_tag(:identify_author, "yes", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_yes ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_yes) %> </label><br /> - + <label class='inline'><%= radio_button_tag(:identify_author, "correct", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_corrections ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_correct) %> </label><br /> - + <label class='inline'><%= radio_button_tag(:identify_author, "no", true, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_no ), :onchange => "identify_author_status($(this).value, #{form_object_id(f.object_name) });") %> <%= l(:identify_author_no) %> </label><br /> </p> - </div> - + </div> + <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> <p> <%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p> @@ -37,22 +37,19 @@ <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p> </p> </div> - <div class="box" id="<%= form_tag_id( f.object_name, :show_author_info ) %>" style="display: none"> - </div> <p> - - <%- 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 %> </p> -</div> -<br/> +<br /> +</fieldset> +
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Thu Nov 29 14:42:16 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 } %> </p> + +<%= observe_field :publication_bibtex_entry_attributes_entry_type, :url => { :controller => :publications, :action => :get_bibtex_required_fields }, + :frequency => 0.25, + :with => 'q' + %> + <p class="bibtex hol"> <%= f.text_field :year, :size => 4 %> </p>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -1,15 +1,13 @@ <%= f.error_messages %> +<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> -<h3><%= f.text_field :title, :required => true, :size => 70 %></h3> <div class="splitcontentleft"> - <h3><%= l(:label_publication_other_details) %></h3> + <h4><%= l(:label_publication_other_details) %></h4> <div class="box tabular"> - <% f.fields_for :bibtex_entry do |builder| -%> - <%= render :partial => 'bibtex_fields', :locals => { :f => builder} %> - <%- end -%> + <p><%= f.text_field :title, :required => true, :size => 70 -%></p> + <p> - <p> <%= f.text_field :external_url, :size => 70 %> <br /> <em><%= l(:text_external_url) %></em> @@ -19,18 +17,22 @@ <br /> <em><%= l(:text_doi) %></em> </p> + <% f.fields_for :bibtex_entry do |builder| -%> + <%= render :partial => 'bibtex_fields', :locals => { :f => builder} %> + <%- end -%> + </div> - </div> + </div> <div class="splitcontentright"> - <h3><%= l(:authors) %></h3> + <h4><%= l(:authors) %></h4> <div class="box tabular"> - <% 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] %> + <div id="authors" class="fields"> + <% f.fields_for :authorships do |builder| -%> + <%= render "authorship_fields", :f => builder %> + <%- end -%> + </div> + <%= link_to_add_author_fields l(:label_add_an_author), f, :authorships, params[:action] -%> </div> -</div> - - +</div> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -0,0 +1,5 @@ + +<p> + Author: <%= h(author[0]) -%> +</p> +
--- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Thu Nov 29 14:42:16 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 %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -1,12 +1,11 @@ <% 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' -%> + <!--<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' -%>--> <% end %> +<%= error_messages_for 'publication' %> +<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div> + <h2><%=l(:label_publication_new)%></h2> -<% form_for @publication, :url => { :project_id => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%> - <%= render :partial => 'form', :locals => { :f => f } %> - <div style="clear:both"></div> - <%= f.submit %> -<% end %> +<%= render_tabs create_publication_tabs %>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_bibtex.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -0,0 +1,17 @@ +<div class="splitcontentleft"> + <div> + <h3>Paste your bibtex entry</h3> + <div class="box"> + <%= text_area_tag :bibtex_paste, "Please paste your bibtex entry here" , :class => "wiki", :style => 'width:90%; height:100px;' -%> + <br /> + <%= link_to_remote "Parse BiBTeX", :url => { :project_id => @project, :action => :parse_bibtex}, :with => "'bibtex_paste=' + $('bibtex_paste').value" -%> + </div> + </div> +</div> + +<div class="splitcontentright"> + <h3>Preview and correct</h3> + + <div class="box" id="ieee_prev"><h3>Preview</h3></div> + <div class="box" id="suggest_bibtex_authors"><h3>Authors</h3></div> +</div> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new/_default.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -0,0 +1,10 @@ +<% form_for @publication, :url => { :project_id => @project, :action => :create }, :builder => TabularFormBuilder do |f| -%> + <div class="settings"> + <fieldset> + <%= render :partial => 'form', :locals => { :f => f } %> + + <div style="clear:both"></div> + <%= f.submit %> + </fieldset> + </div> +<%- end -%> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs Thu Nov 29 14:42:16 2012 +0000 @@ -0,0 +1,14 @@ +if @bibtex_parse_success + page.insert_html :bottom, :ieee_prev, @ieee_prev + page.insert_html :top, :content, '<div class="flash notice">Successfully Parsed BibTeX</div>' + + @suggested_authors.each do |auth| + page.insert_html :bottom, :suggest_bibtex_authors, :partial => "suggest_author" , :locals => {:author => auth} + end + +else + page.insert_html :top, :content, '<div class="flash error">Error parsing BibTeX.</div>' +end + + +flash.discard \ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Nov 29 14:42:16 2012 +0000 @@ -1,3 +1,5 @@ +<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> + <h2><%=l(:label_publication_show)%></h2> <div class="box">
--- a/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Thu Nov 29 14:41:31 2012 +0000 +++ b/vendor/plugins/redmine_bibliography/assets/javascripts/authors.js Thu Nov 29 14:42:16 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)); };