Mercurial > hg > soundsoftware-site
comparison app/helpers/projects_helper.rb @ 1339:c03a6c3c4db9 luisf
Merge
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Thu, 20 Jun 2013 14:34:42 +0100 |
parents | 16826c3afbba |
children | 4f746d8966dd 51364c0cd58f 467282ce64a4 |
comparison
equal
deleted
inserted
replaced
1079:413d1d9c3efa | 1339:c03a6c3c4db9 |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # | 2 # |
3 # Redmine - project management software | 3 # Redmine - project management software |
4 # Copyright (C) 2006-2011 Jean-Philippe Lang | 4 # Copyright (C) 2006-2012 Jean-Philippe Lang |
5 # | 5 # |
6 # This program is free software; you can redistribute it and/or | 6 # This program is free software; you can redistribute it and/or |
7 # modify it under the terms of the GNU General Public License | 7 # modify it under the terms of the GNU General Public License |
8 # as published by the Free Software Foundation; either version 2 | 8 # as published by the Free Software Foundation; either version 2 |
9 # of the License, or (at your option) any later version. | 9 # of the License, or (at your option) any later version. |
28 {:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page}, | 28 {:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page}, |
29 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, | 29 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, |
30 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, | 30 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, |
31 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, | 31 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, |
32 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, | 32 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, |
33 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository}, | 33 {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural}, |
34 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, | 34 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, |
35 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} | 35 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} |
36 ] | 36 ] |
37 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} | 37 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} |
38 end | 38 end |
56 if (project.short_description) | 56 if (project.short_description) |
57 s << "<div class='description'>" | 57 s << "<div class='description'>" |
58 s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') | 58 s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') |
59 s << "</div>" | 59 s << "</div>" |
60 end | 60 end |
61 s | 61 s.html_safe |
62 end | 62 end |
63 | 63 |
64 # Renders a tree of projects as a nested set of unordered lists | 64 # Renders a tree of projects as a nested set of unordered lists |
65 # The given collection may be a subset of the whole project tree | 65 # The given collection may be a subset of the whole project tree |
66 # (eg. some intermediate nodes are private and can not be seen) | 66 # (eg. some intermediate nodes are private and can not be seen) |
87 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") | 87 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") |
88 s << render_project_short_description(project) | 88 s << render_project_short_description(project) |
89 s << "</div>\n" | 89 s << "</div>\n" |
90 ancestors << project | 90 ancestors << project |
91 end | 91 end |
92 s << ("</li></ul>\n" * ancestors.size) | |
93 @project = original_project | |
94 end | 92 end |
95 s.html_safe | 93 s.html_safe |
96 end | 94 end |
97 | 95 |
98 | 96 |
156 a << s | 154 a << s |
157 a << "</ul>\n" | 155 a << "</ul>\n" |
158 s = a | 156 s = a |
159 end | 157 end |
160 | 158 |
161 s | 159 s.html_safe |
162 | 160 |
163 end | 161 end |
164 | 162 |
165 # Renders a tree of projects. The given collection may be a subset | 163 # Renders a tree of projects. The given collection may be a subset |
166 # of the whole project tree (eg. some intermediate nodes are private | 164 # of the whole project tree (eg. some intermediate nodes are private |
190 | 188 |
191 s << "</table>" | 189 s << "</table>" |
192 | 190 |
193 @project = original_project | 191 @project = original_project |
194 | 192 |
195 s | 193 s.html_safe |
196 end | 194 end |
197 | 195 |
198 | 196 |
199 def render_project_in_table(project, oddeven, level) | 197 def render_project_in_table(project, oddeven, level) |
200 | 198 |
251 def version_options_for_select(versions, selected=nil) | 249 def version_options_for_select(versions, selected=nil) |
252 grouped = Hash.new {|h,k| h[k] = []} | 250 grouped = Hash.new {|h,k| h[k] = []} |
253 versions.each do |version| | 251 versions.each do |version| |
254 grouped[version.project.name] << [version.name, version.id] | 252 grouped[version.project.name] << [version.name, version.id] |
255 end | 253 end |
256 # Add in the selected | |
257 if selected && !versions.include?(selected) | |
258 grouped[selected.project.name] << [selected.name, selected.id] | |
259 end | |
260 | 254 |
261 if grouped.keys.size > 1 | 255 if grouped.keys.size > 1 |
262 grouped_options_for_select(grouped, selected && selected.id) | 256 grouped_options_for_select(grouped, selected && selected.id) |
263 else | 257 else |
264 options_for_select((grouped.values.first || []), selected && selected.id) | 258 options_for_select((grouped.values.first || []), selected && selected.id) |
267 | 261 |
268 def format_version_sharing(sharing) | 262 def format_version_sharing(sharing) |
269 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) | 263 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
270 l("label_version_sharing_#{sharing}") | 264 l("label_version_sharing_#{sharing}") |
271 end | 265 end |
266 | |
267 def score_maturity(project) | |
268 nr_changes = (project.repository.nil? ? 0 : project.repository.changesets.count) | |
269 downloadables = [project.attachments, | |
270 project.versions.collect { |v| v.attachments }, | |
271 project.documents.collect { |d| d.attachments }].flatten | |
272 nr_downloadables = downloadables.count | |
273 nr_downloads = downloadables.map do |d| d.downloads end.sum | |
274 nr_members = project.members.count | |
275 nr_publications = if project.respond_to? :publications | |
276 then project.publications.count else 0 end | |
277 Math.log(1 + nr_changes) + | |
278 Math.log(1 + nr_downloadables) + | |
279 Math.log(1 + nr_downloads) + | |
280 Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) + | |
281 Math.sqrt(nr_publications) | |
282 end | |
283 | |
284 def all_maturity_scores() | |
285 phash = Hash.new | |
286 pp = Project.visible(User.anonymous) | |
287 pp.each do |p| | |
288 phash[p] = score_maturity p | |
289 end | |
290 phash | |
291 end | |
292 | |
293 def mature_projects(count) | |
294 phash = all_maturity_scores | |
295 scores = phash.values.sort | |
296 threshold = scores[scores.length / 2] | |
297 if threshold == 0 then threshold = 1 end | |
298 phash.keys.select { |k| phash[k] > threshold }.sample(count) | |
299 end | |
272 end | 300 end |