changeset 1224:30c444ea1338 cannam

Various fixes to colleagues box
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 12 Mar 2013 15:15:18 +0000
parents 324461c477a7
children edf7563e2653 44475ccf56d3
files app/helpers/activities_helper.rb app/helpers/my_helper.rb app/views/my/blocks/_colleagues.html.erb
diffstat 3 files changed, 64 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/app/helpers/activities_helper.rb	Tue Mar 12 14:39:49 2013 +0000
+++ b/app/helpers/activities_helper.rb	Tue Mar 12 15:15:18 2013 +0000
@@ -51,6 +51,10 @@
     # the current user
 
     activity = Redmine::Activity::Fetcher.new(User.current, :author => user)
+
+    # Limit scope so as to exclude issues (which non-members can add)
+    activity.scope = [ "changesets", "files", "documents", "news", "wiki_edits", "messages", "time_entries", "publications" ]
+
     days = Setting.activity_days_default.to_i
     events = activity.events(Date.today - days, Date.today + 1)
     projhash = project_activity_on_events(events)
@@ -67,7 +71,8 @@
       u = User.find_by_id(c)
       active_projects = projects_by_activity(u, 3)
       if !active_projects.empty?
-        s << "<div class='active-person'>"
+        s << "<dl>"
+        s << "<dt>"
         s << avatar(u, :size => '24')
         s << "<span class='user'>"
         s << h(u.name)
@@ -77,11 +82,12 @@
           s << h(u.ssamr_user_detail.institution_name)
           s << "</span>"
         end
-        s << "<br>"
+        s << "</dt>"
+        s << "<dd>"
         s << "<span class='active'>"
         s << (active_projects.map { |p| link_to_project(p) }.join ", ")
         s << "</span>"
-        s << "</div>"
+        s << "</dl>"
       end
     end
 
--- a/app/helpers/my_helper.rb	Tue Mar 12 14:39:49 2013 +0000
+++ b/app/helpers/my_helper.rb	Tue Mar 12 15:15:18 2013 +0000
@@ -19,10 +19,56 @@
 
 module MyHelper
 
-def all_colleagues_of(user)
-  # Return a list of all user ids who have worked with the given user
-  # (on projects that are visible to the current user)
-  user.projects.select { |p| p.visible? }.map { |p| p.members.map { |m| m.user_id } }.flatten.sort.uniq.reject { |i| user.id == i }
-end
+  def all_colleagues_of(user)
+    # Return a list of all user ids who have worked with the given user
+    # (on projects that are visible to the current user)
+    user.projects.select { |p| p.visible? }.map { |p| p.members.map { |m| m.user_id } }.flatten.sort.uniq.reject { |i| user.id == i }
+  end
+
+  def render_active_colleagues(colleagues)
+
+    s = ""
+
+    start = Time.now
+
+    my_inst = ""
+    if ! User.current.ssamr_user_detail.nil?
+      my_inst = User.current.ssamr_user_detail.institution_name
+    end
+
+    for c in colleagues
+      u = User.find_by_id(c)
+      active_projects = projects_by_activity(u, 3)
+      if !active_projects.empty?
+        s << "<div class='active-person'>"
+        s << avatar(u, :size => '24')
+        s << "<span class='user'>"
+        s << h(u.name)
+        s << "</span>"
+        if !u.ssamr_user_detail.nil?
+          inst = u.ssamr_user_detail.institution_name
+          if inst != "" and inst != my_inst
+            s << " - <span class='institution'>"
+            s << h(inst)
+            s << "</span>"
+          end
+        end
+        s << "<br>"
+        s << "<span class='active'>"
+        s << (active_projects.map { |p| link_to_project(p) }.join ", ")
+        s << "</span>"
+        s << "</div>"
+      end
+    end
+
+    finish = Time.now
+    logger.info "render_active_colleagues: took #{finish-start}"
+    
+    if s != ""
+      s
+    else
+      l(:label_no_active_colleagues)
+    end
+  end
 
 end
--- a/app/views/my/blocks/_colleagues.html.erb	Tue Mar 12 14:39:49 2013 +0000
+++ b/app/views/my/blocks/_colleagues.html.erb	Tue Mar 12 15:15:18 2013 +0000
@@ -1,11 +1,13 @@
 
-<% colleagues = all_colleagues_of(@user) %>
+<% colleagues = all_colleagues_of(@user).sample(10) %>
 
 <% if !colleagues.empty? %>
+<div id="activity">
   <h3><%=l(:label_my_colleagues)%></h3>
-  <div class="box" id="active-colleagues">
+  <div class="activity box" id="active-colleagues">
     <%= render_active_colleagues(colleagues) %>
   </div>
+</div>
 <% end %>