annotate app/helpers/projects_helper.rb @ 893:a2450090c0f4 feature_64

Close obsolete branch feature_64
author Chris Cannam
date Tue, 08 Feb 2011 12:30:26 +0000
parents 1412841d48a3
children bc91f2025d05
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@0 26 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
Chris@0 27 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
Chris@0 28 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
Chris@0 29 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
Chris@0 30 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
Chris@0 31 {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
Chris@0 32 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
Chris@0 33 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
Chris@0 34 ]
Chris@0 35 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
Chris@0 36 end
Chris@0 37
Chris@0 38 def parent_project_select_tag(project)
Chris@0 39 selected = project.parent
Chris@0 40 # retrieve the requested parent project
Chris@0 41 parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
Chris@0 42 if parent_id
Chris@0 43 selected = (parent_id.blank? ? nil : Project.find(parent_id))
Chris@0 44 end
Chris@0 45
Chris@0 46 options = ''
Chris@0 47 options << "<option value=''></option>" if project.allowed_parents.include?(nil)
Chris@0 48 options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
Chris@0 49 content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
Chris@0 50 end
Chris@0 51
Chris@0 52 # Renders a tree of projects as a nested set of unordered lists
Chris@0 53 # The given collection may be a subset of the whole project tree
Chris@0 54 # (eg. some intermediate nodes are private and can not be seen)
Chris@0 55 def render_project_hierarchy(projects)
Chris@0 56 s = ''
Chris@0 57 if projects.any?
Chris@0 58 ancestors = []
Chris@0 59 original_project = @project
Chris@0 60 projects.each do |project|
Chris@0 61 # set the project environment to please macros.
Chris@0 62 @project = project
Chris@0 63 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
Chris@0 64 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
Chris@0 65 else
Chris@0 66 ancestors.pop
Chris@0 67 s << "</li>"
Chris@0 68 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
Chris@0 69 ancestors.pop
Chris@0 70 s << "</ul></li>\n"
Chris@0 71 end
Chris@0 72 end
Chris@0 73 classes = (ancestors.empty? ? 'root' : 'child')
Chris@0 74 s << "<li class='#{classes}'><div class='#{classes}'>" +
Chris@14 75 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
Chris@0 76 s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
Chris@0 77 s << "</div>\n"
Chris@0 78 ancestors << project
Chris@0 79 end
Chris@0 80 s << ("</li></ul>\n" * ancestors.size)
Chris@0 81 @project = original_project
Chris@0 82 end
Chris@0 83 s
Chris@0 84 end
Chris@0 85
luisf@68 86
luisf@68 87 # Renders a tree of projects where the current user belongs
luisf@68 88 # as a nested set of unordered lists
luisf@68 89 # The given collection may be a subset of the whole project tree
luisf@68 90 # (eg. some intermediate nodes are private and can not be seen)
luisf@68 91 def render_my_project_hierarchy(projects)
luisf@68 92 s = ''
luisf@69 93
luisf@69 94 a = ''
luisf@69 95
luisf@69 96 # Flag to tell if user has any projects
luisf@69 97 t = FALSE
luisf@68 98
luisf@68 99 if projects.any?
luisf@68 100 ancestors = []
luisf@68 101 original_project = @project
luisf@68 102 projects.each do |project|
luisf@68 103 # set the project environment to please macros.
luisf@68 104
luisf@68 105 @project = project
luisf@68 106
luisf@68 107 if User.current.member_of?(project):
luisf@68 108
luisf@69 109 t = TRUE
luisf@69 110
luisf@68 111 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
luisf@68 112 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
luisf@68 113 else
luisf@68 114 ancestors.pop
luisf@68 115 s << "</li>"
luisf@68 116 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
luisf@68 117 ancestors.pop
luisf@68 118 s << "</ul></li>\n"
luisf@68 119 end
luisf@68 120 end
luisf@68 121
luisf@68 122 classes = (ancestors.empty? ? 'root' : 'child')
luisf@68 123 s << "<li class='#{classes}'><div class='#{classes}'>" +
luisf@68 124 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
luisf@68 125 s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
luisf@68 126 s << "</div>\n"
luisf@68 127 ancestors << project
luisf@68 128 end
luisf@68 129 end
luisf@68 130 s << ("</li></ul>\n" * ancestors.size)
luisf@68 131 @project = original_project
luisf@68 132 end
luisf@69 133
luisf@69 134 if t == TRUE
luisf@69 135 a << "<h2>"
luisf@69 136 a << l("label_my_project_plural")
luisf@69 137 a << "</h2>"
luisf@69 138 a << s
luisf@69 139 else
luisf@69 140 a = s
luisf@69 141 end
luisf@69 142
luisf@69 143 a
luisf@68 144 end
luisf@68 145
luisf@68 146 # Renders a tree of projects where the current DOES NOT belong
luisf@68 147 # as a nested set of unordered lists
luisf@68 148 # The given collection may be a subset of the whole project tree
luisf@68 149 # (eg. some intermediate nodes are private and can not be seen)
luisf@68 150 def render_other_project_hierarchy(projects)
Chris@100 151 a = ''
luisf@68 152 s = ''
luisf@68 153
Chris@100 154 # True if user has any projects (affects the heading used)
Chris@100 155 t = FALSE
Chris@100 156
luisf@68 157 if projects.any?
luisf@68 158 ancestors = []
luisf@68 159 original_project = @project
luisf@68 160 projects.each do |project|
luisf@68 161 # set the project environment to please macros.
luisf@68 162
luisf@68 163 @project = project
luisf@68 164
luisf@68 165 if not User.current.member_of?(project):
luisf@68 166
luisf@68 167 if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
luisf@68 168 s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
luisf@68 169 else
luisf@68 170 ancestors.pop
luisf@68 171 s << "</li>"
luisf@68 172 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
luisf@68 173 ancestors.pop
luisf@68 174 s << "</ul></li>\n"
luisf@68 175 end
luisf@68 176 end
luisf@68 177
luisf@68 178 classes = (ancestors.empty? ? 'root' : 'child')
luisf@68 179 s << "<li class='#{classes}'><div class='#{classes}'>" +
luisf@68 180 link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
luisf@68 181 s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
luisf@68 182 s << "</div>\n"
luisf@68 183 ancestors << project
Chris@100 184 else
Chris@100 185 t = TRUE
luisf@68 186 end
luisf@68 187 end
luisf@68 188
luisf@68 189 s << ("</li></ul>\n" * ancestors.size)
luisf@68 190 @project = original_project
luisf@68 191 end
luisf@69 192
Chris@100 193 if t == TRUE
Chris@100 194 a << "<h2>"
Chris@100 195 a << l("label_other_project_plural")
Chris@100 196 a << "</h2>"
Chris@100 197 a << s
Chris@100 198 else
Chris@100 199 a << "<h2>"
Chris@100 200 a << l("label_project_all")
Chris@100 201 a << "</h2>"
Chris@100 202 a << s
Chris@100 203 end
luisf@69 204
Chris@100 205 a
luisf@68 206 end
luisf@68 207
luisf@68 208
luisf@68 209
Chris@0 210 # Returns a set of options for a select field, grouped by project.
Chris@0 211 def version_options_for_select(versions, selected=nil)
Chris@0 212 grouped = Hash.new {|h,k| h[k] = []}
Chris@0 213 versions.each do |version|
Chris@0 214 grouped[version.project.name] << [version.name, version.id]
Chris@0 215 end
Chris@0 216 # Add in the selected
Chris@0 217 if selected && !versions.include?(selected)
Chris@0 218 grouped[selected.project.name] << [selected.name, selected.id]
Chris@0 219 end
Chris@0 220
Chris@0 221 if grouped.keys.size > 1
Chris@0 222 grouped_options_for_select(grouped, selected && selected.id)
Chris@0 223 else
Chris@0 224 options_for_select((grouped.values.first || []), selected && selected.id)
Chris@0 225 end
Chris@0 226 end
Chris@0 227
Chris@0 228 def format_version_sharing(sharing)
Chris@0 229 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
Chris@0 230 l("label_version_sharing_#{sharing}")
Chris@0 231 end
Chris@0 232 end