To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / projects_helper.rb @ 995:f9a882232e2d
History | View | Annotate | Download (9.2 KB)
| 1 | 909:cbb26bc654de | Chris | # encoding: utf-8
|
|---|---|---|---|
| 2 | #
|
||
| 3 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
| 4 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 5 | 0:513646585e45 | Chris | #
|
| 6 | # This program is free software; you can redistribute it and/or
|
||
| 7 | # modify it under the terms of the GNU General Public License
|
||
| 8 | # as published by the Free Software Foundation; either version 2
|
||
| 9 | # of the License, or (at your option) any later version.
|
||
| 10 | 441:cbce1fd3b1b7 | Chris | #
|
| 11 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 14 | # GNU General Public License for more details.
|
||
| 15 | 441:cbce1fd3b1b7 | Chris | #
|
| 16 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 17 | # along with this program; if not, write to the Free Software
|
||
| 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 19 | |||
| 20 | module ProjectsHelper |
||
| 21 | def link_to_version(version, options = {}) |
||
| 22 | return '' unless version && version.is_a?(Version) |
||
| 23 | link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
|
||
| 24 | end
|
||
| 25 | 441:cbce1fd3b1b7 | Chris | |
| 26 | 0:513646585e45 | Chris | def project_settings_tabs |
| 27 | tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
|
||
| 28 | 354:8c804ce943db | chris | {:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page},
|
| 29 | 0:513646585e45 | Chris | {: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},
|
||
| 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},
|
||
| 33 | {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
|
||
| 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}
|
||
| 36 | ] |
||
| 37 | 441:cbce1fd3b1b7 | Chris | tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
| 38 | 0:513646585e45 | Chris | end
|
| 39 | 441:cbce1fd3b1b7 | Chris | |
| 40 | 0:513646585e45 | Chris | def parent_project_select_tag(project) |
| 41 | selected = project.parent |
||
| 42 | # retrieve the requested parent project
|
||
| 43 | parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id] |
||
| 44 | if parent_id
|
||
| 45 | selected = (parent_id.blank? ? nil : Project.find(parent_id)) |
||
| 46 | end
|
||
| 47 | 441:cbce1fd3b1b7 | Chris | |
| 48 | 0:513646585e45 | Chris | options = ''
|
| 49 | options << "<option value=''></option>" if project.allowed_parents.include?(nil) |
||
| 50 | options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
|
||
| 51 | 909:cbb26bc654de | Chris | content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') |
| 52 | 0:513646585e45 | Chris | end
|
| 53 | 441:cbce1fd3b1b7 | Chris | |
| 54 | 335:7acd282bee3c | chris | def render_project_short_description(project) |
| 55 | s = ''
|
||
| 56 | if (project.short_description)
|
||
| 57 | s << "<div class='description'>"
|
||
| 58 | s << textilizable(project.short_description, :project => project).gsub(/<[^>]+>/, '') |
||
| 59 | s << "</div>"
|
||
| 60 | end
|
||
| 61 | s |
||
| 62 | end
|
||
| 63 | 14:1d32c0a0efbf | Chris | |
| 64 | 0:513646585e45 | Chris | # 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
|
||
| 66 | # (eg. some intermediate nodes are private and can not be seen)
|
||
| 67 | def render_project_hierarchy(projects) |
||
| 68 | s = ''
|
||
| 69 | if projects.any?
|
||
| 70 | ancestors = [] |
||
| 71 | original_project = @project
|
||
| 72 | projects.each do |project|
|
||
| 73 | # set the project environment to please macros.
|
||
| 74 | @project = project
|
||
| 75 | if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
|
||
| 76 | s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
|
||
| 77 | else
|
||
| 78 | ancestors.pop |
||
| 79 | s << "</li>"
|
||
| 80 | 441:cbce1fd3b1b7 | Chris | while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
| 81 | 0:513646585e45 | Chris | ancestors.pop |
| 82 | s << "</ul></li>\n"
|
||
| 83 | end
|
||
| 84 | end
|
||
| 85 | classes = (ancestors.empty? ? 'root' : 'child') |
||
| 86 | s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||
| 87 | 14:1d32c0a0efbf | Chris | link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
| 88 | 335:7acd282bee3c | chris | s << render_project_short_description(project) |
| 89 | 0:513646585e45 | Chris | s << "</div>\n"
|
| 90 | ancestors << project |
||
| 91 | end
|
||
| 92 | s << ("</li></ul>\n" * ancestors.size)
|
||
| 93 | @project = original_project
|
||
| 94 | end
|
||
| 95 | 909:cbb26bc654de | Chris | s.html_safe |
| 96 | 0:513646585e45 | Chris | end
|
| 97 | |||
| 98 | 68:60c0a4e08e09 | luisf | |
| 99 | 420:2008fa7fda29 | chris | def render_my_project_in_hierarchy(project) |
| 100 | |||
| 101 | s = ''
|
||
| 102 | |||
| 103 | if User.current.member_of?(project) |
||
| 104 | |||
| 105 | # set the project environment to please macros.
|
||
| 106 | @project = project
|
||
| 107 | |||
| 108 | classes = (project.root? ? 'root' : 'child') |
||
| 109 | |||
| 110 | s << "<li class='#{classes}'><div class='#{classes}'>" +
|
||
| 111 | link_to_project(project, {}, :class => "project my-project")
|
||
| 112 | if project.is_public?
|
||
| 113 | 939:1affbc7f4b30 | chris | s << " <span class='public'>" << l(:field_is_public) << "</span>" |
| 114 | 420:2008fa7fda29 | chris | else
|
| 115 | 939:1affbc7f4b30 | chris | s << " <span class='private'>" << l(:field_is_private) << "</span>" |
| 116 | 420:2008fa7fda29 | chris | end
|
| 117 | s << render_project_short_description(project) |
||
| 118 | s << "</div>\n"
|
||
| 119 | |||
| 120 | cs = ''
|
||
| 121 | project.children.each do |child|
|
||
| 122 | cs << render_my_project_in_hierarchy(child) |
||
| 123 | end
|
||
| 124 | |||
| 125 | if cs != '' |
||
| 126 | s << "<ul class='projects'>\n" << cs << "</ul>\n"; |
||
| 127 | end
|
||
| 128 | |||
| 129 | end
|
||
| 130 | |||
| 131 | s |
||
| 132 | |||
| 133 | end
|
||
| 134 | |||
| 135 | 68:60c0a4e08e09 | luisf | # Renders a tree of projects where the current user belongs
|
| 136 | # as a nested set of unordered lists
|
||
| 137 | # The given collection may be a subset of the whole project tree
|
||
| 138 | # (eg. some intermediate nodes are private and can not be seen)
|
||
| 139 | def render_my_project_hierarchy(projects) |
||
| 140 | 420:2008fa7fda29 | chris | |
| 141 | 68:60c0a4e08e09 | luisf | s = ''
|
| 142 | 69:dc22c3eb3c81 | luisf | |
| 143 | 420:2008fa7fda29 | chris | original_project = @project
|
| 144 | 69:dc22c3eb3c81 | luisf | |
| 145 | 420:2008fa7fda29 | chris | projects.each do |project|
|
| 146 | if project.root? || !projects.include?(project.parent)
|
||
| 147 | s << render_my_project_in_hierarchy(project) |
||
| 148 | end
|
||
| 149 | 68:60c0a4e08e09 | luisf | end
|
| 150 | 69:dc22c3eb3c81 | luisf | |
| 151 | 420:2008fa7fda29 | chris | @project = original_project
|
| 152 | |||
| 153 | if s != '' |
||
| 154 | a = ''
|
||
| 155 | a << "<ul class='projects root'>\n"
|
||
| 156 | 69:dc22c3eb3c81 | luisf | a << s |
| 157 | 420:2008fa7fda29 | chris | a << "</ul>\n"
|
| 158 | s = a |
||
| 159 | 69:dc22c3eb3c81 | luisf | end
|
| 160 | 420:2008fa7fda29 | chris | |
| 161 | s |
||
| 162 | 69:dc22c3eb3c81 | luisf | |
| 163 | 68:60c0a4e08e09 | luisf | end
|
| 164 | |||
| 165 | 995:f9a882232e2d | chris | # Renders a tree of projects. The given collection may be a subset
|
| 166 | # of the whole project tree (eg. some intermediate nodes are private
|
||
| 167 | # and can not be seen). We are potentially interested in various
|
||
| 168 | # things: the project name, description, manager(s), creation date,
|
||
| 169 | # last activity date, general activity level, whether there is
|
||
| 170 | # anything actually hosted here for the project, etc.
|
||
| 171 | 124:bc91f2025d05 | chris | def render_project_table(projects) |
| 172 | 68:60c0a4e08e09 | luisf | |
| 173 | 124:bc91f2025d05 | chris | s = ""
|
| 174 | s << "<div class='autoscroll'>"
|
||
| 175 | s << "<table class='list projects'>"
|
||
| 176 | s << "<thead><tr>"
|
||
| 177 | |||
| 178 | 939:1affbc7f4b30 | chris | s << sort_header_tag('name', :caption => l(:field_name)) |
| 179 | s << "<th class='managers'>" << l(:label_managers) << "</th>" |
||
| 180 | 124:bc91f2025d05 | chris | s << sort_header_tag('created_on', :default_order => 'desc') |
| 181 | s << sort_header_tag('updated_on', :default_order => 'desc') |
||
| 182 | 100:1412841d48a3 | Chris | |
| 183 | 124:bc91f2025d05 | chris | s << "</tr></thead><tbody>"
|
| 184 | 68:60c0a4e08e09 | luisf | |
| 185 | 124:bc91f2025d05 | chris | original_project = @project
|
| 186 | 68:60c0a4e08e09 | luisf | |
| 187 | 124:bc91f2025d05 | chris | projects.each do |project|
|
| 188 | 205:05f9a2a9c753 | chris | s << render_project_in_table(project, cycle('odd', 'even'), 0) |
| 189 | 68:60c0a4e08e09 | luisf | end
|
| 190 | 69:dc22c3eb3c81 | luisf | |
| 191 | 124:bc91f2025d05 | chris | s << "</table>"
|
| 192 | 69:dc22c3eb3c81 | luisf | |
| 193 | 124:bc91f2025d05 | chris | @project = original_project
|
| 194 | |||
| 195 | s |
||
| 196 | 68:60c0a4e08e09 | luisf | end
|
| 197 | |||
| 198 | |||
| 199 | 205:05f9a2a9c753 | chris | def render_project_in_table(project, oddeven, level) |
| 200 | |||
| 201 | # set the project environment to please macros.
|
||
| 202 | @project = project
|
||
| 203 | |||
| 204 | classes = (level == 0 ? 'root' : 'child') |
||
| 205 | |||
| 206 | s = ""
|
||
| 207 | |||
| 208 | s << "<tr class='#{oddeven} #{classes} level#{level}'>"
|
||
| 209 | s << "<td class='firstcol' align=top><div class='name hosted_here"
|
||
| 210 | s << " no_description" if project.description.blank? |
||
| 211 | s << "'>" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}"); |
||
| 212 | s << "</div>"
|
||
| 213 | 335:7acd282bee3c | chris | s << render_project_short_description(project) |
| 214 | 205:05f9a2a9c753 | chris | |
| 215 | s << "<td class='managers' align=top>"
|
||
| 216 | |||
| 217 | u = project.users_by_role |
||
| 218 | if u
|
||
| 219 | u.keys.each do |r|
|
||
| 220 | if r.allowed_to?(:edit_project) |
||
| 221 | mgrs = [] |
||
| 222 | u[r].sort.each do |m|
|
||
| 223 | mgrs << link_to_user(m) |
||
| 224 | end
|
||
| 225 | if mgrs.size < 3 |
||
| 226 | s << '<nobr>' << mgrs.join(', ') << '</nobr>' |
||
| 227 | else
|
||
| 228 | s << mgrs.join(', ')
|
||
| 229 | end
|
||
| 230 | end
|
||
| 231 | end
|
||
| 232 | end
|
||
| 233 | |||
| 234 | s << "</td>"
|
||
| 235 | s << "<td class='created_on' align=top>" << format_date(project.created_on) << "</td>" |
||
| 236 | s << "<td class='updated_on' align=top>" << format_date(project.updated_on) << "</td>" |
||
| 237 | |||
| 238 | s << "</tr>"
|
||
| 239 | |||
| 240 | project.children.each do |child|
|
||
| 241 | 414:576a1dca2ee2 | chris | if child.is_public? or User.current.member_of?(child) |
| 242 | s << render_project_in_table(child, oddeven, level + 1)
|
||
| 243 | end
|
||
| 244 | 205:05f9a2a9c753 | chris | end
|
| 245 | |||
| 246 | s |
||
| 247 | end
|
||
| 248 | |||
| 249 | 68:60c0a4e08e09 | luisf | |
| 250 | 0:513646585e45 | Chris | # Returns a set of options for a select field, grouped by project.
|
| 251 | def version_options_for_select(versions, selected=nil) |
||
| 252 | grouped = Hash.new {|h,k| h[k] = []}
|
||
| 253 | versions.each do |version|
|
||
| 254 | grouped[version.project.name] << [version.name, version.id] |
||
| 255 | end
|
||
| 256 | # Add in the selected
|
||
| 257 | if selected && !versions.include?(selected)
|
||
| 258 | grouped[selected.project.name] << [selected.name, selected.id] |
||
| 259 | end
|
||
| 260 | 441:cbce1fd3b1b7 | Chris | |
| 261 | 0:513646585e45 | Chris | if grouped.keys.size > 1 |
| 262 | grouped_options_for_select(grouped, selected && selected.id) |
||
| 263 | else
|
||
| 264 | options_for_select((grouped.values.first || []), selected && selected.id) |
||
| 265 | end
|
||
| 266 | end
|
||
| 267 | |||
| 268 | def format_version_sharing(sharing) |
||
| 269 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
||
| 270 | l("label_version_sharing_#{sharing}")
|
||
| 271 | end
|
||
| 272 | end |