annotate 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
rev   line source
chris@1009 1 <% events = @events_by_day %>
chris@1009 2 <% max = 5 %>
chris@1009 3 <% if (events.nil?)
chris@1009 4 activity = Redmine::Activity::Fetcher.new(User.current)
chris@1009 5 events = activity.events(Date.today - 14, Date.today + 1)
chris@1009 6 end
chris@1009 7 %>
chris@1009 8
chris@1009 9 <% if events.empty? %>
chris@1009 10
chris@1009 11 <% else %>
chris@1009 12
chris@1009 13 <ul>
chris@1009 14
chris@1009 15 <%
chris@1009 16 authors = events.map { |e| e.event_author unless !e.respond_to?(:event_author) }.compact
chris@1009 17 institutions = authors.map { |a| a.ssamr_user_detail.institution_name }
chris@1009 18 insthash = institutions.compact.sort.group_by { |i| i }
chris@1009 19 insthash = insthash.merge(insthash) { |k,v| v.length }
chris@1009 20 threshold = insthash.values.sort.last(max).first
chris@1009 21 busy = insthash.keys.select { |k| insthash[k] >= threshold }.sample(max)
chris@1009 22
chris@1009 23 for institution in busy
chris@1009 24 %>
chris@1009 25
chris@1009 26 <li class="busy">
chris@1009 27 <span class="title">
chris@1009 28 <%= link_to h(institution), { :controller => 'activities', :institution => institution } %>
chris@1009 29 </span>
chris@1009 30 </li>
chris@1009 31
chris@1009 32 <% end %>
chris@1009 33 </ul>
chris@1009 34 <% end %>