Mercurial > hg > soundsoftware-site
comparison app/helpers/projects_helper.rb @ 205:05f9a2a9c753 bug_67
Projects page: Sort and paginate table on the basis of root projects only; recurse to children (if any) after each root project is rendered. Fixes #67
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Tue, 08 Feb 2011 12:16:25 +0000 |
parents | 4e485928a26b |
children | 73ff0e6a11b1 f1a12c3b4587 |
comparison
equal
deleted
inserted
replaced
197:5da98461a9f6 | 205:05f9a2a9c753 |
---|---|
161 s = "" | 161 s = "" |
162 s << "<div class='autoscroll'>" | 162 s << "<div class='autoscroll'>" |
163 s << "<table class='list projects'>" | 163 s << "<table class='list projects'>" |
164 s << "<thead><tr>" | 164 s << "<thead><tr>" |
165 | 165 |
166 s << sort_header_tag('lft', :caption => l("field_name"), :default_order => 'desc') | 166 s << sort_header_tag('name', :caption => l("field_name")) |
167 s << "<th class='managers'>" << l("label_managers") << "</th>" | 167 s << "<th class='managers'>" << l("label_managers") << "</th>" |
168 s << sort_header_tag('created_on', :default_order => 'desc') | 168 s << sort_header_tag('created_on', :default_order => 'desc') |
169 s << sort_header_tag('updated_on', :default_order => 'desc') | 169 s << sort_header_tag('updated_on', :default_order => 'desc') |
170 | 170 |
171 s << "</tr></thead><tbody>" | 171 s << "</tr></thead><tbody>" |
172 | 172 |
173 ancestors = [] | |
174 original_project = @project | 173 original_project = @project |
175 oddeven = 'even' | |
176 level = 0 | |
177 | 174 |
178 projects.each do |project| | 175 projects.each do |project| |
179 | 176 s << render_project_in_table(project, cycle('odd', 'even'), 0) |
180 # set the project environment to please macros. | 177 end |
181 | 178 |
182 @project = project | 179 s << "</table>" |
183 | 180 |
184 if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) | 181 @project = original_project |
185 level = level + 1 | 182 |
186 else | 183 s |
187 level = 0 | 184 end |
188 oddeven = cycle('odd','even') | 185 |
189 ancestors.pop | 186 |
190 while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) | 187 def render_project_in_table(project, oddeven, level) |
191 ancestors.pop | 188 |
189 # set the project environment to please macros. | |
190 @project = project | |
191 | |
192 classes = (level == 0 ? 'root' : 'child') | |
193 | |
194 s = "" | |
195 | |
196 s << "<tr class='#{oddeven} #{classes} level#{level}'>" | |
197 s << "<td class='firstcol' align=top><div class='name hosted_here" | |
198 s << " no_description" if project.description.blank? | |
199 s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); | |
200 s << "</div>" | |
201 unless project.description.blank? | |
202 s << "<div class='wiki description'>" | |
203 s << textilizable(project.short_description, :project => project) | |
204 s << "</div>" | |
205 end | |
206 | |
207 s << "<td class='managers' align=top>" | |
208 | |
209 u = project.users_by_role | |
210 if u | |
211 u.keys.each do |r| | |
212 if r.allowed_to?(:edit_project) | |
213 mgrs = [] | |
214 u[r].sort.each do |m| | |
215 mgrs << link_to_user(m) | |
216 end | |
217 if mgrs.size < 3 | |
218 s << '<nobr>' << mgrs.join(', ') << '</nobr>' | |
219 else | |
220 s << mgrs.join(', ') | |
221 end | |
192 end | 222 end |
193 end | 223 end |
194 | 224 end |
195 classes = (ancestors.empty? ? 'root' : 'child') | 225 |
196 | 226 s << "</td>" |
197 s << "<tr class='#{oddeven} #{classes} level#{level}'>" | 227 s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
198 s << "<td class='firstcol' align=top><div class='name hosted_here" | 228 s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
199 s << " no_description" if project.description.blank? | 229 |
200 s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); | 230 s << "</tr>" |
201 s << "</div>" | 231 |
202 unless project.description.blank? | 232 project.children.each do |child| |
203 s << "<div class='wiki description'>" | 233 s << render_project_in_table(child, oddeven, level + 1) |
204 s << textilizable(project.short_description, :project => project) | 234 end |
205 s << "</div>" | 235 |
206 end | |
207 | |
208 s << "<td class='managers' align=top>" | |
209 | |
210 u = project.users_by_role | |
211 if u | |
212 u.keys.each do |r| | |
213 if r.allowed_to?(:edit_project) | |
214 mgrs = [] | |
215 u[r].sort.each do |m| | |
216 mgrs << link_to_user(m) | |
217 end | |
218 if mgrs.size < 3 | |
219 s << '<nobr>' << mgrs.join(', ') << '</nobr>' | |
220 else | |
221 s << mgrs.join(', ') | |
222 end | |
223 end | |
224 end | |
225 end | |
226 | |
227 s << "</td>" | |
228 s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" | |
229 s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" | |
230 | |
231 s << "</tr>" | |
232 | |
233 ancestors << project | |
234 end | |
235 | |
236 s << "</table>" | |
237 | |
238 @project = original_project | |
239 | |
240 s | 236 s |
241 end | 237 end |
242 | |
243 | 238 |
244 | 239 |
245 # Returns a set of options for a select field, grouped by project. | 240 # Returns a set of options for a select field, grouped by project. |
246 def version_options_for_select(versions, selected=nil) | 241 def version_options_for_select(versions, selected=nil) |
247 grouped = Hash.new {|h,k| h[k] = []} | 242 grouped = Hash.new {|h,k| h[k] = []} |