Mercurial > hg > soundsoftware-site
changeset 1430:04cc33a44d4c live
Merge from branch "cannam"
author | Chris Cannam |
---|---|
date | Wed, 09 Oct 2013 17:41:45 +0100 |
parents | ac411172d897 (current diff) 5b52161fb034 (diff) |
children | 303b9be118d4 2b7911132501 |
files | |
diffstat | 30 files changed, 605 insertions(+), 363 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/controllers/publications_controller.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Oct 09 17:41:45 2013 +0100 @@ -15,16 +15,11 @@ # we'll always want a new publication to have its bibtex entry @publication.build_bibtex_entry - # and at least one 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 @project = Project.find(params[:project_id]) - @author_options = [] - @publication = Publication.new(params[:publication]) @publication.projects << @project unless @project.nil? @@ -91,14 +86,11 @@ @publication = Publication.find(params[:id]) @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type - @author_options = [] - @bibtype_fields = BibtexEntryType.fields(@selected_bibtex_entry_type_id) end def update @publication = Publication.find(params[:id]) - @author_options = [] if @publication.update_attributes(params[:publication]) flash[:notice] = "Successfully updated Publication." @@ -176,9 +168,6 @@ @publication.bibtex_entry = @bentry @publication.save - # what is this for??? - # @created_publications << @publication.id - # need to save all authors # and establish the author-publication association # via the authorships table @@ -199,17 +188,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]) @@ -225,60 +203,28 @@ @object_name = "publications[authorships_attributes][#{object_id}][search_results]" # cc 20110909 -- revert to like instead of like_unique -- see #289 - authorships_list = Authorship.like(params[:term]).find(:all, :limit => 100) + authorships_list = Authorship.like(params[:term]).group('author_id').find(:all, :limit => 100) + + authors_list = authorships_list.collect do |x| x.author end + users_list = User.active.like(params[:term]).find(:all, :limit => 100) - logger.debug "Query for \"#{params[:term]}\" returned \"#{authorships_list.size}\" authorships and \"#{users_list.size}\" users" + logger.debug "Query for \"#{params[:term]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users" - @results = users_list + # will check if any of the members of the users list + # doesn't belong to the authors list - # TODO: can be optimized… - authorships_list.each do |authorship| - flag = true + @results = authors_list - 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}" } - flag = false - break - end - end - - @results << authorship if flag + users_list.each do |user| + @results << user unless authors_list.include?(user.author) end + logger.debug { "Autocomplete_for_author results --> #{@results}" } + render :layout => false end - def get_user_info - object_id = params[:object_id] - value = params[:value] - classname = Kernel.const_get(value.split('_')[0]) - - item = classname.find(value.split('_')[1]) - - name_field = "publication_authorships_attributes_#{object_id}_name_on_paper".to_sym - email_field = "publication_authorships_attributes_#{object_id}_email".to_sym - institution_field = "publication_authorships_attributes_#{object_id}_institution".to_sym - - yes_radio = "publication_authorships_attributes_#{object_id}_identify_author_yes".to_sym - - respond_to do |format| - format.js { - render(:update) {|page| - page[name_field].value = item.name - page[email_field].value = item.mail - page[institution_field].value = item.institution - - page[yes_radio].checked = true - page[name_field].readOnly = true - page[email_field].readOnly = true - page[institution_field].readOnly = true - } - } - end - end - def sort_author_order params[:authorships].each_with_index do |id, index| Authorship.update_all(['auth_order=?', index+1], ['id=?', id]) @@ -303,7 +249,6 @@ end end - def remove_project @project = Project.find(params[:project_id]) proj = Project.find(params[:remove_project_id]) @@ -324,7 +269,8 @@ end def destroy - find_project_by_project_id + find_project_by_project_id unless params[:project_id].nil? + @publication = Publication.find(params[:id]) @publication.destroy
--- a/plugins/redmine_bibliography/app/helpers/publications_helper.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Oct 09 17:41:45 2013 +0100 @@ -21,9 +21,6 @@ s.html_safe end - - - def link_to_remove_fields(name, f) f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this)", :class => 'icon icon-del') end @@ -31,8 +28,10 @@ def link_to_add_author_fields(name, f, association, action) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder| + # renders _authorship_fields.html.erb render(association.to_s.singularize + "_fields", :f => builder) end + link_to_function(name, "add_author_fields(this, '#{association}', '#{escape_javascript(fields)}', '#{action}')", { :class => 'icon icon-add', :id => "add_another_author" }) end @@ -59,32 +58,6 @@ str.to_sym end - ####### - ### DELETE ME - - def choose_author_link(object_name, items) - # called by autocomplete_for_author (publications' action/view) - # creates the select list based on the results array - # results is an array with both Users and Authorships objects - - @author_options = [] - @results.each do |result| - email_bit = result.mail.partition('@')[2] - if email_bit != "" - email_bit = "(@#{email_bit})" - end - @author_options << ["#{result.name} #{email_bit}", "#{result.class.to_s}_#{result.id.to_s}"] - end - - if @results.size > 0 - s = select_tag( form_tag_name(object_name, :author_search_results), options_for_select(@author_options), { :id => form_tag_id(object_name, :author_search_results), :size => 3} ) - else - s = "<em>No Authors found that match your search… sorry!</em>" - end - end - - - def render_authorships_list(publication) s = '<p>' @@ -133,7 +106,6 @@ end end - def show_bibtex_fields(bibtex_entry) s = "" bibtex_entry.attributes.keys.sort.each do |key| @@ -152,3 +124,23 @@ end end + +def render_authorship_link(link_class, link_id) + + # Renders a link for an author used when adding authors for a publication + # link_class can be either User or Author + # link_id will be the id of the Author/User we wish to link + + s= "" + + if link_class == "Author" + url = {:controller => 'authors', :action => 'show', :id => link_id} + s << link_to(h(Author.find(link_id).name), url) + else + url = {:controller => 'users', :action => 'show', :id => link_id} + s << link_to(h(User.find(link_id).name), url) + end + + s.html_safe +end +
--- a/plugins/redmine_bibliography/app/models/author.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/author.rb Wed Oct 09 17:41:45 2013 +0100 @@ -18,4 +18,29 @@ } } + def institution + if self.authorships.first.nil? + "" + else + self.authorships.first.institution + end + end + + def mail + if self.authorships.first.nil? + "" + else + self.authorships.first.mail + end + end + + # todo: need to fix the name getter + def name + if self.authorships.first.nil? + "" + else + self.authorships.first.name + end + end + end
--- a/plugins/redmine_bibliography/app/models/authorship.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Wed Oct 09 17:41:45 2013 +0100 @@ -9,9 +9,13 @@ validates_presence_of :name_on_paper - attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author + attr_writer :search_author_id , :search_author_class + attr_writer :search_author_tie - before_create :associate_author_user + ### attr_accessor :search_results, :identify_author + ## attr_writer :search_author_class + + before_save :set_author before_update :delete_publication_cache # tod: review scope of ordering @@ -34,6 +38,40 @@ } } + def search_author_class + # Authorship must always have an Author + # unless it hasn't been saved yet + # using default setter (attr_writer) + + if self.author.nil? + aclass = "" + else + aclass = "Author" + end + + @search_author_class || aclass + end + + def search_author_id + if self.author.nil? + authid = "" + else + authid = author_id + end + + @search_author_id || authid + end + + def search_author_tie + if self.author.nil? + auth_tie = false + else + auth_tie = true + end + + @search_author_tie || auth_tie + end + def name return self.name_on_paper end @@ -54,35 +92,47 @@ Rails.cache.delete "publication-#{publication.id}-bibtex" end - def associate_author_user - case self.search_author_class - when "" - logger.debug { "Unknown Author to be added..." } - when "User" + private + + def set_author + # do we want to associate the authorship + # with an existing author/user? + if @search_author_tie + # if an author, simply associates with it + # if an user, checks if it has already an author associated with it + # if so, associates with that author + # otherwise, creates a new author + + case @search_author_class + when "" + author = Author.new + author.save + + when "User" + user = User.find(@search_author_id) + + if user.author.nil? + # User w/o author: + # create new author and update user + author = Author.new + author.save + user.author = author + user.save + else + author = user.author + end + + when "Author" + author = Author.find(@search_author_id) + end + + # if we don't want to associate with an existing author/user + else + # todo: should we delete any previously existing relationship? author = Author.new author.save - self.author_id = author.id + end - 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 - # 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 - end - end + self.author = author end end
--- a/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Wed Oct 09 17:41:45 2013 +0100 @@ -1,7 +1,7 @@ class BibtexEntryType < ActiveRecord::Base unloadable - @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], + @@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' ], @@ -25,6 +25,6 @@ end def self.fields (type) - @@fields[ self.find(type).name ] + @@fields[ self.find(type).name ] end end
--- a/plugins/redmine_bibliography/app/models/publication.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/publication.rb Wed Oct 09 17:41:45 2013 +0100 @@ -53,14 +53,14 @@ def notify_authors_publication_added(project) self.authors.each do |author| Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." } - Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil? + Mailer.publication_added(author.user, self, project).deliver unless author.user.nil? end end def notify_authors_publication_updated(project) self.authors.each do |author| Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." } - Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil? + Mailer.publication_updated(author.user, self, project).deliver unless author.user.nil? end end
--- a/plugins/redmine_bibliography/app/views/activities/index.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/activities/index.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -6,7 +6,7 @@ l(:label_institution_activity, h(@institution_name)) end else - l(:label_user_activity, link_to_user(@author)) + l(:label_user_activity, link_to_user(@author)).html_safe end %></h2> <p class="subtitle"><%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %></p>
--- a/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,49 +1,26 @@ -<%- content_for :header_tags do -%> - <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' -%> - <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%> - <%= javascript_tag "$('.author_save_btn').live('click', disable_fields);" -%> - <%= javascript_tag "$('.author_edit_btn').live('click', enable_fields);" -%> -<%- end -%> +<div id="authors" class="fields"> + <div class="author_edit" id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> -<div id="authors" class="fields"> - <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> > - <p> - <%= f.text_field :search_name, :size => 25, :class => "author_search" %> + <p><%= f.label :name_on_paper %><%= f.text_field :name_on_paper, :class => "author_name_on_paper" -%></p> + <p><%= f.label :institution %><%= f.text_field :institution -%></p> + <p><%= f.label :email %><%= f.text_field :email -%></p> + + <p class="author_associated search_author_tie"> + <%= f.check_box :search_author_tie, :label => '' -%> + <span>Not associated with any SoundSoftware site user.</span> </p> - <p style="margin-bottom: -2.5em; padding-bottom; 0"><label><%= l(:identify_author_question) %></label></p> - - <p class="author_identify"> - <label class='inline'><%= radio_button_tag(:identify_author, "yes", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_yes )) %> <%= l(:identify_author_yes) %> </label><br /> - - <label class='inline'><%= radio_button_tag(:identify_author, "correct", false, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_corrections )) %> <%= l(:identify_author_correct) %> </label><br /> - - <label class='inline'><%= radio_button_tag(:identify_author, "no", true, :name => form_tag_name(f.object_name,:identify_author ), :id => form_tag_id( f.object_name, :identify_author_no )) %> <%= l(:identify_author_no) %> </label><br /> - </p> - </div> - - <div class='author_edit' id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> - <p><%= f.text_field :name_on_paper, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_name_on_paper") %></p> - - <p><%= f.text_field :institution, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_institution") %></p> - <p><%= f.text_field :email, {:class => ("readonly" unless params[:action] == "new") } %></p> - <p class='description' style=<%= "display:none;" unless params[:action] == "new" %>><%= h l("text_author_email") %></p> - - <%= hidden_field_tag(:search_author_class, '', :name => form_tag_name(f.object_name,:search_author_class ), :id => form_tag_id( f.object_name, :search_author_class )) -%> - - <%= hidden_field_tag(:search_author_id, '', :name => form_tag_name(f.object_name,:search_author_id ), :id => form_tag_id( f.object_name, :search_author_id )) -%> + <%= f.hidden_field :search_author_class -%> + <%= f.hidden_field :search_author_id -%> </div> <div> <p> <%= button_to_function l(:label_save_author), '', :id => form_tag_id(f.object_name, :edit_save_button), :class => 'author_save_btn' -%> - <%= button_to_function l(:label_edit_author), '', :id => form_tag_id(f.object_name, :edit_button), :class => 'author_edit_btn' -%> + <%= button_to_function l(:label_edit_author), '', :id => form_tag_id(f.object_name, :edit_button), :class => 'author_edit_btn', :style => "display:none;" -%> <%= link_to_remove_fields l("remove_author"), f %> </p> </div> -</div> - +</div> \ No newline at end of file
--- a/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,5 +1,5 @@ <p> - <label for="bibtex_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label> + <label for="publication_bibtex_entry_attributes_entry_type"><%=l("field_entry_type")%> <span class="required">*</span></label> <%= f.collection_select :entry_type, BibtexEntryType.find(:all).reject { |x| x.redundant? }, :id, @@ -8,71 +8,71 @@ </p> <p class="bibtex hol"> - <%= f.text_field :year, :size => 4 %> + <%= f.label :year %><%= f.text_field :year, :size => 5 -%> </p> <p class="bibtex hol"> - <%= f.text_field :month, :size => 4%> + <%= f.label :month %><%= f.text_field :month, :size => 5 -%> </p> <p class="bibtex hol"> - <%= f.text_field :chapter, :size => 15%> + <%= f.label :chapter %><%= f.text_field :chapter, :size => 5 -%> </p> <p class="bibtex hol"> - <%= f.text_field :editor, :size => 33 %> + <%= f.label :editor %><%= f.text_field :editor -%> </p> <p class="bibtex hol"> - <%= f.text_field :booktitle, :size => 33 %> + <%= f.label :booktitle %><%= f.text_field :booktitle -%> </p> <p class="bibtex hol"> - <%= f.text_field :publisher,:size => 33 %> + <%= f.label :publisher %><%= f.text_field :publisher -%> </p> <p class="bibtex hol"> - <%= f.text_field :pages, :size => 12 %> + <%= f.label :pages %><%= f.text_field :pages, :size => 5 -%> </p> <p class="bibtex hol"> - <%= f.text_field :address %> + <%= f.label :address %><%= f.text_field :address -%> </p> <p class="bibtex hol"> - <%= f.text_field :annote %> + <%= f.label :annote %><%= f.text_field :annote -%> </p> <p class="bibtex hol"> - <%= f.text_field :crossref %> + <%= f.label :crossref %><%= f.text_field :crossref -%> </p> <p class="bibtex hol"> - <%= f.text_field :edition %> + <%= f.label :edition %><%= f.text_field :edition -%> </p> <p class="bibtex hol"> - <%= f.text_field :eprint %> + <%= f.label :eprint %><%= f.text_field :eprint -%> </p> <p class="bibtex hol"> - <%= f.text_field :howpublished %> + <%= f.label :howpublished %><%= f.text_field :howpublished -%> </p> <p class="bibtex hol"> - <%= f.text_field :journal %> + <%= f.label :journal %><%= f.text_field :journal -%> </p> <p class="bibtex hol"> - <%= f.text_field :key %> + <%= f.label :key %><%= f.text_field :key -%> </p> <p class="bibtex hol"> - <%= f.text_field :note %> + <%= f.label :note %><%= f.text_field :note -%> </p> <p class="bibtex hol"> - <%= f.text_field :number %> + <%= f.label :number %><%= f.text_field :number, :size => 5 -%> </p> <p class="bibtex hol"> - <%= f.text_field :organization %> + <%= f.label :organization %><%= f.text_field :organization %> </p> <p class="bibtex hol"> - <%= f.text_field :school %> + <%= f.label :school %><%= f.text_field :school %> </p> <p class="bibtex hol"> - <%= f.text_field :series %> + <%= f.label :series %><%= f.text_field :series %> </p> <p class="bibtex hol"> - <%= f.text_field :type %> + <%= f.label :type %><%= f.text_field :type %> </p> <p class="bibtex hol"> - <%= f.text_field :url %> + <%= f.label :url %><%= f.text_field :url %> </p> <p class="bibtex hol"> - <%= f.text_field :volume %> + <%= f.label :volume %><%= f.text_field :volume %> </p> \ No newline at end of file
--- a/plugins/redmine_bibliography/app/views/publications/_form.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_form.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,20 +1,4 @@ -<%= error_messages_for 'publication' %> - <%= javascript_tag " - $('#publication_bibtex_entry_attributes_entry_type').live('change', function() { - $this = $(this); - $.ajax({ - type: 'get', - url: '#{url_for(:controller => :publications, :action => :show_bibtex_fields)}', - data: { - value: $this.val() - }, - dataType: 'script' - }); - return false; - });" - -%> - -<h3><%= f.text_field :title, :required => true, :size => 70 %></h3> +<h3><%= f.label :title %> <span class="required">*</span> <%= f.text_field :title, :required => true, :size => 70 %></h3> <div class="splitcontentleft"> <h3><%= l(:label_publication_other_details) %></h3> @@ -24,12 +8,12 @@ <%- end -%> <p> - <%= f.text_field :external_url, :size => 70 %> + <%= f.label :external_url %><%= f.text_field :external_url -%> <br /> - <em><%= l(:text_external_url) %></em> + <em><%= l(:text_external_url) -%></em> </p> <p> - <%= f.text_field :doi, :size => 70 %> + <%= f.label :doi %><%= f.text_field :doi -%> <br /> <em><%= l(:text_doi) %></em> </p>
--- a/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,10 +1,12 @@ -<%= raw @results.map {|result| { - 'label' => "#{result.name} <em>#{result.mail.partition('@')[2]}</em>", +<%= raw @results.map { |result| + { + 'label' => result.name, 'value' => result.name, 'search_author_class' => result.class.name, 'search_author_id' => result.id, 'name' => result.name, 'institution' => result.institution, 'email' => result.mail, + 'authorship_link' => " Keep associated with #{render_authorship_link(result.class.name, result.id)}" } }.to_json %> \ No newline at end of file
--- a/plugins/redmine_bibliography/app/views/publications/edit.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/edit.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,19 +1,39 @@ <% content_for :header_tags do %> - <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> - <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> - <%= javascript_tag "$(document).ready(function() { $('#publication_bibtex_entry_attributes_entry_type').trigger('change'); });" %> + <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' -%> + <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%> + <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' -%> + + <%= javascript_include_tag 'edit_publication', :plugin => 'redmine_bibliography' -%> + + <%= javascript_tag "$('#publication_bibtex_entry_attributes_entry_type').live('change', function() { + $this = $(this); + $.ajax({ + type: 'get', + url: '#{url_for(:controller => :publications, :action => :show_bibtex_fields)}', + data: { + value: $this.val() + }, + dataType: 'script' + }); return false; });" -%> + + <%= javascript_tag "authorship_autocomplete('#{url_for :controller => :publications, :action => :autocomplete_for_author}');" -%> + <% end %> +<%= error_messages_for 'publication' %> + <h2><%=l(:label_publication_show)%></h2> -<%= labelled_form_for @publication, :url => { :project_id => @project, :action => :update } do |f| -%> - <%= render :partial => 'form', :locals => { :f => f } %> +<%= form_for @publication, :url => { :project_id => @project, :action => :update } do |f| -%> - <div style="clear:both"></div> - <%= f.submit %> + <%= render :partial => 'form', :locals => { :f => f } %> + + <div style="clear:both"></div> + <%= f.submit %> <% end %> + <p> - <%= link_to l(:label_publication_show), { :controller => "publications", :action => "show", :id => @publication, :project_id => @project_id } %> | - <%= link_to l(:label_publication_index), { :controller => "publications", :action => "index", :project_id => @project } %> + <%= link_to l(:label_publication_show), { :controller => "publications", :action => "show", :id => @publication, :project_id => @project_id } %> | + <%= link_to l(:label_publication_index), { :controller => "publications", :action => "index", :project_id => @project } %> </p>
--- a/plugins/redmine_bibliography/app/views/publications/new.html.erb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/new.html.erb Wed Oct 09 17:41:45 2013 +0100 @@ -1,12 +1,35 @@ <% content_for :header_tags do %> <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> <%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %> + <%= javascript_include_tag 'bibliography', :plugin => 'redmine_bibliography' -%> + <%= javascript_include_tag 'new_publication', :plugin => 'redmine_bibliography' -%> + + <%= javascript_tag " + $('#publication_bibtex_entry_attributes_entry_type').live('change', function() { + $this = $(this); + $.ajax({ + type: 'get', + url: '#{url_for(:controller => :publications, :action => :show_bibtex_fields)}', + data: { + value: $this.val() + }, + dataType: 'script' + }); + return false; + });"-%> + + <%= javascript_tag "authorship_autocomplete('#{url_for :controller => :publications, :action => :autocomplete_for_author}');" -%> + <% end %> +<%= error_messages_for 'publication' %> + <h2><%=l(:label_publication_new)%></h2> -<%= labelled_form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> +<%= form_for @publication, :url => { :project_id => @project, :action => :create } do |f| -%> + <%= render :partial => 'form', :locals => { :f => f } %> + <div style="clear:both"></div> <%= f.submit %> <% end %>
--- a/plugins/redmine_bibliography/assets/javascripts/authors.js Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/authors.js Wed Oct 09 17:41:45 2013 +0100 @@ -3,10 +3,6 @@ var regexp = new RegExp("new_" + association, "g"); $(link).before(content.replace(regexp, new_id)); - - if(action != "new"){ - toggle_save_author(new_id, $(link)); - } } function remove_fields(link) { @@ -14,60 +10,36 @@ $(link).closest(".fields").hide(); } -$(".author_search").live('keyup.autocomplete', function(){ - $this = $(this); +function authorship_autocomplete(url){ + $(".author_name_on_paper").live('keyup.autocomplete', function(){ + $this = $(this); - $this.autocomplete({ - source: '/publications/autocomplete_for_author', - minLength: 2, - focus: function(event, ui) { - $this.closest('div').next().find("input[id$='name_on_paper']").val(ui.item.name); - $this.closest('div').next().find("input[id$='institution']").val(ui.item.institution); - $this.closest('div').next().find("input[id$='email']").val(ui.item.email); - $this.closest('div').next().find("input[id$='search_author_class']").val(ui.item.search_author_class); - $this.closest('div').next().find("input[id$='search_author_id']").val(ui.item.search_author_id); + $this.autocomplete({ + source: url, + minLength: 2, + focus: function(event, ui) { + $this.val(ui.item.label); + return false; + }, + select: function(event, ui){ + $this.closest('div').find("input[id$='institution']").val(ui.item.institution); + $this.closest('div').find("input[id$='email']").val(ui.item.email); - return false; - }, - select: function(event, ui){ - $this.closest('div').next().find("input[id$='name_on_paper']").val(ui.item.name); - $this.closest('div').next().find("input[id$='institution']").val(ui.item.institution); - $this.closest('div').next().find("input[id$='email']").val(ui.item.email); - $this.closest('div').next().find("input[id$='search_author_class']").val(ui.item.search_author_class); - $this.closest('div').next().find("input[id$='search_author_id']").val(ui.item.search_author_id); - } - }) - .data( "autocomplete" )._renderItem = function( ul, item ) { - return $( "<li></li>" ) - .data( "item.autocomplete", item ) - .append( "<a>" + item.label + "</a>" ) - .appendTo( ul ); - }; - }); + $this.closest('div').find("input[id$='search_author_class']").val(ui.item. search_author_class); + $this.closest('div').find("input[id$='search_author_id']").val(ui.item. search_author_id); + $this.closest('div').find("input[id$='search_author_tie']").attr('checked', ' checked'); + $this.closest('div').find("input[id$='search_author_tie']").next('span').replaceWith("<span>" + ui.item.authorship_link + "</span>"); -$("input[id$='identify_author_yes']").live("click", function() { - console.log("aaaa"); -}); - -$("input[id$='identify_author_no']").live("click", function() { - $this.closest('div').next().find("input[id$='name_on_paper']").val(''); - $this.closest('div').next().find("input[id$='institution']").val(''); - $this.closest('div').next().find("input[id$='email']").val(''); - $this.closest('div').next().find("input[id$='search_author_class']").val(''); -}); - -function toggle_div(div_id){ - $("#" + div_id).toggle(0.3); + // triggers the save button + $this.closest('div').next('div').find('.author_save_btn').click(); + } + }) + .data( "autocomplete" )._renderItem = function( ul, item ) { + return $( "<li>" ) + .data("item.autocomplete", item ) + .append( "<a>" + item.label + "<br><em>" + item.email + "</em><br>" + item. institution + "</a>" ) + .appendTo(ul); + }; + }); } - -function toggle_save_author(form_object_id, $this){ - $('publication_authorships_attributes_' + form_object_id + '_edit_author_info').select('input').each(function(s) { - toggle_input_field(s, $this); - }); - $('publication_authorships_attributes_' + form_object_id + '_edit_author_info').select('p.description').each(function(s) { - s.toggle(); - }); - toggle_edit_save_button(form_object_id); - toggle_div("publication_authorships_attributes_" + form_object_id +"_search_author"); -} \ No newline at end of file
--- a/plugins/redmine_bibliography/assets/javascripts/bibliography.js Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/bibliography.js Wed Oct 09 17:41:45 2013 +0100 @@ -2,11 +2,15 @@ function disable_fields(){ $this = $(this); + $author_info = $this.closest('div').prev(); - $author_info.children('.description').toggle(); +// $author_info.children('.description').toggle(); $author_info.find('p :input').attr("readonly", true); $author_info.find('p :input').addClass('readonly'); + // Always hides on save + $this.closest('div').prev().find('p.search_author_tie').hide(); + $this.siblings('.author_edit_btn').show(); $this.hide(); @@ -15,13 +19,18 @@ function enable_fields(){ $this = $(this); + $author_info = $this.closest('div').prev(); - $author_info.children('.description').toggle(); +// $author_info.children('.description').toggle(); $author_info.find('p :input').attr("readonly", false); $author_info.find('p :input').removeClass('readonly'); + // Always shows on edit + $this.closest('div').prev().find('p.search_author_tie').show(); + $this.siblings('.author_save_btn').show(); $this.hide(); return false; } +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/assets/javascripts/edit_publication.js Wed Oct 09 17:41:45 2013 +0100 @@ -0,0 +1,13 @@ +// edit_publication.js + +$(document).ready(function(){ + // shows the correct bibtex fields + $('#publication_bibtex_entry_attributes_entry_type').trigger('change'); + + // adds the events to the edit/save authorship button + $('.author_save_btn').live('click', disable_fields); + $('.author_edit_btn').live('click', enable_fields); + + // clicks all authorships + $('.author_save_btn').trigger('click'); +}); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/assets/javascripts/new_publication.js Wed Oct 09 17:41:45 2013 +0100 @@ -0,0 +1,9 @@ +// edit_publication.js + +$(document).ready(function(){ + // adds the events to the edit/save authorship button + $('.author_save_btn').live('click', disable_fields); + $('.author_edit_btn').live('click', enable_fields); + + +}); \ No newline at end of file
--- a/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Wed Oct 09 17:41:45 2013 +0100 @@ -20,19 +20,14 @@ } .tabular .author_edit .description { - padding-top: 0; font-style: italic; + font-size: small; } .publication_project { margin-right: 18px; } -#authors select { - min-width: 150px; -} - - div#bibliography dd { margin-bottom: 1em; font-size: 0.9em; } div#bibliography dd .authors { font-style: italic; } @@ -71,7 +66,11 @@ background-image: url(../../../images/loading.gif); } -.author_edit_btn { - display:none; +.search_author_tie { + display: none; + float: left; } +.author_edit_btn { + display: none; +}
--- a/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb Wed Oct 09 17:41:45 2013 +0100 @@ -4,7 +4,7 @@ module MailerPatch def self.included(base) # :nodoc: - # Builds a tmail object used to email the specified user that a publication was created and the user is + # Builds a tmail object used to email the specified user that a publication was created and the user is # an author of that publication # # Example: @@ -16,16 +16,15 @@ @project = project set_language_if_valid user.language - recipients user.mail - subject l(:mail_subject_publication_added, Setting.app_title) - body :publication_url => url_for( :controller => 'publications', :action => 'show', :id => publication.id ), - :publication_title => publication.title - render_multipart('publication_added', body) + mail :to => user.mail, + :subject => l(:mail_subject_register, Setting.app_title) + @publication_url = url_for( :controller => 'publications', :action => 'show', :id => publication.id ) + @publication_title = publication.title end - - + + end end end
--- a/plugins/redmine_bibliography/test/fixtures/authors.yml Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/fixtures/authors.yml Wed Oct 09 17:41:45 2013 +0100 @@ -1,17 +1,18 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +# authors.yml +--- one: id: 1 - user_id: - name: MyString + user_id: 1 + name: two: id: 2 - user_id: - name: MyString -one: + user_id: + name: +three: id: 3 - user_id: - name: MyString -two: + user_id: + name: +four: id: 4 - user_id: - name: MyString + user_id: + name:
--- a/plugins/redmine_bibliography/test/fixtures/authorships.yml Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/fixtures/authorships.yml Wed Oct 09 17:41:45 2013 +0100 @@ -1,33 +1,42 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +# authorships.yml +--- one: id: 1 author_id: 1 publication_id: 1 name_on_paper: Yih-Farn R. Chen - order: 1 - institution: - email: MyString + auth_order: 1 + institution: Imperial College London + email: chen@imperial.ac.uk two: id: 2 author_id: 2 publication_id: 1 name_on_paper: Glenn S. Fowler - order: 2 - institution: + auth_order: 2 + institution: email: MyString three: id: 3 - author_id: 1 + author_id: 3 publication_id: 1 - name_on_paper: Yih-Farn R. Chen - order: 1 - institution: - email: MyString + name_on_paper: Jackie Brown + auth_order: 1 + institution: + email: j.brown@m.com four: id: 4 - author_id: 2 + author_id: 4 publication_id: 1 - name_on_paper: Glenn S. Fowler - order: 2 - institution: - email: MyString + name_on_paper: Captain Boomtime + auth_order: 2 + institution: + email: cpt.boom@time.co.uk +five: + id: 5 + author_id: 1 + publication_id: 2 + name_on_paper: Yih-Farn Chen + auth_order: 1 + institution: "Imperial College, London" + email: yfc@gmail.com
--- a/plugins/redmine_bibliography/test/fixtures/bibtex_entries.yml Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/fixtures/bibtex_entries.yml Wed Oct 09 17:41:45 2013 +0100 @@ -1,4 +1,5 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +# bibtex_entries.yml +--- one: id: 1 entry_type: InProceedings
--- a/plugins/redmine_bibliography/test/fixtures/publications.yml Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/fixtures/publications.yml Wed Oct 09 17:41:45 2013 +0100 @@ -1,9 +1,13 @@ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html one: - id: 1 - title: Test Fixture Title No1 - bibtex_entry_id: 1 + id: 1 + title: Publication Number 1 + reviewed: true + external_url: + doi: two: - id: 2 - title: MyString - bibtex_entry_id: MyString + id: 2 + title: Publication Number 2 + reviewed: false + external_url: + doi:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/test/fixtures/users.yml Wed Oct 09 17:41:45 2013 +0100 @@ -0,0 +1,167 @@ +# users.yml +--- +users_004: + created_on: 2006-07-19 19:34:07 +02:00 + status: 1 + last_login_on: + language: en + # password = foo + salt: 3126f764c3c5ac61cbfc103f25f934cf + hashed_password: 9e4dd7eeb172c12a0691a6d9d3a269f7e9fe671b + updated_on: 2006-07-19 19:34:07 +02:00 + admin: false + mail: rhill@somenet.foo + lastname: Hill + firstname: Robert + id: 4 + auth_source_id: + mail_notification: all + login: rhill + type: User +users_001: + created_on: 2006-07-19 19:12:21 +02:00 + status: 1 + last_login_on: 2006-07-19 22:57:52 +02:00 + language: en + # password = admin + salt: 82090c953c4a0000a7db253b0691a6b4 + hashed_password: b5b6ff9543bf1387374cdfa27a54c96d236a7150 + updated_on: 2006-07-19 22:57:52 +02:00 + admin: true + mail: admin@somenet.foo + lastname: Admin + firstname: redMine + id: 1 + auth_source_id: + mail_notification: all + login: admin + type: User +users_002: + created_on: 2006-07-19 19:32:09 +02:00 + status: 1 + last_login_on: 2006-07-19 22:42:15 +02:00 + language: en + # password = jsmith + salt: 67eb4732624d5a7753dcea7ce0bb7d7d + hashed_password: bfbe06043353a677d0215b26a5800d128d5413bc + updated_on: 2006-07-19 22:42:15 +02:00 + admin: false + mail: jsmith@somenet.foo + lastname: Smith + firstname: John + id: 2 + auth_source_id: + mail_notification: all + login: jsmith + type: User +users_003: + created_on: 2006-07-19 19:33:19 +02:00 + status: 1 + last_login_on: + language: en + # password = foo + salt: 7599f9963ec07b5a3b55b354407120c0 + hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: dlopper@somenet.foo + lastname: Lopper + firstname: Dave + id: 3 + auth_source_id: + mail_notification: all + login: dlopper + type: User +users_005: + id: 5 + created_on: 2006-07-19 19:33:19 +02:00 + # Locked + status: 3 + last_login_on: + language: en + hashed_password: 1 + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: dlopper2@somenet.foo + lastname: Lopper2 + firstname: Dave2 + auth_source_id: + mail_notification: all + login: dlopper2 + type: User +users_006: + id: 6 + created_on: 2006-07-19 19:33:19 +02:00 + status: 0 + last_login_on: + language: '' + hashed_password: 1 + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: '' + lastname: Anonymous + firstname: '' + auth_source_id: + mail_notification: only_my_events + login: '' + type: AnonymousUser +users_007: + id: 7 + created_on: 2006-07-19 19:33:19 +02:00 + status: 1 + last_login_on: + language: '' + hashed_password: 1 + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: someone@foo.bar + lastname: One + firstname: Some + auth_source_id: + mail_notification: only_my_events + login: someone + type: User +users_008: + id: 8 + created_on: 2006-07-19 19:33:19 +02:00 + status: 1 + last_login_on: + language: 'it' + # password = foo + salt: 7599f9963ec07b5a3b55b354407120c0 + hashed_password: 8f659c8d7c072f189374edacfa90d6abbc26d8ed + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: miscuser8@foo.bar + lastname: Misc + firstname: User + auth_source_id: + mail_notification: only_my_events + login: miscuser8 + type: User +users_009: + id: 9 + created_on: 2006-07-19 19:33:19 +02:00 + status: 1 + last_login_on: + language: 'it' + hashed_password: 1 + updated_on: 2006-07-19 19:33:19 +02:00 + admin: false + mail: miscuser9@foo.bar + lastname: Misc + firstname: User + auth_source_id: + mail_notification: only_my_events + login: miscuser9 + type: User +groups_010: + id: 10 + lastname: A Team + type: Group +groups_011: + id: 11 + lastname: B Team + type: Group + +
--- a/plugins/redmine_bibliography/test/functional/authors_controller_test.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/functional/authors_controller_test.rb Wed Oct 09 17:41:45 2013 +0100 @@ -1,8 +1,13 @@ -require File.dirname(__FILE__) + '/../test_helper' +# authors_controller_test.rb + +require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class AuthorsControllerTest < ActionController::TestCase - # Replace this with your real tests. + self.fixture_path = File.dirname(__FILE__) + "/../fixtures/" + fixtures :users, :authors, :authorships + def test_truth assert true end + end
--- a/plugins/redmine_bibliography/test/test_helper.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/test_helper.rb Wed Oct 09 17:41:45 2013 +0100 @@ -1,24 +1,27 @@ +ENV['RAILS_ENV'] ||= 'test' + # Load the normal Rails helper -require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper') -require 'publications_controller' - -# Ensure that we are using the temporary fixture path -Engines::Testing.set_fixture_path +require File.expand_path(File.dirname(__FILE__) + '/../../../test/test_helper') +require File.expand_path(File.dirname(__FILE__) + '/../app/controllers/publications_controller') class BibliographyControllerTest < ActionController::TestCase - fixtures :all + self.fixture_path = File.dirname(__FILE__) + "/fixtures/" + + fixtures :authors def setup + end - def test_publication - + def test_truth + assert true end - - def test_routing - assert_routing( - {:method => :get, :path => '/requirements'}, - :controller => 'requirements', :action => 'index' - ) - end + # def test_routing + # assert_routing( + # {:method => :get, :path => '/requirements'}, + # :controller => 'requirements', :action => 'index' + # ) + # end + +end
--- a/plugins/redmine_bibliography/test/unit/author_test.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/unit/author_test.rb Wed Oct 09 17:41:45 2013 +0100 @@ -1,10 +1,17 @@ -require File.dirname(__FILE__) + '/../test_helper' +# author_test.rb + +require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class AuthorTest < ActiveSupport::TestCase - fixtures :authors + self.fixture_path = File.dirname(__FILE__) + "/../fixtures/" + fixtures :users, :authors, :authorships - # Replace this with your real tests. - def test_truth - assert true - end + def test_relationships + author = Author.find(1) + + assert_equal(author.authorships.first.name_on_paper, "Yih-Farn R. Chen") + assert_equal(author.authorships.count, 2) + + end + end
--- a/plugins/redmine_bibliography/test/unit/authorship_test.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/unit/authorship_test.rb Wed Oct 09 17:41:45 2013 +0100 @@ -5,6 +5,12 @@ # Replace this with your real tests. def test_truth + luis = Author.first + + assert true end + + + end
--- a/plugins/redmine_bibliography/test/unit/publication_test.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_bibliography/test/unit/publication_test.rb Wed Oct 09 17:41:45 2013 +0100 @@ -1,10 +1,31 @@ -require File.dirname(__FILE__) + '/../test_helper' +# publication_test + +require File.expand_path(File.dirname(__FILE__) + '/../test_helper') class PublicationTest < ActiveSupport::TestCase - fixtures :publications + self.fixture_path = File.dirname(__FILE__) + "/../fixtures/" - # Replace this with your real tests. - def test_truth - assert true - end + fixtures :publications, :authorships + + # Replace this with your real tests. + def test_truth + assert true + end + + def test_relationships + # test authorships - publication relationship + publication = Publication.find(1) + + assert 4, publication.authorships.count + end + + def test_new_publication_validations + pub = Publication.create + + assert !pub.valid?, "!pub.valid?" + assert_equal 2, pub.errors.count, "Number of errors" + assert_equal ["can't be blank"], pub.errors[:title] + assert_equal ["Please add at least one author to this publication."], pub.errors[:authorships] + end + end
--- a/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb Tue Sep 17 09:51:20 2013 +0100 +++ b/plugins/redmine_tags/lib/redmine_tags/patches/projects_helper_patch.rb Wed Oct 09 17:41:45 2013 +0100 @@ -116,8 +116,6 @@ s = [] if projects.any? tokens = RedmineProjectFiltering.calculate_tokens(question, custom_fields) - debugger - ancestors = [] original_project = @project