changeset 564:95bbf7849d40 cannam_integration

Merge from branch feature_36
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 08 Aug 2011 11:52:12 +0100
parents 61e0de6cc1bb (current diff) 82a6e3756383 (diff)
children a47abc953e45
files vendor/plugins/redmine_bibliography/app/views/publications/__author_form.html.erb
diffstat 10 files changed, 103 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -3,6 +3,9 @@
 class PublicationsController < ApplicationController
   unloadable
   
+  model_object Publication
+  before_filter :find_model_object, :except => [:new, :create, :index, :autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author]
+  
   # before_filter :find_project, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author]
     
   def new
@@ -24,10 +27,10 @@
     find_project_by_project_id
     
     @publication = Publication.new(params[:publication])
-
+        
     # @project = Project.find(params[:project_id])
-    @publication.projects << @project
-    
+    @publication.projects << @project unless @project.nil?
+        
     if @publication.save 
       flash[:notice] = "Successfully created publication."
       redirect_to :action => :show, :id => @publication, :project_id => @project.id
@@ -226,12 +229,40 @@
     render :layout => false
   end
 
-  def sort_authors
-    params[:authors].each_with_index do |id, index|
-      Author.update_all(['order=?', index+1], ['id=?', id])
+  def sort_author_order
+    params[:authorships].each_with_index do |id, index|
+      Authorship.update_all(['auth_order=?', index+1], ['id=?', id])
     end
     render :nothing => true
   end
+  
+  def remove_from_project_list
+    pub = Publication.find(params[:id])
+    proj = Project.find(params[:project_id])
+
+    if pub.projects.length > 1
+      if pub.projects.exists? proj
+        pub.projects.delete proj if request.post?
+      end
+    else
+      logger.error { "Cannot remove project from publication list" }      
+    end
+    
+    respond_to do |format|
+      format.js { render(:update) {|page| page.replace_html "list_projects", :partial => 'list_projects', :id  => pub} } 
+    end
+    
+    
+  end
+  
+  def destroy
+    find_project_by_project_id
+    
+    @publication.destroy
+        
+    flash[:notice] = "Successfully deleted Publication."
+    redirect_to :controller => :publications, :action => 'index', :project_id => @project
+  end
 
   def identify_author
     
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -10,11 +10,17 @@
   end
   
   def identify_author(author)
-    if author.class == User      
+    if author.class == User
       author_info = {
         :name_on_paper => author.name,
-        :user_id => author.id
+        :email => author.mail,
+        :user_id => author.id, 
+        :institution  => ""
       }
+      
+      unless author.ssamr_user_detail.nil?
+        author_info[:institution] = author.ssamr_user_detail.institution_name
+      end
     
     else 
       if author.class == Author    
@@ -64,18 +70,12 @@
   
   def render_projects_list(publication)
     s = ""
-    projs = []
     
     publication.projects.each do |proj|
-      projs << link_to_project(proj)
+      s << link_to_project(proj) + link_to_remote(l(:button_delete), { :url => { :controller => 'publications', :action => 'remove_from_project_list', :id => publication, :project_id => proj }, :method => :post }, :class => 'icon icon-del') + "<br />"
     end
     
-    if projs.size < 3
-      s << '<nobr>' << projs.join(', ') << '</nobr>'
-    else
-      s << projs.join(', ')
-    end
-    s
+    s  
   end
   
   def show_bibtex_fields(bibtex_entry)
--- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -1,4 +1,6 @@
 class Authorship < ActiveRecord::Base
+  unloadable 
+  
   belongs_to :author
   belongs_to :publication
   
@@ -11,17 +13,22 @@
   end 
   
   def user_id=(uid)  
-    unless uid.blank?
+    if uid.blank?
+      author = Author.new :name => self.name_on_paper
+      author.save!
+      self.author_id = author.id
+    else
       user = User.find(uid)                         
+      
       if user.author.nil?      
         # TODO: should reflect the name_on_paper parameter
-        author = Author.new :name => user.name
+        author = Author.new :name => self.name_on_paper
         author.save!
         user.author = author
         user.save!
-     end
-           
-    self.author_id = user.author.id
+      else
+        self.author_id = user.author.id        
+      end
     end    
   end
 end
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -16,4 +16,22 @@
   
   has_and_belongs_to_many :projects, :uniq => true
   
+  after_save :set_initial_author_order
+  
+  def set_initial_author_order
+    authorships = self.authorships
+    
+    logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
+    
+    authorships.each_with_index do |authorship, index|
+      if authorship.auth_order.nil?
+         authorship.auth_order = index
+         authorship.save!
+      end
+    end    
+  end
+  
+  
+  
+  
 end
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb	Mon Aug 08 11:52:12 2011 +0100
@@ -1,1 +1,3 @@
-<%= render_projects_list(@publication) %>
\ No newline at end of file
+<% publication = Publication.find(params[:id]) %>
+
+<%= render_projects_list(publication) %>
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Mon Aug 08 11:52:12 2011 +0100
@@ -1,3 +1,5 @@
+<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
+
 <h2><%=l(:label_publication_show)%></h2>
 
 <div class="splitcontentleft">
@@ -6,14 +8,15 @@
 
 <h4><%= l(:authors) %></h4>
 <ul id="authorships">
-  <% for authorship in @publication.authorships %>
+  <% for authorship in @publication.authorships.find(:all, :order => :auth_order) %>
     <% content_tag_for :li, authorship do %>
+      <span class="handle">[drag to reorder]</span>
       <%= h authorship.name_on_paper %> <br />
       <%= h authorship.institution %> <br />
     <% end %>
   <% end %>
 </ul>
-<%= sortable_element("authorships", :url => { :controller => :publications, :action => :sort_authors }) %>
+<%= sortable_element("authorships", :url => { :controller => :publications, :action => :sort_author_order }, :handle => "handle") %>
 
 <br />
 
@@ -23,7 +26,8 @@
 
 <p>
   <%= link_to l(:label_publication_edit), { :controller => "publications", :action => "edit", :id => @publication, :project_id => @project } %> |
-  <%= link_to "Destroy", @publication, :confirm => 'Are you sure?', :method => :delete %> |
+  <%= link_to "Delete", {:controller => 'publications', :action => 'destroy', :id => @publication, :project_id => @project },
+                                                     :confirm => l(:text_are_you_sure), :method => :delete, :title => l(:button_delete) %> |
   <%= link_to "View All", publications_path %>
 </p>
 </div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css	Mon Aug 08 11:52:12 2011 +0100
@@ -0,0 +1,5 @@
+li .handle {
+  font-size: 12px;
+  cursor: move;
+  color: #777;
+}
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/config/routes.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/routes.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -1,3 +1,3 @@
 ActionController::Routing::Routes.draw do |map|
-  map.resources :publications, :collection => { :sort_authors => :post }
+  map.resources :publications, :collection => { :sort_author_order => :post }
 end
\ No newline at end of file
--- a/vendor/plugins/redmine_bibliography/db/migrate/003_create_authorships.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/db/migrate/003_create_authorships.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -4,7 +4,7 @@
       t.column :author_id, :integer
       t.column :publication_id, :integer
       t.column :name_on_paper, :string
-      t.column :order, :integer
+      t.column :auth_order, :integer
       t.column :institution, :string
       t.column :email, :string
     end
--- a/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Mon Aug 01 19:05:24 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb	Mon Aug 08 11:52:12 2011 +0100
@@ -25,23 +25,21 @@
           :user_id => self.id                    
         }
         
-        unless self.author.nil?
-          logger.error { "We've got author" }          
+        if self.author.nil?
+          logger.error { "NO AUTHOR HERE" }
+          info[:name_on_paper] = self.name
+          info[:email] = self.mail
+          if not self.ssamr_user_detail.nil?
+            info[:institution]  = self.ssamr_user_detail.institution_name
+          end
+        else
+          logger.error { "-----> We've got an author associated with the user." }          
           info[:name_on_paper] = self.author.name            
 
           if self.author.authorships.length > 0
             info[:email] = self.author.authorships.first.email
             info[:institution] = self.author.authorships.first.institution
           end
-
-        else
-          logger.error { "No author" }
-          
-          info[:name_on_paper] = "No Name"
-          info[:email] = self.mail
-          if not self.ssamr_user_detail.nil?
-            info[:institution]  = self.ssamr_user_detail.institution_name
-          end
         end
         
         return info