annotate app/helpers/projects_helper.rb @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents 433d4f72a19b
children bb32da3bea34 622f24f53b42 261b3d9a4903
rev   line source
Chris@909 1 # encoding: utf-8
Chris@909 2 #
Chris@441 3 # Redmine - project management software
Chris@1115 4 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@0 5 #
Chris@0 6 # This program is free software; you can redistribute it and/or
Chris@0 7 # modify it under the terms of the GNU General Public License
Chris@0 8 # as published by the Free Software Foundation; either version 2
Chris@0 9 # of the License, or (at your option) any later version.
Chris@441 10 #
Chris@0 11 # This program is distributed in the hope that it will be useful,
Chris@0 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 14 # GNU General Public License for more details.
Chris@441 15 #
Chris@0 16 # You should have received a copy of the GNU General Public License
Chris@0 17 # along with this program; if not, write to the Free Software
Chris@0 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 19
Chris@0 20 module ProjectsHelper
Chris@0 21 def link_to_version(version, options = {})
Chris@0 22 return '' unless version && version.is_a?(Version)
Chris@0 23 link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
Chris@0 24 end
Chris@441 25
Chris@0 26 def project_settings_tabs
Chris@0 27 tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
Chris@0 28 {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
Chris@0 29 {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
Chris@0 30 {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
Chris@0 31 {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
Chris@0 32 {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
Chris@1115 33 {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
Chris@0 34 {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
Chris@0 35 {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
Chris@0 36 ]
Chris@441 37 tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
Chris@0 38 end
Chris@441 39
Chris@0 40 def parent_project_select_tag(project)
Chris@0 41 selected = project.parent
Chris@0 42 # retrieve the requested parent project
Chris@0 43 parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
Chris@0 44 if parent_id
Chris@0 45 selected = (parent_id.blank? ? nil : Project.find(parent_id))
Chris@0 46 end
Chris@441 47
Chris@0 48 options = ''
Chris@0 49 options << "<option value=''></option>" if project.allowed_parents.include?(nil)
Chris@0 50 options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
Chris@909 51 content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
Chris@0 52 end
Chris@441 53
Chris@1115 54 # Renders the projects index
Chris@0 55 def render_project_hierarchy(projects)
Chris@1115 56 render_project_nested_lists(projects) do |project|
Chris@1115 57 s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'my-project' : nil}")
Chris@1115 58 if project.description.present?
Chris@1115 59 s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
Chris@0 60 end
Chris@1115 61 s
Chris@0 62 end
Chris@0 63 end
Chris@0 64
Chris@0 65 # Returns a set of options for a select field, grouped by project.
Chris@0 66 def version_options_for_select(versions, selected=nil)
Chris@0 67 grouped = Hash.new {|h,k| h[k] = []}
Chris@0 68 versions.each do |version|
Chris@0 69 grouped[version.project.name] << [version.name, version.id]
Chris@0 70 end
Chris@441 71
Chris@0 72 if grouped.keys.size > 1
Chris@0 73 grouped_options_for_select(grouped, selected && selected.id)
Chris@0 74 else
Chris@0 75 options_for_select((grouped.values.first || []), selected && selected.id)
Chris@0 76 end
Chris@0 77 end
Chris@0 78
Chris@0 79 def format_version_sharing(sharing)
Chris@0 80 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
Chris@0 81 l("label_version_sharing_#{sharing}")
Chris@0 82 end
Chris@0 83 end