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 @ 1022:f2ec92061fca
History | View | Annotate | Download (9.2 KB)
| 1 |
# encoding: utf-8
|
|---|---|
| 2 |
#
|
| 3 |
# Redmine - project management software
|
| 4 |
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 5 |
#
|
| 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 |
#
|
| 11 |
# 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 |
#
|
| 16 |
# 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 |
|
| 26 |
def project_settings_tabs |
| 27 |
tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
|
| 28 |
{:name => 'overview', :action => :edit_project, :partial => 'projects/settings/overview', :label => :label_welcome_page},
|
| 29 |
{: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 |
tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
|
| 38 |
end
|
| 39 |
|
| 40 |
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 |
|
| 48 |
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 |
content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id') |
| 52 |
end
|
| 53 |
|
| 54 |
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 |
|
| 64 |
# 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 |
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
| 81 |
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 |
link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
|
| 88 |
s << render_project_short_description(project) |
| 89 |
s << "</div>\n"
|
| 90 |
ancestors << project |
| 91 |
end
|
| 92 |
s << ("</li></ul>\n" * ancestors.size)
|
| 93 |
@project = original_project
|
| 94 |
end
|
| 95 |
s.html_safe |
| 96 |
end
|
| 97 |
|
| 98 |
|
| 99 |
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 |
s << " <span class='public'>" << l(:field_is_public) << "</span>" |
| 114 |
else
|
| 115 |
s << " <span class='private'>" << l(:field_is_private) << "</span>" |
| 116 |
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 |
# 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 |
|
| 141 |
s = ''
|
| 142 |
|
| 143 |
original_project = @project
|
| 144 |
|
| 145 |
projects.each do |project|
|
| 146 |
if project.root? || !projects.include?(project.parent)
|
| 147 |
s << render_my_project_in_hierarchy(project) |
| 148 |
end
|
| 149 |
end
|
| 150 |
|
| 151 |
@project = original_project
|
| 152 |
|
| 153 |
if s != '' |
| 154 |
a = ''
|
| 155 |
a << "<ul class='projects root'>\n"
|
| 156 |
a << s |
| 157 |
a << "</ul>\n"
|
| 158 |
s = a |
| 159 |
end
|
| 160 |
|
| 161 |
s |
| 162 |
|
| 163 |
end
|
| 164 |
|
| 165 |
# 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 |
def render_project_table(projects) |
| 172 |
|
| 173 |
s = ""
|
| 174 |
s << "<div class='autoscroll'>"
|
| 175 |
s << "<table class='list projects'>"
|
| 176 |
s << "<thead><tr>"
|
| 177 |
|
| 178 |
s << sort_header_tag('name', :caption => l(:field_name)) |
| 179 |
s << "<th class='managers'>" << l(:label_managers) << "</th>" |
| 180 |
s << sort_header_tag('created_on', :default_order => 'desc') |
| 181 |
s << sort_header_tag('updated_on', :default_order => 'desc') |
| 182 |
|
| 183 |
s << "</tr></thead><tbody>"
|
| 184 |
|
| 185 |
original_project = @project
|
| 186 |
|
| 187 |
projects.each do |project|
|
| 188 |
s << render_project_in_table(project, cycle('odd', 'even'), 0) |
| 189 |
end
|
| 190 |
|
| 191 |
s << "</table>"
|
| 192 |
|
| 193 |
@project = original_project
|
| 194 |
|
| 195 |
s |
| 196 |
end
|
| 197 |
|
| 198 |
|
| 199 |
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 |
s << render_project_short_description(project) |
| 214 |
|
| 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 |
if child.is_public? or User.current.member_of?(child) |
| 242 |
s << render_project_in_table(child, oddeven, level + 1)
|
| 243 |
end
|
| 244 |
end
|
| 245 |
|
| 246 |
s |
| 247 |
end
|
| 248 |
|
| 249 |
|
| 250 |
# 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 |
|
| 261 |
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
|