Mercurial > hg > soundsoftware-site
changeset 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 | 05ce7de07fef |
children | 194867efafa9 658b403da20a |
files | app/controllers/my_controller.rb app/controllers/users_controller.rb app/helpers/activities_helper.rb app/helpers/my_helper.rb app/views/my/blocks/_colleagues.html.erb config/locales/en.yml public/themes/soundsoftware/stylesheets/application.css |
diffstat | 7 files changed, 81 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/app/controllers/my_controller.rb Tue Mar 12 10:30:38 2013 +0000 +++ b/app/controllers/my_controller.rb Tue Mar 12 13:01:36 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'],
--- a/app/controllers/users_controller.rb Tue Mar 12 10:30:38 2013 +0000 +++ b/app/controllers/users_controller.rb Tue Mar 12 13:01:36 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
--- 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
--- a/app/helpers/my_helper.rb Tue Mar 12 10:30:38 2013 +0000 +++ b/app/helpers/my_helper.rb Tue Mar 12 13:01:36 2013 +0000 @@ -18,4 +18,11 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module MyHelper + +def all_colleagues_of(user) + # Return a list of all user ids who have worked with the given user + # (on projects that are visible to the current user) + user.projects.select { |p| p.visible? }.map { |p| p.members.map { |m| m.user_id } }.flatten.sort.uniq.reject { |i| user.id == i } end + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/views/my/blocks/_colleagues.html.erb Tue Mar 12 13:01:36 2013 +0000 @@ -0,0 +1,11 @@ + +<% colleagues = all_colleagues_of(@user) %> + +<% if !colleagues.empty? %> + <h3><%=l(:label_my_colleagues)%></h3> + <div class="box"> + <%= render_active_colleagues(colleagues) %> + </div> +<% end %> + +
--- a/config/locales/en.yml Tue Mar 12 10:30:38 2013 +0000 +++ b/config/locales/en.yml Tue Mar 12 13:01:36 2013 +0000 @@ -883,6 +883,9 @@ label_parent_revision: Parent label_child_revision: Child label_export_options: %{export_format} export options + label_my_colleagues: People I'm working with + label_working_in: Working in + label_no_active_colleagues: No recent activity button_login: Login button_submit: Submit
--- a/public/themes/soundsoftware/stylesheets/application.css Tue Mar 12 10:30:38 2013 +0000 +++ b/public/themes/soundsoftware/stylesheets/application.css Tue Mar 12 13:01:36 2013 +0000 @@ -79,6 +79,9 @@ .box .more { margin-left: 40px; } +.box .institution { font-size: 0.95em; } +.box .active { margin-left: 2em; } + #content .tabs { margin-bottom: 0; } table.list th { background-color: #fdfaf0; border-bottom: 1px solid #a9b680; }