Mercurial > hg > soundsoftware-site
comparison app/helpers/projects_helper.rb @ 423:50fd9c6b93a9 live
Merge from branch "bug_145"
author | Chris Cannam |
---|---|
date | Tue, 10 May 2011 12:00:10 +0100 |
parents | 2008fa7fda29 |
children | 350acce374a2 |
comparison
equal
deleted
inserted
replaced
422:19549b0c417a | 423:50fd9c6b93a9 |
---|---|
93 end | 93 end |
94 s | 94 s |
95 end | 95 end |
96 | 96 |
97 | 97 |
98 def render_my_project_in_hierarchy(project) | |
99 | |
100 s = '' | |
101 | |
102 if User.current.member_of?(project) | |
103 | |
104 # set the project environment to please macros. | |
105 @project = project | |
106 | |
107 classes = (project.root? ? 'root' : 'child') | |
108 | |
109 s << "<li class='#{classes}'><div class='#{classes}'>" + | |
110 link_to_project(project, {}, :class => "project my-project") | |
111 if project.is_public? | |
112 s << " <span class='public'>" << l("field_is_public") << "</span>" | |
113 else | |
114 s << " <span class='private'>" << l("field_is_private") << "</span>" | |
115 end | |
116 s << render_project_short_description(project) | |
117 s << "</div>\n" | |
118 | |
119 cs = '' | |
120 project.children.each do |child| | |
121 cs << render_my_project_in_hierarchy(child) | |
122 end | |
123 | |
124 if cs != '' | |
125 s << "<ul class='projects'>\n" << cs << "</ul>\n"; | |
126 end | |
127 | |
128 end | |
129 | |
130 s | |
131 | |
132 end | |
133 | |
98 # Renders a tree of projects where the current user belongs | 134 # Renders a tree of projects where the current user belongs |
99 # as a nested set of unordered lists | 135 # as a nested set of unordered lists |
100 # The given collection may be a subset of the whole project tree | 136 # The given collection may be a subset of the whole project tree |
101 # (eg. some intermediate nodes are private and can not be seen) | 137 # (eg. some intermediate nodes are private and can not be seen) |
102 def render_my_project_hierarchy(projects) | 138 def render_my_project_hierarchy(projects) |
103 s = '' | 139 |
104 | 140 s = '' |
105 a = '' | 141 |
106 | 142 original_project = @project |
107 # Flag to tell if user has any projects | 143 |
108 t = FALSE | 144 projects.each do |project| |
109 | 145 if project.root? || !projects.include?(project.parent) |
110 if projects.any? | 146 s << render_my_project_in_hierarchy(project) |
111 ancestors = [] | 147 end |
112 original_project = @project | 148 end |
113 projects.each do |project| | 149 |
114 # set the project environment to please macros. | 150 @project = original_project |
115 | 151 |
116 @project = project | 152 if s != '' |
117 | 153 a = '' |
118 if User.current.member_of?(project): | |
119 | |
120 t = TRUE | |
121 | |
122 if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) | |
123 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" | |
124 else | |
125 ancestors.pop | |
126 s << "</li>" | |
127 while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) | |
128 ancestors.pop | |
129 s << "</ul></li>\n" | |
130 end | |
131 end | |
132 | |
133 classes = (ancestors.empty? ? 'root' : 'child') | |
134 s << "<li class='#{classes}'><div class='#{classes}'>" + | |
135 link_to_project(project, {}, :class => "project my-project") | |
136 if project.is_public? | |
137 s << " <span class='public'>" << l("field_is_public") << "</span>" | |
138 else | |
139 s << " <span class='private'>" << l("field_is_private") << "</span>" | |
140 end | |
141 s << render_project_short_description(project) | |
142 s << "</div>\n" | |
143 ancestors << project | |
144 end | |
145 end | |
146 s << ("</li></ul>\n" * ancestors.size) | |
147 @project = original_project | |
148 end | |
149 | |
150 if t == TRUE | |
151 a << "<h2>" | 154 a << "<h2>" |
152 a << l("label_my_project_plural") | 155 a << l("label_my_project_plural") |
153 a << "</h2>" | 156 a << "</h2>" |
157 a << "<ul class='projects root'>\n" | |
154 a << s | 158 a << s |
155 else | 159 a << "</ul>\n" |
156 a = s | 160 s = a |
157 end | 161 end |
158 | 162 |
159 a | 163 s |
164 | |
160 end | 165 end |
161 | 166 |
162 # Renders a tree of projects that the current user does not belong | 167 # Renders a tree of projects that the current user does not belong |
163 # to, or of all projects if the current user is not logged in. The | 168 # to, or of all projects if the current user is not logged in. The |
164 # given collection may be a subset of the whole project tree | 169 # given collection may be a subset of the whole project tree |