changeset 664:ad6874c5c651 cannam_integration

Merge from branch "feature_36"
author Chris Cannam
date Fri, 09 Sep 2011 16:35:27 +0100
parents 3c49c63173ef (current diff) 6246ad0f9e98 (diff)
children 45ec06a8eec9 0ec052b8b297
files
diffstat 16 files changed, 163 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -17,7 +17,7 @@
     
     # and at least one author
     # @publication.authorships.build.build_author        
-    @author_options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
+    @author_options = [["#{User.current.name} (@#{User.current.mail.partition('@')[2]})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
 
 
   end
@@ -25,7 +25,7 @@
   def create    
     @project = Project.find(params[:project_id])
 
-    @author_options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
+    @author_options = []
 
     @publication = Publication.new(params[:publication])
     @publication.projects << @project unless @project.nil?
@@ -75,19 +75,16 @@
     
     @edit_view = true;
     
-    @options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
     @publication = Publication.find(params[:id])
     @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type
 
-    # todo: should be removed? 
-    @author_options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]  
+    @author_options = []  
   end
 
   def update    
     @publication = Publication.find(params[:id])        
 
-    # todo: should be removed? 
-    @author_options = [["#{User.current.name} (#{User.current.mail})", "#{User.current.class.to_s}_#{User.current.id.to_s}"]]
+    @author_options = []
 
     logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" }
 
--- a/vendor/plugins/redmine_bibliography/app/helpers/my_helper.rb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/my_helper.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -13,14 +13,10 @@
     projs = []
     
     publication.projects.each do |proj|
-      projs << link_to(proj.name, proj)               
+      projs << link_to(proj.name, proj)
     end
     
-    if projs.size < 3
-        s << '<nobr>' << projs.join(', ') << '</nobr>'
-      else
-        s << projs.join(', ')
-    end  
+    s << projs.join(', ')
     
     s
   end
@@ -33,11 +29,8 @@
       auths << h(auth.name_on_paper)
     end
     
-    if auths.size < 3
-        s << '<nobr>' << auths.join(', ') << '</nobr>'
-      else
-        s << auths.join(', ')
-    end
+    s << auths.join(', ')
+
     s
   end
 
--- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -23,7 +23,11 @@
         
     @author_options = []
     @results.each do |result|
-      @author_options << ["#{result.name} (#{result.mail})", "#{result.class.to_s}_#{result.id.to_s}"]
+      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
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -17,6 +17,29 @@
   has_and_belongs_to_many :projects, :uniq => true
   
   before_save :set_initial_author_order
+  after_save :notify_authors
+
+  # Ensure error message uses proper text instead of
+  # bibtex_entry.entry_type (#268).  There has to be a better way to
+  # do this!
+  def self.human_attribute_name(k)
+    if k == 'bibtex_entry.entry_type'
+      l(:field_entry_type)
+    else
+      super
+    end
+  end
+
+  # Returns the mail adresses of users that should be notified
+  def notify_authors
+        
+    self.authors.each do |author|
+      Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
+      Mailer.deliver_publication_added(author.user, self) unless author.user.nil?
+    end
+    
+  end
+  
   
   def set_initial_author_order
     authorships = self.authorships
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.html.rhtml	Fri Sep 09 16:35:27 2011 +0100
@@ -0,0 +1,3 @@
+<%= link_to(h(@publication.title), @publication_url) %> <br />
+<br />
+<%= textilizable(@publication, :title, :only_path => false) %>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/mailer/publication_added.text.plain.rhtml	Fri Sep 09 16:35:27 2011 +0100
@@ -0,0 +1,3 @@
+<%= @publication.title %>
+<%= @publication_url %>
+
--- a/vendor/plugins/redmine_bibliography/app/views/projects/_bibliography_box.html.erb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/projects/_bibliography_box.html.erb	Fri Sep 09 16:35:27 2011 +0100
@@ -1,8 +1,26 @@
 <% if @project.publications.any? %>
-  <div class="bibliography box">
-	  <h3><%=l(:label_publications_plural)%></h3>	
-	  <p><% @project.publications.each do |publication| %>
-	    <%= link_to publication.title, :controller => 'publications', :action => 'show', :id => publication, :project_id => @project %><br />
-	  <% end %></p>
+<%= stylesheet_link_tag 'bibliography', :plugin => 'redmine_bibliography' %>
+  <div id="bibliography">
+    <div class="box">
+    <h3><%=l(:label_related_publication_plural)%></h3>
+
+   <dl>
+     <% @project.publications.each do |publication| %>
+     <dt>
+       <%= link_to publication.title, :controller => 'publications', :action => 'show', :id => publication, :project_id => @project %>
+     </dt>
+     <dd>
+     <span class="authors">
+       <%= publication.authorships.map { |a| h a.name_on_paper }.join(', ') %>
+     </span>
+     <% if publication.bibtex_entry.year.to_s != "" %>
+     <span class="year">
+       <%= publication.bibtex_entry.year %>
+     </span>
+     <% end %>
+     </dd>
+   <% end -%>
+   </dl>
   </div>
+</div>
 <% end %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml	Fri Sep 09 16:35:27 2011 +0100
@@ -2,7 +2,7 @@
 
 
 <div id="authors" class="fields">
-  <h4><%= l("label_author_1") %></h4>
+<!--  <h4><%= l("label_author_1") %></h4> -->
 
   <div id="<%= form_tag_id( f.object_name, :search_author ) %>" style=<%= "display:none;" unless params[:action] == "new" %> >
       <p>
@@ -44,7 +44,14 @@
   </div>
 
   <p>
-  <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
+
+  <% if params[:action] == 'new' %>
+   <%= button_to_function l(:label_save_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
+  <% else %>
+<%= button_to_function l(:label_edit_author), {}, { :onclick => "toggle_save_author(#{form_object_id(f.object_name)}); return false;", :id => form_tag_id( f.object_name, :edit_save_button )} %>
+
+ <% end %>
+
 
   <%= link_to_remove_fields l("remove_author"), f %>
   </p>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb	Fri Sep 09 16:35:27 2011 +0100
@@ -8,6 +8,13 @@
     <% f.fields_for :bibtex_entry do |builder| -%>
       <%= render :partial => 'bibtex_fields', :locals => { :f => builder}  %>
     <%- end -%>
+
+    <p>
+      <%= f.text_field :external_url, :size => 70 %>
+      <br />
+      <em><%= l(:text_external_url) %></em>
+    </p>
+
   </div>
 </div>
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/index.html.erb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/index.html.erb	Fri Sep 09 16:35:27 2011 +0100
@@ -1,5 +1,7 @@
-<div class="contextual">		
-		<%= link_to l(:label_publication_new), {:controller => 'publications', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %>
+<div class="contextual">
+  <% if User.current.allowed_to?(:add_publication, @project) %>			
+	  <%= link_to l(:label_publication_new), {:controller => 'publications', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %>
+	<% end %>
 </div>
 
   <% if @project %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Fri Sep 09 16:35:27 2011 +0100
@@ -26,13 +26,23 @@
   <%= show_bibtex_fields(@publication.bibtex_entry) %>
 <%- end -%>
 
+
+<% unless @publication.external_url.blank? %>
+  <h4>
+    <%= l(:field_external_url) %>
+  </h4>
+  <p>
+    <%= link_to h(@publication.external_url), @publication.external_url, {:target => "_blank"} %>
+  </p>
+<% end %>
+
 <br / >
   <% if User.current.allowed_to?(:add_publication, @project) %>	
     <%= link_to l(:label_publication_edit), { :controller => "publications", :action => "edit", :id => @publication, :project_id => @project } %> |
     <%= link_to "Delete", {:controller => 'publications', :action => 'destroy', :id => @publication, :project_id => @project },
                                                      :confirm => l(:text_are_you_sure), :method => :delete, :title => l(:button_delete) %> |
   <% end %>
-  <%= link_to l(:view_all_publications), publications_path %>
+  <%= link_to l(:view_all_publications), {:controller => 'publications', :action => 'index', :project_id => @project } %>
 </div>
 
 <% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %>
--- a/vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/assets/stylesheets/bibliography.css	Fri Sep 09 16:35:27 2011 +0100
@@ -27,3 +27,19 @@
 .publication_project {
     margin-right: 18px;
 }
+
+#authors select {
+    min-width: 150px;
+}
+
+div#bibliography dl { margin-left: 2em; }
+div#bibliography .box dl { margin-left: 0; }
+div#bibliography dt { margin-bottom: 0px; padding-left: 20px }
+div#bibliography .box dt { margin-bottom: 0px; padding-left: 10px }
+div#bibliography dd { margin-bottom: 1em; padding-left: 18px; font-size: 0.9em; }
+div#bibliography .box dd { margin-bottom: 0.6em; padding-left: 0; }
+div#bibliography dd .authors { font-style: italic; }
+div#bibliography dd span.authors { color: #808080; }
+div#bibliography dd span.year { padding-left: 0.6em; }
+
+div#bibliography h3 { background: url(../../../images/table_multiple.png) no-repeat 0% 50%; padding-left: 20px; }
--- a/vendor/plugins/redmine_bibliography/config/locales/en.yml	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml	Fri Sep 09 16:35:27 2011 +0100
@@ -24,17 +24,17 @@
   field_authorship_email: "Email Address"
   field_authorship_institution: "Institution"
   
+  field_external_url: "External URL"
   field_publication_title: Title
   field_publication_authors: Authors
-  field_publication_projects: "Associated Projects"
+  field_publication_projects: "Associated projects"
   field_author_name: Author
   field_author_user: User Name
-  field_author_username: "Associated User"
+  field_author_username: "Associated user"
   field_author_publications: "Publications by this Author" 
   field_identify_author_yes: "Yes"
   field_identify_author_correct: "Corrections"
   field_identify_author_no: "No"
-  entry_type: "Bibtex Entry Type"
   
   label_author_is_me: "(I am this author)"
   label_add_me_as_author: "Add me as an author"
@@ -43,11 +43,13 @@
   field_search_name: "Search by name"
   field_search_results: ""
   label_save_author: "Save author"
+  label_edit_author: "Edit author"
   label_author_information: "Author Information"
 
   remove_author: "Remove this author"
   
-  label_publications_plural: "Publications"
+  label_publication_plural: "Publications"
+  label_related_publication_plural: "Related publications"
   label_publication_new: "Create New Publication"
   label_publication_index: "List of Publication"
   label_add_publication_to_project: "Add publication to this project"
@@ -59,6 +61,7 @@
   label_publication_index: "View all publications"
   label_publication_other_details: "Details"
   
+  text_external_url: "Link to the publication or to an external page about it."
   text_author_name_on_paper: "Author's name as it appears on the paper."
   text_author_institution: "Author's institution as on the paper."
   text_author_email: "Author's email address as on the paper."
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/db/migrate/007_add_external_url_column_to_publications.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -0,0 +1,9 @@
+class AddExternalUrlColumnToPublications < ActiveRecord::Migration
+  def self.up
+    add_column :publications, :external_url, :string
+  end
+
+  def self.down
+    remove_column :publications, :external_url
+  end
+end
--- a/vendor/plugins/redmine_bibliography/init.rb	Fri Sep 09 16:35:12 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/init.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -7,6 +7,7 @@
 Dispatcher.to_prepare :redmine_model_dependencies do
   require_dependency 'project'
   require_dependency 'user'
+  require_dependency 'mailer'
 
   unless Project.included_modules.include? Bibliography::ProjectPublicationsPatch
     Project.send(:include, Bibliography::ProjectPublicationsPatch)
@@ -15,6 +16,12 @@
   unless User.included_modules.include? Bibliography::UserAuthorPatch
     User.send(:include, Bibliography::UserAuthorPatch)
   end
+
+  unless Mailer.included_modules.include? Bibliography::MailerPatch
+    Mailer.send(:include, Bibliography::MailerPatch)
+  end
+
+
 end
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/lib/bibliography/mailer_patch.rb	Fri Sep 09 16:35:27 2011 +0100
@@ -0,0 +1,28 @@
+require_dependency 'mailer'
+
+module Bibliography
+  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 
+        # an author of that publication
+        #
+        # Example:
+        #   publication_added(user) => tmail object
+        #   Mailer.deliver_add_to_project(user) => sends an email to the registered user
+        def publication_added(user, publication)
+
+          @publication = publication
+
+          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)
+        end
+        
+        
+    end
+  end
+end