changeset 405:8a105a53b8f4 feature_36

Refactoring.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 13 Apr 2011 18:16:45 +0100
parents 216a61338322
children 40144aa9dfe7
files vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb 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/models/bibtex_entry.rb vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb
diffstat 7 files changed, 66 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/controllers/bibtex_entries_controller.rb	Wed Apr 13 18:16:45 2011 +0100
@@ -0,0 +1,55 @@
+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 14:29:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Apr 13 18:16:45 2011 +0100
@@ -2,46 +2,6 @@
 
 class PublicationsController < ApplicationController
 
-  # parse string with bibtex authors
-  # return an ordered array
-  def parse_authors
-
-  end
-
-  def parse_bibtex_file
-
-  end
-
-  def parse_bibtex_text
-    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)
-
-        d.fields.keys.map do |k|
-          if k == "title"
-            @publication.title = d[k]
-          else
-            @bentry[k] = d[k]
-          end
-        end
-      end               
-    end
-      
-    @publication.bibtex_entry = @bentry
-      
-    if @publication.save
-      logger.error "SAVED"
-    else
-      logger.error "NOT SAVED"
-    end
-
-    logger.error @publication.bibtex_entry
-  end 
 
   def new
     # we always try to create at least one publication
@@ -63,7 +23,7 @@
 
     # method for creating "pasted" bibtex entries
     if bibtex_entry
-      parse_bibtex_text
+      parse_bibtex_text bibtex_entry
     end
 
     # form's flow control
@@ -78,6 +38,7 @@
     render "new"
   end
 
+
   def index
     @publications = Publication.find(:all)
   end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/helpers/bibtex_entries_helper.rb	Wed Apr 13 18:16:45 2011 +0100
@@ -0,0 +1,5 @@
+require 'bibtex'
+
+module BibtexEntriesHelper
+
+end
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Wed Apr 13 14:29:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Wed Apr 13 18:16:45 2011 +0100
@@ -1,7 +1,3 @@
-# require 'rubygems'
-require 'bibtex'
-
-
 module PublicationsHelper
 
 end
--- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Wed Apr 13 14:29:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Wed Apr 13 18:16:45 2011 +0100
@@ -1,4 +1,4 @@
 class BibtexEntry < ActiveRecord::Base
   belongs_to :publication
-    
+  
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb	Wed Apr 13 14:29:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_new_bibtex_step.html.erb	Wed Apr 13 18:16:45 2011 +0100
@@ -1,10 +1,6 @@
 <h3>New Bibtex</h3>
 
-<p>
-  <%= f.label :title %>
-  <%= f.text_field :title %>
-</p>
-
+<h4>Paste your bibtex entries here</h4>
 <p>
   <%=label_tag :bibtex_entry %>
   <%=text_area_tag :bibtex_entry%>  
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Wed Apr 13 14:29:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Wed Apr 13 18:16:45 2011 +0100
@@ -5,8 +5,8 @@
 
   <%= render :partial  => "#{@publication.current_step}_bibtex_step", :locals => { :f => f }  %>
 
-  <%= f.submit "Continue" %>
-  <%= f.submit "Back", :name => "back_button" unless @publication.first_step? %>
+  <%= f.submit "Submit" %>
+  
 
 <% end %>