# HG changeset patch # User Chris Cannam # Date 1377774796 -3600 # Node ID c28ce1a71a2238a79b5c406db3f26b5eb0df90ae # Parent 2f4c076ed281c8575ebc7053ed545a6de1f678c4# Parent a2e51c0a78608833203a2691a51995c1596cdb67 Merge from branch "luisf" diff -r 2f4c076ed281 -r c28ce1a71a22 plugins/redmine_bibliography/app/controllers/authorships_controller.rb --- a/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/authorships_controller.rb Thu Aug 29 12:13:16 2013 +0100 @@ -1,10 +1,15 @@ class AuthorshipsController < ApplicationController - - def index - - end - - def update - end + def sort + @authorships = Authorship.find(params['authorship']) + + @authorships.each do |authorship| + + # note: auth_order is usually called position (default column name in the acts_as_list plugin ) + authorship.auth_order = params['authorship'].index(authorship.id.to_s) + 1 + authorship.save + end + + render :nothing => true, :status => 200 + end end diff -r 2f4c076ed281 -r c28ce1a71a22 plugins/redmine_bibliography/app/models/authorship.rb --- a/plugins/redmine_bibliography/app/models/authorship.rb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Thu Aug 29 12:13:16 2013 +0100 @@ -10,9 +10,12 @@ validates_presence_of :name_on_paper attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author - before_save :associate_author_user - acts_as_list + before_create :associate_author_user + before_update :delete_publication_cache + + # tod: review scope of ordering + acts_as_list :column => 'auth_order' # todo: review usage of scope --lf.20130108 scope :like_unique, lambda {|q| @@ -44,32 +47,42 @@ end protected + + def delete_publication_cache + publication = Publication.find(self.publication_id) + Rails.cache.delete "publication-#{publication.id}-ieee" + Rails.cache.delete "publication-#{publication.id}-bibtex" + end + def associate_author_user case self.search_author_class - when "User" - author = Author.new - author.save - self.author_id = author.id + when "" + logger.debug { "Unknown Author to be added..." } + when "User" + author = Author.new + author.save + self.author_id = author.id + + when "Author" + selected = self.search_results + selected_classname = Kernel.const_get(self.search_author_class) + selected_id = self.search_author_id + object = selected_classname.find(selected_id) + + if object.respond_to? :name_on_paper + # Authorship + self.author_id = object.author.id else - selected = self.search_results - selected_classname = Kernel.const_get(self.search_author_class) - selected_id = self.search_author_id - object = selected_classname.find(selected_id) - - if object.respond_to? :name_on_paper - # Authorship + # User + unless object.author.nil? self.author_id = object.author.id else - # User - unless object.author.nil? - self.author_id = object.author.id - else - author = Author.new - object.author = author - object.save - self.author_id = object.author.id - end + author = Author.new + object.author = author + object.save + self.author_id = object.author.id end + end end end end diff -r 2f4c076ed281 -r c28ce1a71a22 plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Aug 29 12:13:01 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/show.html.erb Thu Aug 29 12:13:16 2013 +0100 @@ -1,3 +1,5 @@ +<%= javascript_include_tag 'order_authorships', :plugin => 'redmine_bibliography' %> +