Revision 421:3d2f1bea385a app/helpers
| app/helpers/projects_helper.rb | ||
|---|---|---|
| 95 | 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 | 134 |
# Renders a tree of projects where the current user belongs |
| 99 | 135 |
# as a nested set of unordered lists |
| 100 | 136 |
# The given collection may be a subset of the whole project tree |
| 101 | 137 |
# (eg. some intermediate nodes are private and can not be seen) |
| 102 | 138 |
def render_my_project_hierarchy(projects) |
| 139 |
|
|
| 103 | 140 |
s = '' |
| 104 | 141 |
|
| 105 |
a = ''
|
|
| 142 |
original_project = @project
|
|
| 106 | 143 |
|
| 107 |
# Flag to tell if user has any projects |
|
| 108 |
t = FALSE |
|
| 109 |
|
|
| 110 |
if projects.any? |
|
| 111 |
ancestors = [] |
|
| 112 |
original_project = @project |
|
| 113 |
projects.each do |project| |
|
| 114 |
# set the project environment to please macros. |
|
| 115 |
|
|
| 116 |
@project = project |
|
| 117 |
|
|
| 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 |
|
| 144 |
projects.each do |project| |
|
| 145 |
if project.root? || !projects.include?(project.parent) |
|
| 146 |
s << render_my_project_in_hierarchy(project) |
|
| 147 |
end |
|
| 148 | 148 |
end |
| 149 | 149 |
|
| 150 |
if t == TRUE |
|
| 150 |
@project = original_project |
|
| 151 |
|
|
| 152 |
if s != '' |
|
| 153 |
a = '' |
|
| 151 | 154 |
a << "<h2>" |
| 152 | 155 |
a << l("label_my_project_plural")
|
| 153 | 156 |
a << "</h2>" |
| 157 |
a << "<ul class='projects root'>\n" |
|
| 154 | 158 |
a << s |
| 155 |
else
|
|
| 156 |
a = s
|
|
| 159 |
a << "</ul>\n"
|
|
| 160 |
s = a
|
|
| 157 | 161 |
end |
| 162 |
|
|
| 163 |
s |
|
| 158 | 164 |
|
| 159 |
a |
|
| 160 | 165 |
end |
| 161 | 166 |
|
| 162 | 167 |
# Renders a tree of projects that the current user does not belong |
Also available in: Unified diff