# HG changeset patch # User Chris Cannam # Date 1363093251 0 # Node ID 194867efafa9bb56b0fb91cf7b9f3caad8169afa # Parent 68a94715fb56b89c5158e08d28a1824e39ca8cf3# Parent 875b5b4c574d8b356f41f1c0bfc0b37e6ba944cb Merge from branch "cannam" diff -r 68a94715fb56 -r 194867efafa9 app/controllers/my_controller.rb --- a/app/controllers/my_controller.rb Tue Feb 12 10:37:52 2013 +0000 +++ b/app/controllers/my_controller.rb Tue Mar 12 13:00:51 2013 +0000 @@ -22,6 +22,7 @@ helper :users helper :custom_fields helper :projects + helper :activities BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, 'issuesreportedbyme' => :label_reported_issues, @@ -32,7 +33,8 @@ 'calendar' => :label_calendar, 'documents' => :label_document_plural, 'timelog' => :label_spent_time, - 'myprojects' => :label_my_projects + 'myprojects' => :label_my_projects, + 'colleagues' => :label_my_colleagues }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze DEFAULT_LAYOUT = { 'left' => ['myprojects', 'activitymyprojects'], diff -r 68a94715fb56 -r 194867efafa9 app/controllers/users_controller.rb --- a/app/controllers/users_controller.rb Tue Feb 12 10:37:52 2013 +0000 +++ b/app/controllers/users_controller.rb Tue Mar 12 13:00:51 2013 +0000 @@ -71,15 +71,7 @@ if @user.ssamr_user_detail != nil @description = @user.ssamr_user_detail.description - - if @user.ssamr_user_detail.institution_type != nil - # institution_type is true for listed institutions - if (@user.ssamr_user_detail.institution_type) - @institution_name = Institution.find(@user.ssamr_user_detail.institution_id).name - else - @institution_name = @user.ssamr_user_detail.other_institution - end - end + @institution_name = @user.ssamr_user_detail.institution_name end # show projects based on current user visibility diff -r 68a94715fb56 -r 194867efafa9 app/helpers/activities_helper.rb --- a/app/helpers/activities_helper.rb Tue Feb 12 10:37:52 2013 +0000 +++ b/app/helpers/activities_helper.rb Tue Mar 12 13:00:51 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 << "