projects_helper.rb 4.1 KB
Newer Older
1 2
# encoding: utf-8
#
3
# Redmine - project management software
marutosijp's avatar
marutosijp committed
4
# Copyright (C) 2006-2014  Jean-Philippe Lang
5 6 7 8 9
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
10
#
11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
15
#
16 17 18 19 20
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

module ProjectsHelper
21 22
  def link_to_version(version, options = {})
    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

jplang's avatar
jplang committed
26 27 28 29 30 31 32
  def project_settings_tabs
    tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
            {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
            {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
            {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
            {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
            {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
jplang's avatar
jplang committed
33
            {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
34 35
            {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
            {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
jplang's avatar
jplang committed
36
            ]
37
    tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
jplang's avatar
jplang committed
38
  end
39

40
  def parent_project_select_tag(project)
41 42 43 44 45 46
    selected = project.parent
    # retrieve the requested parent project
    parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
    if parent_id
      selected = (parent_id.blank? ? nil : Project.find(parent_id))
    end
47

48
    options = ''
49
    options << "<option value=''>&nbsp;</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
  # Renders the projects index
55
  def render_project_hierarchy(projects)
56 57 58 59
    render_project_nested_lists(projects) do |project|
      s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
      if project.description.present?
        s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
60
      end
61
      s
62 63
    end
  end
64 65 66 67 68

  # Returns a set of options for a select field, grouped by project.
  def version_options_for_select(versions, selected=nil)
    grouped = Hash.new {|h,k| h[k] = []}
    versions.each do |version|
69
      grouped[version.project.name] << [version.name, version.id]
70
    end
71

72
    selected = selected.is_a?(Version) ? selected.id : selected
73
    if grouped.keys.size > 1
74
      grouped_options_for_select(grouped, selected)
75
    else
76
      options_for_select((grouped.values.first || []), selected)
77 78 79 80 81 82 83
    end
  end

  def format_version_sharing(sharing)
    sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
    l("label_version_sharing_#{sharing}")
  end
jplang's avatar
jplang committed
84
end