comparison app/helpers/projects_helper.rb @ 523:0b6c82dead28 luisf

Merge from branch "cannam"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:23:37 +0100
parents d7326bb4f6f0
children 863f447c4d88
comparison
equal deleted inserted replaced
318:f7c525dc7585 523:0b6c82dead28
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 module ProjectsHelper 18 module ProjectsHelper
19 def link_to_version(version, options = {}) 19 def link_to_version(version, options = {})
20 return '' unless version && version.is_a?(Version) 20 return '' unless version && version.is_a?(Version)
21 link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options 21 link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
22 end 22 end
23 23
24 def project_settings_tabs 24 def project_settings_tabs
25 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural}, 25 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
26 {:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page},
26 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural}, 27 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
27 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
28 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural}, 28 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
29 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural}, 29 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
30 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki}, 30 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
31 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository}, 31 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
32 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural}, 32 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
33 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities} 33 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
34 ] 34 ]
35 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)} 35 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
36 end 36 end
37 37
38 def parent_project_select_tag(project) 38 def parent_project_select_tag(project)
39 selected = project.parent 39 selected = project.parent
40 # retrieve the requested parent project 40 # retrieve the requested parent project
41 parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] 41 parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
42 if parent_id 42 if parent_id
43 selected = (parent_id.blank? ? nil : Project.find(parent_id)) 43 selected = (parent_id.blank? ? nil : Project.find(parent_id))
44 end 44 end
45 45
46 options = '' 46 options = ''
47 options << "<option value=''></option>" if project.allowed_parents.include?(nil) 47 options << "<option value=''></option>" if project.allowed_parents.include?(nil)
48 options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected) 48 options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
49 content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id') 49 content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
50 end
51
52 def render_project_short_description(project)
53 s = ''
54 if (project.short_description)
55 s << "<div class='description'>"
56 s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '')
57 s << "</div>"
58 end
59 s
50 end 60 end
51 61
52 # Renders a tree of projects as a nested set of unordered lists 62 # Renders a tree of projects as a nested set of unordered lists
53 # The given collection may be a subset of the whole project tree 63 # The given collection may be a subset of the whole project tree
54 # (eg. some intermediate nodes are private and can not be seen) 64 # (eg. some intermediate nodes are private and can not be seen)
63 if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) 73 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
64 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" 74 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
65 else 75 else
66 ancestors.pop 76 ancestors.pop
67 s << "</li>" 77 s << "</li>"
68 while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) 78 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
69 ancestors.pop 79 ancestors.pop
70 s << "</ul></li>\n" 80 s << "</ul></li>\n"
71 end 81 end
72 end 82 end
73 classes = (ancestors.empty? ? 'root' : 'child') 83 classes = (ancestors.empty? ? 'root' : 'child')
74 s << "<li class='#{classes}'><div class='#{classes}'>" + 84 s << "<li class='#{classes}'><div class='#{classes}'>" +
75 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") 85 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
76 s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? 86 s << render_project_short_description(project)
77 s << "</div>\n" 87 s << "</div>\n"
78 ancestors << project 88 ancestors << project
79 end 89 end
80 s << ("</li></ul>\n" * ancestors.size) 90 s << ("</li></ul>\n" * ancestors.size)
81 @project = original_project 91 @project = original_project
82 end 92 end
83 s 93 s
84 end 94 end
85 95
96
97 def render_my_project_in_hierarchy(project)
98
99 s = ''
100
101 if User.current.member_of?(project)
102
103 # set the project environment to please macros.
104 @project = project
105
106 classes = (project.root? ? 'root' : 'child')
107
108 s << "<li class='#{classes}'><div class='#{classes}'>" +
109 link_to_project(project, {}, :class => "project my-project")
110 if project.is_public?
111 s << " <span class='public'>" << l("field_is_public") << "</span>"
112 else
113 s << " <span class='private'>" << l("field_is_private") << "</span>"
114 end
115 s << render_project_short_description(project)
116 s << "</div>\n"
117
118 cs = ''
119 project.children.each do |child|
120 cs << render_my_project_in_hierarchy(child)
121 end
122
123 if cs != ''
124 s << "<ul class='projects'>\n" << cs << "</ul>\n";
125 end
126
127 end
128
129 s
130
131 end
86 132
87 # Renders a tree of projects where the current user belongs 133 # Renders a tree of projects where the current user belongs
88 # as a nested set of unordered lists 134 # as a nested set of unordered lists
89 # The given collection may be a subset of the whole project tree 135 # The given collection may be a subset of the whole project tree
90 # (eg. some intermediate nodes are private and can not be seen) 136 # (eg. some intermediate nodes are private and can not be seen)
91 def render_my_project_hierarchy(projects) 137 def render_my_project_hierarchy(projects)
92 s = '' 138
93 139 s = ''
94 a = '' 140
95 141 original_project = @project
96 # Flag to tell if user has any projects 142
97 t = FALSE 143 projects.each do |project|
98 144 if project.root? || !projects.include?(project.parent)
99 if projects.any? 145 s << render_my_project_in_hierarchy(project)
100 ancestors = [] 146 end
101 original_project = @project 147 end
102 projects.each do |project| 148
103 # set the project environment to please macros. 149 @project = original_project
104 150
105 @project = project 151 if s != ''
106 152 a = ''
107 if User.current.member_of?(project):
108
109 t = TRUE
110
111 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
112 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
113 else
114 ancestors.pop
115 s << "</li>"
116 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
117 ancestors.pop
118 s << "</ul></li>\n"
119 end
120 end
121
122 classes = (ancestors.empty? ? 'root' : 'child')
123 s << "<li class='#{classes}'><div class='#{classes}'>" +
124 link_to_project(project, {}, :class => "project my-project")
125 if project.is_public?
126 s << " <span class='public'>" << l("field_is_public") << "</span>"
127 else
128 s << " <span class='private'>" << l("field_is_private") << "</span>"
129 end
130 s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
131 s << "</div>\n"
132 ancestors << project
133 end
134 end
135 s << ("</li></ul>\n" * ancestors.size)
136 @project = original_project
137 end
138
139 if t == TRUE
140 a << "<h2>" 153 a << "<h2>"
141 a << l("label_my_project_plural") 154 a << l("label_my_project_plural")
142 a << "</h2>" 155 a << "</h2>"
156 a << "<ul class='projects root'>\n"
143 a << s 157 a << s
144 else 158 a << "</ul>\n"
145 a = s 159 s = a
146 end 160 end
147 161
148 a 162 s
163
149 end 164 end
150 165
151 # Renders a tree of projects that the current user does not belong 166 # Renders a tree of projects that the current user does not belong
152 # to, or of all projects if the current user is not logged in. The 167 # to, or of all projects if the current user is not logged in. The
153 # given collection may be a subset of the whole project tree 168 # given collection may be a subset of the whole project tree
196 s << "<tr class='#{oddeven} #{classes} level#{level}'>" 211 s << "<tr class='#{oddeven} #{classes} level#{level}'>"
197 s << "<td class='firstcol' align=top><div class='name hosted_here" 212 s << "<td class='firstcol' align=top><div class='name hosted_here"
198 s << " no_description" if project.description.blank? 213 s << " no_description" if project.description.blank?
199 s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); 214 s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}");
200 s << "</div>" 215 s << "</div>"
201 unless project.description.blank? 216 s << render_project_short_description(project)
202 s << "<div class='wiki description'>"
203 s << textilizable(project.short_description, :project => project)
204 s << "</div>"
205 end
206 217
207 s << "<td class='managers' align=top>" 218 s << "<td class='managers' align=top>"
208 219
209 u = project.users_by_role 220 u = project.users_by_role
210 if u 221 if u
228 s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" 239 s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>"
229 240
230 s << "</tr>" 241 s << "</tr>"
231 242
232 project.children.each do |child| 243 project.children.each do |child|
233 s << render_project_in_table(child, oddeven, level + 1) 244 if child.is_public? or User.current.member_of?(child)
245 s << render_project_in_table(child, oddeven, level + 1)
246 end
234 end 247 end
235 248
236 s 249 s
237 end 250 end
238 251
245 end 258 end
246 # Add in the selected 259 # Add in the selected
247 if selected && !versions.include?(selected) 260 if selected && !versions.include?(selected)
248 grouped[selected.project.name] << [selected.name, selected.id] 261 grouped[selected.project.name] << [selected.name, selected.id]
249 end 262 end
250 263
251 if grouped.keys.size > 1 264 if grouped.keys.size > 1
252 grouped_options_for_select(grouped, selected && selected.id) 265 grouped_options_for_select(grouped, selected && selected.id)
253 else 266 else
254 options_for_select((grouped.values.first || []), selected && selected.id) 267 options_for_select((grouped.values.first || []), selected && selected.id)
255 end 268 end