diff vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb @ 1071:fe32745aaa3d bibplugin_cache

Deletes publication cache on controller update action.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 21 Nov 2012 15:09:58 +0000
parents a0c9cc95bcf3
children 3d387b121e85
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Nov 21 14:42:12 2012 +0000
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Nov 21 15:09:58 2012 +0000
@@ -5,7 +5,7 @@
   unloadable
 
   model_object Publication
-  before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]  
+  before_filter :find_model_object, :except => [:new, :create, :index, :get_bibtex_required_fields, :autocomplete_for_project, :add_author, :sort_author_order, :autocomplete_for_author, :get_user_info ]
   before_filter :find_project_by_project_id, :authorize, :only => [ :edit, :new, :update, :create ]
 
   def new
@@ -16,13 +16,11 @@
     @publication.build_bibtex_entry
 
     # and at least one author
-    # @publication.authorships.build.build_author        
+    # @publication.authorships.build.build_author
     @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
-
-
   end
 
-  def create    
+  def create
     @project = Project.find(params[:project_id])
 
     @author_options = []
@@ -30,7 +28,7 @@
     @publication = Publication.new(params[:publication])
     @publication.projects << @project unless @project.nil?
 
-    if @publication.save 
+    if @publication.save
       @publication.notify_authors_publication_added(@project)
 
       flash[:notice] = "Successfully created publication."
@@ -58,19 +56,19 @@
 
     # method for creating "pasted" bibtex entries
     if bibtex_entry
-      parse_bibtex_list bibtex_entry    
+      parse_bibtex_list bibtex_entry
     end
   end
 
   def get_bibtex_required_fields
 
     unless params[:value].empty?
-      fields = BibtexEntryType.fields(params[:value]) 
+      fields = BibtexEntryType.fields(params[:value])
     end
 
     respond_to do |format|
       format.js {
-        render(:update) {|page|       
+        render(:update) {|page|
           if params[:value].empty?
             page << "hideOnLoad();"
           else
@@ -92,28 +90,29 @@
     end
   end
 
-  def edit   
+  def edit
     find_project_by_project_id unless params[:project_id].nil?
 
     @edit_view = true;
     @publication = Publication.find(params[:id])
     @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
 
-    @author_options = []  
+    @author_options = []
 
-    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)    
+    @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id)
   end
 
-  def update    
-    @publication = Publication.find(params[:id])        
-
+  def update
+    @publication = Publication.find(params[:id])
     @author_options = []
 
-    logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" }
-
     if @publication.update_attributes(params[:publication])
       flash[:notice] = "Successfully updated Publication."
 
+      # expires the previosly cached entries
+      Rails.cache.delete "publication-#{@publication.id}-ieee"
+      Rails.cache.delete "publication-#{@publication.id}-bibtex"
+
       if !params[:project_id].nil?
         redirect_to :action => :show, :id => @publication, :project_id => params[:project_id]
       else
@@ -121,7 +120,7 @@
       end
     else
       render :action => 'edit'
-    end   
+    end
   end
 
 
@@ -143,7 +142,7 @@
     return authors_entry.split(" and ")
   end
 
-  # parses a list of bibtex 
+  # parses a list of bibtex
   def parse_bibtex_list(bibtex_list)
     bibliography = BibTeX.parse bibtex_list
 
@@ -156,11 +155,11 @@
         create_bibtex_entry d
       end
     end
-  end 
+  end
 
-  def create_bibtex_entry(d)        
+  def create_bibtex_entry(d)
     @publication = Publication.new
-    @bentry = BibtexEntry.new        
+    @bentry = BibtexEntry.new
     authors = []
     institution = ""
     email = ""
@@ -178,17 +177,17 @@
       else
         @bentry[field] = d[field]
       end
-    end 
+    end
 
     @publication.bibtex_entry = @bentry
     @publication.save
 
-    # what is this for??? 
+    # what is this for???
     # @created_publications << @publication.id
 
     # need to save all authors
-    #   and establish the author-publication association 
-    #   via the authorships table 
+    #   and establish the author-publication association
+    #   via the authorships table
     authors.each_with_index.map do |authorname, idx|
       author = Author.new(:name => authorname)
       if author.save!
@@ -220,12 +219,12 @@
   def autocomplete_for_project
     @publication = Publication.find(params[:id])
 
-    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects            
+    @projects = Project.active.like(params[:q]).find(:all, :limit => 100) - @publication.projects
     logger.debug "Query for \"#{params[:q]}\" returned \"#{@projects.size}\" results"
     render :layout => false
   end
 
-  def autocomplete_for_author    
+  def autocomplete_for_author
     @results = []
 
     object_id = params[:object_id]
@@ -239,8 +238,8 @@
 
     @results = users_list
 
-    # TODO: can be optimized…    
-    authorships_list.each do |authorship|      
+    # TODO: can be optimized…
+    authorships_list.each do |authorship|
       flag = true
 
       users_list.each do |user|
@@ -254,7 +253,7 @@
       @results << authorship if flag
     end
 
-    render :layout => false    
+    render :layout => false
   end
 
   def get_user_info
@@ -272,7 +271,7 @@
 
     respond_to do |format|
       format.js {
-        render(:update) {|page| 
+        render(:update) {|page|
           page[name_field].value = item.name
           page[email_field].value = item.mail
           page[institution_field].value = item.institution
@@ -294,16 +293,16 @@
   end
 
   def add_project
-    @projects = Project.find(params[:publication][:project_ids])    
+    @projects = Project.find(params[:publication][:project_ids])
     @publication.projects << @projects
-    @project = Project.find(params[:project_id])    
+    @project = Project.find(params[:project_id])
 
-    # TODO luisf should also respond to HTML??? 
+    # TODO luisf should also respond to HTML???
     respond_to do |format|
       format.html { redirect_to :back }
-      format.js { 
-        render(:update) {|page| 
-          page[:add_project_form].reset          
+      format.js {
+        render(:update) {|page|
+          page[:add_project_form].reset
           page.replace_html :list_projects, :partial => 'list_projects'
         }
       }
@@ -320,14 +319,14 @@
         @publication.projects.delete proj if request.post?
       end
     else
-      logger.error { "Cannot remove project from publication list" }      
+      logger.error { "Cannot remove project from publication list" }
     end
 
     logger.error { "CURRENT project name#{proj.name} and wanna delete #{@project.name}" }
 
-    render(:update) {|page| 
+    render(:update) {|page|
       page.replace_html "list_projects", :partial => 'list_projects', :id  => @publication
-    }    
+    }
   end
 
   def destroy