diff app/helpers/activities_helper.rb @ 1217:875b5b4c574d cannam

Add "People I'm working with" as My Page box -- currently off by default
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 12 Mar 2013 13:01:36 +0000
parents adb5f38f6ab7
children 3286032e15cf
line wrap: on
line diff
--- a/app/helpers/activities_helper.rb	Tue Mar 12 10:30:38 2013 +0000
+++ b/app/helpers/activities_helper.rb	Tue Mar 12 13:01:36 2013 +0000
@@ -15,11 +15,11 @@
     end
   end
 
-  def busy_projects(events, count)
+  def project_activity_on_events(events)
 
     # Score each project for which there are any events, by giving
     # each event a score based on how long ago it was (the more recent
-    # the better).
+    # the better). Return a hash mapping project id to score.
 
     projhash = Hash.new
     
@@ -40,6 +40,57 @@
       end
     end
 
+    projhash
+  end
+
+  def projects_by_activity(user, count)
+
+    # Return up to count of the user's projects ordered by that user's
+    # recent activity, omitting any projects for which no activity
+    # occurred in the recent past
+
+    activity = Redmine::Activity::Fetcher.new(user, :author => user)
+    days = Setting.activity_days_default.to_i
+    events = activity.events(Date.today - days, Date.today + 1)
+    projhash = project_activity_on_events(events)
+    projhash.keys.sort_by { |k| -projhash[k] }.first(count)
+  end
+
+  def render_active_colleagues(colleagues)
+
+    s = ""
+
+    for c in colleagues
+      u = User.find_by_id(c)
+      active_projects = projects_by_activity(u, 3)
+      if !active_projects.empty?
+        s << "<div class='user'>"
+        s << link_to_user(u)
+        s << "<span class='institution'>"
+        s << h(u.ssamr_user_detail.institution_name)
+        s << "</span>"
+        s << "</div>"
+        s << "<div class='active'>"
+        s << l(:label_working_in) << " "
+        s << (active_projects.map { |p| link_to_project(p) }.join ", ")
+        s << "</div>"
+      end
+    end
+    
+    if s != ""
+      s
+    else
+      l(:label_no_active_colleagues)
+    end
+  end
+
+  def busy_projects(events, count)
+
+    # Return a list of count projects randomly selected from amongst
+    # the busiest projects represented by the given activity events
+
+    projhash = project_activity_on_events(events)
+
     # pick N highest values and use cutoff value as selection threshold
     threshold = projhash.values.sort.last(count).first