diff app/helpers/activities_helper.rb @ 1227:eb168c1e9553 live

Show maximum of 10 colleagues
author Chris Cannam
date Tue, 12 Mar 2013 15:45:41 +0000
parents d280360758e5
children 4f746d8966dd 441b66f148b6
line wrap: on
line diff
--- a/app/helpers/activities_helper.rb	Tue Mar 12 15:26:58 2013 +0000
+++ b/app/helpers/activities_helper.rb	Tue Mar 12 15:45:41 2013 +0000
@@ -45,7 +45,7 @@
 
   def projects_by_activity(user, count)
 
-    # Return up to count of the user's projects ordered by that user's
+    # Return up to count of the user's project ids ordered by that user's
     # recent activity, omitting any projects for which no activity
     # occurred in the recent past and any projects not visible to
     # the current user
@@ -72,11 +72,22 @@
       my_inst = User.current.ssamr_user_detail.institution_name
     end
 
-    s << "<dl>"
+    actives = Hash.new
     for c in colleagues
       u = User.find_by_id(c)
       active_projects = projects_by_activity(u, 3)
       if !active_projects.empty?
+        actives[c] = active_projects
+      end
+    end
+
+    if actives.empty?
+      l(:label_no_active_colleagues)
+    else
+
+      s << "<dl>"
+      for c in actives.keys.sample(10)
+        u = User.find_by_id(c)
         s << "<dt>"
         s << avatar(u, :size => '24')
         s << "<span class='user'>"
@@ -93,19 +104,15 @@
         s << "</dt>"
         s << "<dd>"
         s << "<span class='active'>"
-        s << (active_projects.map { |p| link_to_project(p) }.join ", ")
+        s << (actives[c].map { |p| link_to_project(p) }.join ", ")
         s << "</span>"
       end
-    end
-    s << "</dl>"
+      s << "</dl>"
 
-    finish = Time.now
-    logger.info "render_active_colleagues: took #{finish-start}"
+      finish = Time.now
+      logger.info "render_active_colleagues: took #{finish-start}"
     
-    if s != ""
       s
-    else
-      l(:label_no_active_colleagues)
     end
   end