Mercurial > hg > soundsoftware-site
changeset 407:96910efbd45e feature_36
Pasting of bibtex entries already working correctly.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 14 Apr 2011 17:35:31 +0100 |
parents | 40144aa9dfe7 |
children | cd3158bf28b5 |
files | vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb |
diffstat | 5 files changed, 58 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Apr 14 12:28:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Thu Apr 14 17:35:31 2011 +0100 @@ -2,11 +2,10 @@ class PublicationsController < ApplicationController - def new # we always try to create at least one publication @publication = Publication.new - + # the step we're at in the form @publication.current_step = session[:publication_step] end @@ -18,12 +17,9 @@ # contents of the paste text area bibtex_entry = params[:bibtex_entry] - # debug message - logger.error bibtex_entry - # method for creating "pasted" bibtex entries if bibtex_entry - parse_bibtex_text bibtex_entry + parse_bibtex_list bibtex_entry end # form's flow control @@ -52,7 +48,6 @@ logger.error "AAAA update" - end def show @@ -60,31 +55,10 @@ @authors = @publication.authors end - - - - - - - - - - - # parse string with bibtex authors def parse_authors(authors_entry) # in bibtex the authors are always seperated by "and" - authors = authors_entry.split(" and ") - - # need to save all authors - - - return authors - end - - # parses the bibtex file - def parse_bibtex_file - + return authors_entry.split(" and ") end # parses a list of bibtex @@ -93,57 +67,65 @@ no_entries = bibliography.data.length - puts "Gonna parse " + no_entries.to_s + " Bibtex entries" - # parses the bibtex entries bibliography.data.map do |d| - create_bibtex_entry d + + if d.class == BibTeX::Entry + create_bibtex_entry d + end end + end + + def create_bibtex_entry(d) + @publication = Publication.new + @bentry = BibtexEntry.new + authors = [] + institution = "" + email = "" + + d.fields.keys.map do |field| + case field.to_s + when "author" + authors = parse_authors d[field] + when "title" + @publication.title = d[field] + when "institution" + institution = d[field] + when "email" + email = d[field] + else + @bentry[field] = d[field] + end + end @publication.bibtex_entry = @bentry - - if @publication.save - puts "SAVED" - else - puts "NOT SAVED" - end - - Rails.logger.error @publication.bibtex_entry - end - - - - def create_bibtex_entry(d) - - if d.class == BibTeX::Entry - # creates a new BibTex instance - @bentry = BibtexEntry.new - - d.fields.keys.map do |field| - - case field.to_s - when "author" - authors = parse_authors d[field] - puts "Number of authors: " + authors.length.to_s - when "title" - puts "The title " + d[field] - @publication.title = d[field] - when "The institution" - puts "institution " + d[field] - when "email" - puts "The email " + d[field] - else - @bentry[field] = d[field] - puts field.to_s + " " + d[field] - end + @publication.save + + # need to save all authors + # and establish the author-publication association + # via the authorships table + authors.each_with_index.map do |authorname, idx| + author = Author.new(:name => authorname) + if author.save! + puts "SAVED" + else + puts "NOT SAVED" end - @bentry.save! - end + author.authorships.create!( + :publication => @publication, + :institution => institution, + :email => email, + :order => idx) + + end + end + + + # parses the bibtex file + def parse_bibtex_file + end - - - - + end
--- a/vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb Thu Apr 14 12:28:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb Thu Apr 14 17:35:31 2011 +0100 @@ -1,5 +1,3 @@ -require 'bibtex' - module BibtexEntriesHelper end \ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Apr 14 12:28:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Apr 14 17:35:31 2011 +0100 @@ -1,3 +1,5 @@ +require 'bibtex' + module PublicationsHelper end
--- a/vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb Thu Apr 14 12:28:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb Thu Apr 14 17:35:31 2011 +0100 @@ -1,5 +1,5 @@ <h2>Authors#index</h2> <% @authors.each do |author| %> - <%= author.id %> + <p><%= author.name %> - <%= author.publications.first.title%></p> <% end %> \ No newline at end of file