diff app/views/activities/_busy_institution.html.erb @ 1009:066b55d7c053 browsing

Add busy institutions list
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Mon, 12 Nov 2012 13:34:32 +0000
parents
children f44860e089c5
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/app/views/activities/_busy_institution.html.erb	Mon Nov 12 13:34:32 2012 +0000
@@ -0,0 +1,34 @@
+<% events = @events_by_day %>
+<% max = 5 %>
+<% if (events.nil?) 
+     activity = Redmine::Activity::Fetcher.new(User.current)
+     events = activity.events(Date.today - 14, Date.today + 1)
+   end
+%>
+
+<% if events.empty? %>
+
+<% else %>
+
+   <ul>
+
+   <% 
+      authors = events.map { |e| e.event_author unless !e.respond_to?(:event_author) }.compact
+      institutions = authors.map { |a| a.ssamr_user_detail.institution_name }
+      insthash = institutions.compact.sort.group_by { |i| i }
+      insthash = insthash.merge(insthash) { |k,v| v.length }
+      threshold = insthash.values.sort.last(max).first
+      busy = insthash.keys.select { |k| insthash[k] >= threshold }.sample(max)
+
+      for institution in busy
+   %>
+
+   <li class="busy">
+     <span class="title">
+       <%= link_to h(institution), { :controller => 'activities', :institution => institution } %>
+     </span>
+   </li>
+
+    <% end %>
+  </ul>
+<% end %>