changeset 1093:294545c0282d bibplugin_bibtex

minor changes on structure of suggestions; deleted some unused code
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 27 Nov 2012 17:39:01 +0000
parents d6e59c6f10bd
children 9b7f99b7cb14
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs
diffstat 3 files changed, 27 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Nov 26 17:41:48 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Nov 27 17:39:01 2012 +0000
@@ -38,6 +38,9 @@
       logger.error { "BibTex Parsing Error" }
     end
 
+    # suggest likely authors/users from database
+    @suggested_authors = {}
+
     respond_to do |format|
         # todo: response for HTML
         format.html{}
@@ -45,11 +48,16 @@
         if @bibtex_parse_success
           # todo: should this code be here?
           @ieee_prev = CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
-          @bibtex_parsed_authors = bib[0].authors
-          logger.error { "Authors: #{@bibtex_parsed_authors}" }
+          bibtex_parsed_authors = bib[0].authors
+
+          bibtex_parsed_authors.each do |auth|
+            @suggested_authors[auth] = suggest_authors(auth)
+          end
+
+          logger.error { "Suggested Authors: #{@suggested_authors}" }
+
         end
         format.js
-
     end
   end
 
@@ -270,17 +278,6 @@
     end
   end
 
-  # parses the bibtex file
-  def parse_bibtex_file
-
-  end
-
-  def import
-    @publication = Publication.new
-
-
-  end
-
   def autocomplete_for_project
     @publication = Publication.find(params[:id])
 
@@ -289,6 +286,17 @@
     render :layout => false
   end
 
+  # returns a list of authors and users
+  def suggest_authors(author)
+    firstname = author.first
+    lastname = author.last
+
+    # todo: improve name searching algorithm -- lf.20121127
+    authorships = Authorship.like(lastname).find(:all, :limit => 100).count
+    users = User.like(lastname).find(:all, :limit => 100).count
+
+    # todo: finish implementing. Use same code as in autocomplete_for_author
+  end
 
   def autocomplete_for_author
     @results = []
@@ -304,10 +312,11 @@
 
     @results = users_list
 
-    # TODO: can be optimized…
+    # todo: can be optimized…
     authorships_list.each do |authorship|
       flag = true
 
+      # todo: refactor this code using select -- lf.20121127
       users_list.each do |user|
         if authorship.name == user.name && authorship.email == user.mail && authorship.institution == user.institution
           Rails.logger.debug { "Rejecting Authorship #{authorship.id}" }
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb	Mon Nov 26 17:41:48 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_suggest_author.html.erb	Tue Nov 27 17:39:01 2012 +0000
@@ -1,5 +1,6 @@
 
 <p>
-  Author <%= h author %>
+  Author <%= h author[0] %>
+
 </p>
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs	Mon Nov 26 17:41:48 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/parse_bibtex.rjs	Tue Nov 27 17:39:01 2012 +0000
@@ -2,7 +2,7 @@
   page.insert_html :bottom, :ieee_prev, @ieee_prev
   page.insert_html :top, :content, '<div class="flash notice">Successfully Parsed BibTeX</div>'
 
-  @bibtex_parsed_authors.each do |auth|
+  @suggested_authors.each do |auth|
     page.insert_html :bottom, :suggest_bibtex_authors, :partial => "suggest_author" , :locals => {:author => auth}
   end