annotate .svn/pristine/95/95bdf08986ed3dae85595182bbe89d47e7f91bb1.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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