changeset 393:9595ab4cac6b feature_36

DEV Commit: more logic to the publication controller; bibtexentry model, fixtures, test
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 11 Apr 2011 13:31:17 +0100
parents b97577523b0c
children ef8a9bc67e15
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/authorship.rb vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/test/fixtures/bibtex_entries.yml vendor/plugins/redmine_bibliography/test/unit/bibtex_entry_test.rb
diffstat 6 files changed, 93 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Apr 11 12:34:18 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Apr 11 13:31:17 2011 +0100
@@ -5,11 +5,11 @@
   # parse string with bibtex authors
   # return an ordered array
   def parse_authors
-    
+
   end
 
   def parse_bibtex_file
-  
+
   end
 
   def parse_bibtex_text
@@ -17,24 +17,31 @@
 
     if bibtex_entry
       bib = BibTeX.parse bibtex_entry
-      
+
       # parses the bibtex entries
       bib.data.map do |d|
         result = ''
         if d.class == BibTeX::Entry
+          @bentry = BibtexEntry.new
           #    d.replace!(bib.strings)
-          
-          result = [author, '. ', d.title].join
-        end
+
+          d.fields.keys.map do |k|
+            @bentry[k] = d[k]
+          end
+        end                
       end
 
-    end
-  end 
+      @publication.bibtex_entry = @bentry
+
+      logger.error @publication.bibtex_entry
+
+    end 
+  end
 
   def new 
     @publication = Publication.new
     @publication.current_step = session[:publication_step]
-        
+
   end
 
   def create    
@@ -43,14 +50,20 @@
 
     parse_bibtex_text
 
+    if @publication.save
+      logger.error "SAVED"
+    else
+      logger.error "NOT SAVED"
+    end
+
     if params[:back_button]
       @publication.previous_step
     else
       @publication.next_step
     end
-    
+
     session[:publication_step] = @publication.current_step
-    
+
     render "new"
   end
 
@@ -75,5 +88,4 @@
     @authors = @publication.authors
   end
 
-
 end
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Apr 11 12:34:18 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Apr 11 13:31:17 2011 +0100
@@ -1,4 +1,5 @@
 class Authorship < ActiveRecord::Base
   belongs_to :author
   belongs_to :publication
+  
 end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Mon Apr 11 13:31:17 2011 +0100
@@ -0,0 +1,4 @@
+class BibtexEntry < ActiveRecord::Base
+  belongs_to :publication
+    
+end
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Mon Apr 11 12:34:18 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Mon Apr 11 13:31:17 2011 +0100
@@ -3,6 +3,7 @@
 class Publication < ActiveRecord::Base
   has_many :authorships
   has_many :authors, :through => :authorships
+  has_one :bibtex_entry
 
   validates_presence_of :title
   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/test/fixtures/bibtex_entries.yml	Mon Apr 11 13:31:17 2011 +0100
@@ -0,0 +1,53 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+one:
+  id: 1
+  entry_type: 
+  address: 
+  annote: 
+  booktitle: 
+  chapter: 
+  crossref: 
+  edition: 
+  editor: 
+  eprint: 
+  howpublished: 
+  journal: 
+  key: 
+  month: 
+  note: 
+  number: 
+  organization: 
+  pages: 
+  publisher: 
+  school: 
+  series: 
+  type: 
+  url: 
+  volume: 
+  year: 1
+two:
+  id: 2
+  entry_type: 
+  address: 
+  annote: 
+  booktitle: 
+  chapter: 
+  crossref: 
+  edition: 
+  editor: 
+  eprint: 
+  howpublished: 
+  journal: 
+  key: 
+  month: 
+  note: 
+  number: 
+  organization: 
+  pages: 
+  publisher: 
+  school: 
+  series: 
+  type: 
+  url: 
+  volume: 
+  year: 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/test/unit/bibtex_entry_test.rb	Mon Apr 11 13:31:17 2011 +0100
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class BibtexEntryTest < ActiveSupport::TestCase
+  fixtures :bibtex_entries
+
+  # Replace this with your real tests.
+  def test_truth
+    assert true
+  end
+end