changeset 685:4481db876cdb feature_36

Feature #238 - Refactoring of the Bibtex Fields Hash and Arrays.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 16 Sep 2011 14:37:24 +0100
parents cd7e10c4ab86
children b1debf464389
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb
diffstat 3 files changed, 32 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 16 13:17:28 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 16 14:37:24 2011 +0100
@@ -63,31 +63,15 @@
   end
 
   def get_bibtex_required_fields
-    all_fields = [ "editor", "publisher", "chapter", "pages", "volume", "series", "address", "edition", "month", "year", "type", "note", "number", "journal", "howpublished", "key", "school" ]
 
-    fields = Hash.new
-    fields[ 'article' ] = [ 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ]
-    fields[ 'book' ] = [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ]
-    fields[ 'booklet' ] = [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ]
-    fields[ 'conference' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'inbook' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
-    fields[ 'incollection' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
-    fields[ 'inproceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'manual' ] = [ 'organization', 'address', 'edition', 'month', 'year', 'note' ]
-    fields[ 'masterthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
-    fields[ 'misc' ] = [ 'howpublished', 'month', 'year', 'note' ]
-    fields[ 'phdthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
-    fields[ 'proceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'techreport' ] = [ 'year', 'type', 'number', 'address', 'month', 'note' ]
-    fields[ 'unpublished' ] = [ 'note', 'month', 'year' ]
+    fields = BibtexEntryType.fields(params[:value])
+    all_fields = BibtexEntryType.all_fields
 
-    entrytype = BibtexEntryType.find(params[:value]).name
-    
     respond_to do |format|
       format.js {
         render(:update) {|page| 
           all_fields.each_with_index do |field, idx|            
-            unless fields[entrytype].include? field
+            unless fields.include? field
               page["publication_bibtex_entry_attributes_#{field}"].up('p').hide()
             else
               page["publication_bibtex_entry_attributes_#{field}"].up('p').show()
@@ -117,27 +101,7 @@
 
     @author_options = []  
     
-    
-    fields = Hash.new
-    fields[ 'article' ] = [ 'journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ]
-    fields[ 'book' ] = [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ]
-    fields[ 'booklet' ] = [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ]
-    fields[ 'conference' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'inbook' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
-    fields[ 'incollection' ] = [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ]
-    fields[ 'inproceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'manual' ] = [ 'organization', 'address', 'edition', 'month', 'year', 'note' ]
-    fields[ 'masterthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
-    fields[ 'misc' ] = [ 'howpublished', 'month', 'year', 'note' ]
-    fields[ 'phdthesis' ] = [ 'school', 'year', 'address', 'month', 'note' ]
-    fields[ 'proceedings' ] = [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ]
-    fields[ 'techreport' ] = [ 'year', 'type', 'number', 'address', 'month', 'note' ]
-    fields[ 'unpublished' ] = [ 'note', 'month', 'year' ]
-    
-    entrytype = BibtexEntryType.find(@selected_bibtex_entry_type_id).name
-    
-    @bibtype_fields = fields[entrytype]
-    
+    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
   end
 
   def update    
--- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Fri Sep 16 13:17:28 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb	Fri Sep 16 14:37:24 2011 +0100
@@ -12,6 +12,5 @@
   def entry_type_label
     entry_type = self.entry_type
     BibtexEntryType.find(entry_type).label
-  end
-  
+  end  
 end
--- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb	Fri Sep 16 13:17:28 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb	Fri Sep 16 14:37:24 2011 +0100
@@ -1,8 +1,35 @@
 class BibtexEntryType < ActiveRecord::Base
+
+  @@all_fields = [ "editor", "publisher", "chapter", "pages", "volume", "series", "address", "edition", "month", "year", "type", "note", "number", "journal", "howpublished", "key", "school" ]
+
+  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 
+                  'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ],
+                  'booklet' , [ 'howpublished', 'address', 'year', 'month', 'note', 'key' ],
+                  'conference', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'inbook', [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ],
+                  'incollection', [ 'editor', 'publisher', 'chapter', 'pages', 'volume', 'series', 'address', 'edition', 'year', 'note' ],
+                  'inproceedings', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'manual', [ 'organization', 'address', 'edition', 'month', 'year', 'note' ],
+                  'masterthesis', [ 'school', 'year', 'address', 'month', 'note' ],
+                  'misc', [ 'howpublished', 'month', 'year', 'note' ],
+                  'phdthesis', [ 'school', 'year', 'address', 'month', 'note' ],
+                  'proceedings', [ 'booktitle', 'year', 'editor', 'pages', 'organization', 'publisher', 'address', 'month', 'note' ],
+                  'techreport', [ 'year', 'type', 'number', 'address', 'month', 'note' ],
+                  'unpublished', [ 'note', 'month', 'year' ]]
+
   def redundant?
     name == 'conference'  # conference is a duplicate of inproceedings
   end
+
   def label
     l("field_bibtex_#{name}")
   end
+
+  def self.fields (type)
+    @@fields[ self.find(type).name ]    
+  end
+
+  def self.all_fields
+    @@all_fields
+  end
 end