annotate app/helpers/my_helper.rb @ 1224:30c444ea1338 cannam

Various fixes to colleagues box
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 12 Mar 2013 15:15:18 +0000
parents 875b5b4c574d
children d280360758e5
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@909 3 # Redmine - project management software
Chris@909 4 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@909 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@909 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@0 20 module MyHelper
chris@1217 21
chris@1224 22 def all_colleagues_of(user)
chris@1224 23 # Return a list of all user ids who have worked with the given user
chris@1224 24 # (on projects that are visible to the current user)
chris@1224 25 user.projects.select { |p| p.visible? }.map { |p| p.members.map { |m| m.user_id } }.flatten.sort.uniq.reject { |i| user.id == i }
chris@1224 26 end
chris@1224 27
chris@1224 28 def render_active_colleagues(colleagues)
chris@1224 29
chris@1224 30 s = ""
chris@1224 31
chris@1224 32 start = Time.now
chris@1224 33
chris@1224 34 my_inst = ""
chris@1224 35 if ! User.current.ssamr_user_detail.nil?
chris@1224 36 my_inst = User.current.ssamr_user_detail.institution_name
chris@1224 37 end
chris@1224 38
chris@1224 39 for c in colleagues
chris@1224 40 u = User.find_by_id(c)
chris@1224 41 active_projects = projects_by_activity(u, 3)
chris@1224 42 if !active_projects.empty?
chris@1224 43 s << "<div class='active-person'>"
chris@1224 44 s << avatar(u, :size => '24')
chris@1224 45 s << "<span class='user'>"
chris@1224 46 s << h(u.name)
chris@1224 47 s << "</span>"
chris@1224 48 if !u.ssamr_user_detail.nil?
chris@1224 49 inst = u.ssamr_user_detail.institution_name
chris@1224 50 if inst != "" and inst != my_inst
chris@1224 51 s << " - <span class='institution'>"
chris@1224 52 s << h(inst)
chris@1224 53 s << "</span>"
chris@1224 54 end
chris@1224 55 end
chris@1224 56 s << "<br>"
chris@1224 57 s << "<span class='active'>"
chris@1224 58 s << (active_projects.map { |p| link_to_project(p) }.join ", ")
chris@1224 59 s << "</span>"
chris@1224 60 s << "</div>"
chris@1224 61 end
chris@1224 62 end
chris@1224 63
chris@1224 64 finish = Time.now
chris@1224 65 logger.info "render_active_colleagues: took #{finish-start}"
chris@1224 66
chris@1224 67 if s != ""
chris@1224 68 s
chris@1224 69 else
chris@1224 70 l(:label_no_active_colleagues)
chris@1224 71 end
chris@1224 72 end
chris@1217 73
chris@1217 74 end