annotate app/helpers/projects_helper.rb @ 861:b8105f717bf7 bug_182

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