Mercurial > hg > soundsoftware-site
changeset 1394:0f918e37e1d6 biblio_alt_search_auth
Major interface changes; will use virtual attributes to identify search results.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Fri, 27 Sep 2013 18:43:29 +0100 |
parents | 67abd7b08753 |
children | 0e4c6c2f400e |
files | plugins/redmine_bibliography/app/helpers/publications_helper.rb plugins/redmine_bibliography/app/models/authorship.rb plugins/redmine_bibliography/app/models/bibtex_entry_type.rb plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb plugins/redmine_bibliography/assets/javascripts/authors.js plugins/redmine_bibliography/assets/javascripts/bibliography.js plugins/redmine_bibliography/assets/stylesheets/bibliography.css |
diffstat | 8 files changed, 104 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/helpers/publications_helper.rb Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Sep 27 18:43:29 2013 +0100 @@ -106,7 +106,6 @@ end end - def show_bibtex_fields(bibtex_entry) s = "" bibtex_entry.attributes.keys.sort.each do |key| @@ -124,4 +123,3 @@ s end end -
--- a/plugins/redmine_bibliography/app/models/authorship.rb Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/authorship.rb Fri Sep 27 18:43:29 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_create :set_author before_update :delete_publication_cache # tod: review scope of ordering @@ -34,6 +38,35 @@ } } + 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? + return "" + else + return "Author" + end + end + + def search_author_id + if self.author.nil? + return "" + else + return self.author_id + end + end + + def search_author_tie + if self.author.nil? + return false + else + return true + end + + end + def name return self.name_on_paper end @@ -54,35 +87,46 @@ Rails.cache.delete "publication-#{publication.id}-bibtex" end - def associate_author_user + def set_author + # if an author, simply associates with it + # if an user, checks if it has already an author associated with it + # if so, assicoates with that author + # otherwise, creates a new author + + logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" } + + logger.error { "EU #{self.to_yaml}" } + logger.error { "Class: #{search_author_class}" } + logger.error { "ID #{search_author_id}" } + case self.search_author_class when "" - logger.debug { "Unknown Author to be added..." } - when "User" + logger.debug { "Adding new author to the database." } author = Author.new author.save - self.author_id = author.id + + when "User" + # get user id + user = User.find(self.search_author_id) + logger.error { "Found user with this ID: #{user.id}" } + + if user.author.nil? + logger.error { "The user has no author... creating one!" } + + # User w/o author: + # create new author and update user + author = Author.new + author.save + user << author + else + logger.error { "found an author!" } + author = user.author + 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) + author = Author.find(self.search_author_id) + end - 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 Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Fri Sep 27 18:43:29 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/views/publications/_authorship_fields.html.erb Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/_authorship_fields.html.erb Fri Sep 27 18:43:29 2013 +0100 @@ -1,32 +1,17 @@ <div id="authors" class="fields"> - <div id="<%= form_tag_id( f.object_name, :search_author ) %>" > - <p> - <%= f.text_field :search_name, :size => 25, :class => "author_search" %> + <div class="author_edit" id="<%= form_tag_id( f.object_name, :edit_author_info ) %>"> + + <p><%= f.text_field :name_on_paper, :class => "author_name_on_paper" -%></p> + <p><%= f.text_field :institution -%></p> + <p><%= f.text_field :email -%></p> + + <p class="author_associated"> + <%= f.check_box :search_author_tie, :style => "float:left;" -%> + <span class="author_associated_name"></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 -%></p> - <p class="description"><%= h l("text_author_name_on_paper") -%></p> - - <p><%= f.text_field :institution -%></p> - <p class="description"><%= h l("text_author_institution") %></p> - - <p><%= f.text_field :email -%></p> - <p class="description"><%= 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.text_field :search_author_class -%> + <%= f.text_field :search_author_id -%> </div> <div> @@ -38,5 +23,4 @@ <%= 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/autocomplete_for_author.html.erb Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/app/views/publications/autocomplete_for_author.html.erb Fri Sep 27 18:43:29 2013 +0100 @@ -1,10 +1,11 @@ -<%= raw @results.map {|result| { +<%= 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, + 'email' => result.mail } }.to_json %> \ No newline at end of file
--- a/plugins/redmine_bibliography/assets/javascripts/authors.js Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/authors.js Fri Sep 27 18:43:29 2013 +0100 @@ -10,7 +10,7 @@ $(link).closest(".fields").hide(); } -$(".author_search").live('keyup.autocomplete', function(){ +$(".author_name_on_paper").live('keyup.autocomplete', function(){ $this = $(this); $this.autocomplete({ @@ -21,11 +21,17 @@ 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); + $this.closest('div').find("input[id$='institution']").val(ui.item.institution); + $this.closest('div').find("input[id$='email']").val(ui.item.email); + + $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'); + + + + // triggers the save button + $this.closest('div').next('div').find('.author_save_btn').click(); } }) .data( "autocomplete" )._renderItem = function( ul, item ) { @@ -36,15 +42,3 @@ }; }); - -$("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(''); -}); -
--- a/plugins/redmine_bibliography/assets/javascripts/bibliography.js Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/assets/javascripts/bibliography.js Fri Sep 27 18:43:29 2013 +0100 @@ -2,8 +2,9 @@ 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'); @@ -15,8 +16,9 @@ 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'); @@ -25,3 +27,4 @@ return false; } +
--- a/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Thu Sep 26 11:44:57 2013 +0100 +++ b/plugins/redmine_bibliography/assets/stylesheets/bibliography.css Fri Sep 27 18:43:29 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; } @@ -74,4 +69,3 @@ .author_edit_btn { display:none; } -