Chris@0: # redMine - project management software
Chris@0: # Copyright (C) 2006 Jean-Philippe Lang
Chris@0: #
Chris@0: # This program is free software; you can redistribute it and/or
Chris@0: # modify it under the terms of the GNU General Public License
Chris@0: # as published by the Free Software Foundation; either version 2
Chris@0: # of the License, or (at your option) any later version.
Chris@0: #
Chris@0: # This program is distributed in the hope that it will be useful,
Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0: # GNU General Public License for more details.
Chris@0: #
Chris@0: # You should have received a copy of the GNU General Public License
Chris@0: # along with this program; if not, write to the Free Software
Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0:
Chris@0: module ProjectsHelper
Chris@0: def link_to_version(version, options = {})
Chris@0: return '' unless version && version.is_a?(Version)
Chris@0: link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
Chris@0: end
Chris@0:
Chris@0: def project_settings_tabs
Chris@0: tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
Chris@0: {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
Chris@0: {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
Chris@0: {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
Chris@0: {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
Chris@0: {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
Chris@0: {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
Chris@0: {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
Chris@0: {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
Chris@0: ]
Chris@0: tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
Chris@0: end
Chris@0:
Chris@0: def parent_project_select_tag(project)
Chris@0: selected = project.parent
Chris@0: # retrieve the requested parent project
Chris@0: parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
Chris@0: if parent_id
Chris@0: selected = (parent_id.blank? ? nil : Project.find(parent_id))
Chris@0: end
Chris@0:
Chris@0: options = ''
Chris@0: options << "" if project.allowed_parents.include?(nil)
Chris@0: options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
Chris@0: content_tag('select', options, :name => 'project[parent_id]', :id => 'project_parent_id')
Chris@0: end
Chris@0:
Chris@0: # Renders a tree of projects as a nested set of unordered lists
Chris@0: # The given collection may be a subset of the whole project tree
Chris@0: # (eg. some intermediate nodes are private and can not be seen)
Chris@0: def render_project_hierarchy(projects)
Chris@0: s = ''
Chris@0: if projects.any?
Chris@0: ancestors = []
Chris@0: original_project = @project
Chris@0: projects.each do |project|
Chris@0: # set the project environment to please macros.
Chris@0: @project = project
Chris@0: if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
Chris@0: s << "
\n"
Chris@0: else
Chris@0: ancestors.pop
Chris@0: s << ""
Chris@0: while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
Chris@0: ancestors.pop
Chris@0: s << "
\n"
Chris@0: end
Chris@0: end
Chris@0: classes = (ancestors.empty? ? 'root' : 'child')
Chris@0: s << "
" unless project.description.blank?
Chris@0: s << "
\n"
Chris@0: ancestors << project
Chris@0: end
Chris@0: s << ("
\n" * ancestors.size)
Chris@0: @project = original_project
Chris@0: end
Chris@0: s
Chris@0: end
Chris@0:
luisf@68:
luisf@68: # Renders a tree of projects where the current user belongs
luisf@68: # as a nested set of unordered lists
luisf@68: # The given collection may be a subset of the whole project tree
luisf@68: # (eg. some intermediate nodes are private and can not be seen)
luisf@68: def render_my_project_hierarchy(projects)
luisf@68: s = ''
luisf@69:
luisf@69: a = ''
luisf@69:
luisf@69: # Flag to tell if user has any projects
luisf@69: t = FALSE
luisf@68:
luisf@68: if projects.any?
luisf@68: ancestors = []
luisf@68: original_project = @project
luisf@68: projects.each do |project|
luisf@68: # set the project environment to please macros.
luisf@68:
luisf@68: @project = project
luisf@68:
luisf@68: if User.current.member_of?(project):
luisf@68:
luisf@69: t = TRUE
luisf@69:
luisf@68: if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
luisf@68: s << "
\n"
luisf@68: else
luisf@68: ancestors.pop
luisf@68: s << ""
luisf@68: while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
luisf@68: ancestors.pop
luisf@68: s << "
\n"
luisf@68: end
luisf@68: end
luisf@68:
luisf@68: classes = (ancestors.empty? ? 'root' : 'child')
luisf@68: s << "
" unless project.description.blank?
luisf@68: s << "
\n"
luisf@68: ancestors << project
luisf@68: end
luisf@68: end
luisf@68: s << ("
\n" * ancestors.size)
luisf@68: @project = original_project
luisf@68: end
luisf@69:
luisf@69: if t == TRUE
luisf@69: a << "
"
luisf@69: a << l("label_my_project_plural")
luisf@69: a << "
"
luisf@69: a << s
luisf@69: else
luisf@69: a = s
luisf@69: end
luisf@69:
luisf@69: a
luisf@68: end
luisf@68:
luisf@68: # Renders a tree of projects where the current DOES NOT belong
luisf@68: # as a nested set of unordered lists
luisf@68: # The given collection may be a subset of the whole project tree
luisf@68: # (eg. some intermediate nodes are private and can not be seen)
luisf@68: def render_other_project_hierarchy(projects)
Chris@100: a = ''
luisf@68: s = ''
luisf@68:
Chris@100: # True if user has any projects (affects the heading used)
Chris@100: t = FALSE
Chris@100:
luisf@68: if projects.any?
luisf@68: ancestors = []
luisf@68: original_project = @project
luisf@68: projects.each do |project|
luisf@68: # set the project environment to please macros.
luisf@68:
luisf@68: @project = project
luisf@68:
luisf@68: if not User.current.member_of?(project):
luisf@68:
luisf@68: if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
luisf@68: s << "
\n"
luisf@68: else
luisf@68: ancestors.pop
luisf@68: s << ""
luisf@68: while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
luisf@68: ancestors.pop
luisf@68: s << "
\n"
luisf@68: end
luisf@68: end
luisf@68:
luisf@68: classes = (ancestors.empty? ? 'root' : 'child')
luisf@68: s << "
" unless project.description.blank?
luisf@68: s << "
\n"
luisf@68: ancestors << project
Chris@100: else
Chris@100: t = TRUE
luisf@68: end
luisf@68: end
luisf@68:
luisf@68: s << ("
\n" * ancestors.size)
luisf@68: @project = original_project
luisf@68: end
luisf@69:
Chris@100: if t == TRUE
Chris@100: a << "
"
Chris@100: a << l("label_other_project_plural")
Chris@100: a << "
"
Chris@100: a << s
Chris@100: else
Chris@100: a << "
"
Chris@100: a << l("label_project_all")
Chris@100: a << "
"
Chris@100: a << s
Chris@100: end
luisf@69:
Chris@100: a
luisf@68: end
luisf@68:
luisf@68:
luisf@68:
Chris@0: # Returns a set of options for a select field, grouped by project.
Chris@0: def version_options_for_select(versions, selected=nil)
Chris@0: grouped = Hash.new {|h,k| h[k] = []}
Chris@0: versions.each do |version|
Chris@0: grouped[version.project.name] << [version.name, version.id]
Chris@0: end
Chris@0: # Add in the selected
Chris@0: if selected && !versions.include?(selected)
Chris@0: grouped[selected.project.name] << [selected.name, selected.id]
Chris@0: end
Chris@0:
Chris@0: if grouped.keys.size > 1
Chris@0: grouped_options_for_select(grouped, selected && selected.id)
Chris@0: else
Chris@0: options_for_select((grouped.values.first || []), selected && selected.id)
Chris@0: end
Chris@0: end
Chris@0:
Chris@0: def format_version_sharing(sharing)
Chris@0: sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
Chris@0: l("label_version_sharing_#{sharing}")
Chris@0: end
Chris@0: end