Revision 1026:b42553f6df71 app/helpers
| app/helpers/activities_helper.rb | ||
|---|---|---|
| 1 |
|
|
| 2 |
module ActivitiesHelper |
|
| 3 |
|
|
| 4 |
def busy_projects(events, count) |
|
| 5 |
# Transform events list into hash from project id to number of |
|
| 6 |
# occurrences of project in list (there is surely a tidier way |
|
| 7 |
# to do this, e.g. chunk() in Ruby 1.9 but not in 1.8) |
|
| 8 |
phash = events.map { |e| e.project unless !e.respond_to?(:project) }.sort.group_by { |p| p.id }
|
|
| 9 |
phash = phash.merge(phash) { |k,v| v.length }
|
|
| 10 |
threshold = phash.values.sort.last(count).first |
|
| 11 |
busy = phash.keys.select { |k| phash[k] >= threshold }.sample(count)
|
|
| 12 |
busy.map { |pid| Project.find(pid) }
|
|
| 13 |
end |
|
| 14 |
|
|
| 15 |
def busy_institutions(events, count) |
|
| 16 |
authors = events.map do |e| |
|
| 17 |
e.event_author unless !e.respond_to?(:event_author) |
|
| 18 |
end.compact |
|
| 19 |
institutions = authors.map do |a| |
|
| 20 |
if a.respond_to?(:ssamr_user_detail) and !a.ssamr_user_detail.nil? |
|
| 21 |
a.ssamr_user_detail.institution_name |
|
| 22 |
end |
|
| 23 |
end |
|
| 24 |
insthash = institutions.compact.sort.group_by { |i| i }
|
|
| 25 |
insthash = insthash.merge(insthash) { |k,v| v.length }
|
|
| 26 |
threshold = insthash.values.sort.last(count).first |
|
| 27 |
insthash.keys.select { |k| insthash[k] >= threshold }.sample(count)
|
|
| 28 |
end |
|
| 29 |
|
|
| 30 |
end |
|
| app/helpers/application_helper.rb | ||
|---|---|---|
| 291 | 291 |
def principals_check_box_tags(name, principals) |
| 292 | 292 |
s = '' |
| 293 | 293 |
principals.sort.each do |principal| |
| 294 |
s << "<label>#{ check_box_tag name, principal.id, false } #{link_to_user principal}</label>\n"
|
|
| 294 |
|
|
| 295 |
if principal.type == "User": |
|
| 296 |
s << "<label>#{ check_box_tag name, principal.id, false } #{link_to_user principal}</label>\n"
|
|
| 297 |
else |
|
| 298 |
s << "<label>#{ check_box_tag name, principal.id, false } #{h principal} (Group)</label>\n"
|
|
| 299 |
end |
|
| 300 |
|
|
| 295 | 301 |
end |
| 296 | 302 |
s.html_safe |
| 297 | 303 |
end |
| app/helpers/attachments_helper.rb | ||
|---|---|---|
| 42 | 42 |
api.created_on attachment.created_on |
| 43 | 43 |
end |
| 44 | 44 |
end |
| 45 |
|
|
| 46 |
# Returns true if user agent appears (approximately) to be a search |
|
| 47 |
# bot or crawler |
|
| 48 |
def user_is_search_bot? |
|
| 49 |
agent = request.env['HTTP_USER_AGENT'] |
|
| 50 |
agent and agent =~ /(bot|slurp|crawler|spider)\b/i |
|
| 51 |
end |
|
| 45 | 52 |
end |
| app/helpers/projects_helper.rb | ||
|---|---|---|
| 162 | 162 |
|
| 163 | 163 |
end |
| 164 | 164 |
|
| 165 |
# Renders a tree of projects that the current user does not belong |
|
| 166 |
# to, or of all projects if the current user is not logged in. The |
|
| 167 |
# given collection may be a subset of the whole project tree |
|
| 168 |
# (eg. some intermediate nodes are private and can not be seen). We |
|
| 169 |
# are potentially interested in various things: the project name, |
|
| 170 |
# description, manager(s), creation date, last activity date, |
|
| 171 |
# general activity level, whether there is anything actually hosted |
|
| 172 |
# here for the project, etc. |
|
| 165 |
# Renders a tree of projects. The given collection may be a subset |
|
| 166 |
# of the whole project tree (eg. some intermediate nodes are private |
|
| 167 |
# and can not be seen). We are potentially interested in various |
|
| 168 |
# things: the project name, description, manager(s), creation date, |
|
| 169 |
# last activity date, general activity level, whether there is |
|
| 170 |
# anything actually hosted here for the project, etc. |
|
| 173 | 171 |
def render_project_table(projects) |
| 174 | 172 |
|
| 175 | 173 |
s = "" |
Also available in: Unified diff