changeset 535:dd9d9c0ff0f9 feature_36

created the helpers to display correctly the My Publications Authors and Projects.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Tue, 26 Jul 2011 18:25:14 +0100
parents cdec3eeaef7e
children 168714032c7e e25248ba597c
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/helpers/my_helper.rb vendor/plugins/redmine_bibliography/app/views/my/blocks/_publications_box.html.erb
diffstat 3 files changed, 56 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jul 26 14:35:11 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Tue Jul 26 18:25:14 2011 +0100
@@ -3,7 +3,7 @@
 class PublicationsController < ApplicationController
   unloadable
   
-  before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author]
+  # before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author]
     
   def new
     @publication = Publication.new      
@@ -24,8 +24,7 @@
     
     logger.error { "PUBLICATION CREATE ACTION" }
     logger.error { params[:publication]  }
-    
-    
+        
     @project = Project.find(params[:project_id])
 
     logger.error { "PARAMS publication" }
@@ -83,7 +82,7 @@
   end
 
   def show
-    logger.error "-------> No Show"
+    find_project_by_project_id unless params[:project_id].nil?
     
     @publication = Publication.find(params[:id])
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/helpers/my_helper.rb	Tue Jul 26 18:25:14 2011 +0100
@@ -0,0 +1,45 @@
+module MyHelper
+
+  def get_my_publications()
+    if not User.current.author.nil?
+      @my_publications = Publication.all(:include => :authors, :conditions => "authors.id = #{User.current.author.id}")
+    else
+      @my_publications = []
+    end
+  end 
+
+  def render_publications_projects(publication)    
+    s = ""
+    projs = []
+    
+    publication.projects.each do |proj|
+      projs << link_to(proj.name, proj)               
+    end
+    
+    if projs.size < 3
+        s << '<nobr>' << projs.join(', ') << '</nobr>'
+      else
+        s << projs.join(', ')
+    end  
+    
+    s
+  end
+
+  def render_publications_authors(publication)    
+    s = ""
+    auths = []
+          
+    publication.authorships.each do |auth|
+      auths << h(auth.name_on_paper)
+    end
+    
+    if auths.size < 3
+        s << '<nobr>' << auths.join(', ') << '</nobr>'
+      else
+        s << auths.join(', ')
+    end
+    s
+  end
+
+
+end
--- a/vendor/plugins/redmine_bibliography/app/views/my/blocks/_publications_box.html.erb	Tue Jul 26 14:35:11 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/my/blocks/_publications_box.html.erb	Tue Jul 26 18:25:14 2011 +0100
@@ -1,4 +1,6 @@
-<h3><%=l(:label_my_publications_box)%> <%= "(" + Publication.all(:include => :authors, :conditions => "authors.id = #{User.current.author.id}").count.to_s + ")" unless User.current.author.nil? %></h3>
+<% get_my_publications %>
+
+<h3><%=l(:label_my_publications_box) %> <%= "(" + @my_publications.count.to_s + ")" %> </h3>
 
 <table class="list publications">		
 	<thead><tr>
@@ -6,24 +8,18 @@
 	<th><%=l(:field_publication_authors)%></th>
 	<th><%=l(:field_publication_projects)%></th>
 	</tr></thead>
-	<tbody>	
-  <% Publication.all(:include => :authors, :conditions => "authors.id = #{User.current.author.id}").each do |publication|%>
-    
+	<tbody>
+	  	
+  <% @my_publications.each do |publication|%>    
 	<tr id="publication-<%= publication.id %>" class="<%= cycle('odd', 'even') %>">
 		<td class="title">
 			<%= link_to publication.title, publication %>
 		</td>
     <td class="authors">
-      <% publication.authorships.each do |authorship| %>
-        <%= h authorship.name_on_paper %>
-      <% end %>		
+      <%= render_publications_authors(publication) %>
     </td>
     <td class="project">             
-      <% publication.projects.each do |proj| %>
-        
-        <%= link_to proj.name, proj %>
-        
-      <% end %>		
+      <%= render_publications_projects(publication) %>	
     </td>
 	</tr>
 	<% end %>