changeset 406:40144aa9dfe7 feature_36

Corrected migration: added the "name" column to the table.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 14 Apr 2011 12:28:01 +0100
parents 8a105a53b8f4
children 96910efbd45e
files vendor/plugins/redmine_bibliography/app/controllers/authors_controller.rb vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/db/migrate/001_create_authors.rb
diffstat 4 files changed, 88 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/authors_controller.rb	Wed Apr 13 18:16:45 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/authors_controller.rb	Thu Apr 14 12:28:01 2011 +0100
@@ -2,6 +2,6 @@
   
   def index
     @authors = Author.find(:all)
+  end
 
-  end
 end
--- a/vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb	Wed Apr 13 18:16:45 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb	Thu Apr 14 12:28:01 2011 +0100
@@ -1,55 +1,3 @@
 class BibtexEntriesController < ApplicationController
 
-  # parse string with bibtex authors
-  # return an ordered array
-  def parse_authors
-
-  end
-
-  # parses the bibtex file
-  def parse_bibtex_file
-
-  end
-
-  def parse_bibtex_list(bibtex_list)
-    bibliography = BibTeX.parse bibtex_list
-
-    no_entries =  bibliography.data.length
-
-    logger.error "Gonna parse " no_entries.to_s " Bibtex entries"
-
-    # parses the bibtex entries
-    bibliography.data.map do |d|
-      create_bibtex_entry d
-    end
-
-    @publication.bibtex_entry = @bentry
-
-    if @publication.save
-      logger.error "SAVED"
-    else
-      logger.error "NOT SAVED"
-    end
-
-    logger.error @publication.bibtex_entry
-  end 
-
-
-
-  def create_bibtex_entry(d)
-    result = ''
-    if d.class == BibTeX::Entry
-      @bentry = BibtexEntry.new
-
-      d.fields.keys.map do |k|
-        if k == "title"
-          @publication.title = d[k]
-        else
-          @bentry[k] = d[k]
-        end
-      end
-      @bentry.save!
-    end 
-  end
-
 end
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Apr 13 18:16:45 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Thu Apr 14 12:28:01 2011 +0100
@@ -60,4 +60,90 @@
     @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
+
+  end
+
+  # parses a list of bibtex 
+  def parse_bibtex_list(bibtex_list)
+    bibliography = BibTeX.parse bibtex_list
+
+    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
+    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
+      end
+
+      @bentry.save!
+    end 
+  end
+
+
+
+
+
 end
--- a/vendor/plugins/redmine_bibliography/db/migrate/001_create_authors.rb	Wed Apr 13 18:16:45 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/db/migrate/001_create_authors.rb	Thu Apr 14 12:28:01 2011 +0100
@@ -2,6 +2,7 @@
   def self.up
     create_table :authors do |t|
       t.column :user_id, :integer
+      t.column :name, :string
     end
   end