You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

projects_helper.rb 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2011 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. module ProjectsHelper
  18. def link_to_version(version, options = {})
  19. return '' unless version && version.is_a?(Version)
  20. link_to_if version.visible?, format_version_name(version), { :controller => 'versions', :action => 'show', :id => version }, options
  21. end
  22. def project_settings_tabs
  23. tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_information_plural},
  24. {:name => 'modules', :action => :select_project_modules, :partial => 'projects/settings/modules', :label => :label_module_plural},
  25. {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
  26. {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural},
  27. {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
  28. {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
  29. {:name => 'repository', :action => :manage_repository, :partial => 'projects/settings/repository', :label => :label_repository},
  30. {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
  31. {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
  32. ]
  33. tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
  34. end
  35. def parent_project_select_tag(project)
  36. selected = project.parent
  37. # retrieve the requested parent project
  38. parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
  39. if parent_id
  40. selected = (parent_id.blank? ? nil : Project.find(parent_id))
  41. end
  42. options = ''
  43. options << "<option value=''></option>" if project.allowed_parents.include?(nil)
  44. options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
  45. content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
  46. end
  47. # Renders a tree of projects as a nested set of unordered lists
  48. # The given collection may be a subset of the whole project tree
  49. # (eg. some intermediate nodes are private and can not be seen)
  50. def render_project_hierarchy(projects)
  51. s = ''
  52. if projects.any?
  53. ancestors = []
  54. original_project = @project
  55. projects.each do |project|
  56. # set the project environment to please macros.
  57. @project = project
  58. if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
  59. s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
  60. else
  61. ancestors.pop
  62. s << "</li>"
  63. while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
  64. ancestors.pop
  65. s << "</ul></li>\n"
  66. end
  67. end
  68. classes = (ancestors.empty? ? 'root' : 'child')
  69. s << "<li class='#{classes}'><div class='#{classes}'>" +
  70. link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}")
  71. s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank?
  72. s << "</div>\n"
  73. ancestors << project
  74. end
  75. s << ("</li></ul>\n" * ancestors.size)
  76. @project = original_project
  77. end
  78. s.html_safe
  79. end
  80. # Returns a set of options for a select field, grouped by project.
  81. def version_options_for_select(versions, selected=nil)
  82. grouped = Hash.new {|h,k| h[k] = []}
  83. versions.each do |version|
  84. grouped[version.project.name] << [version.name, version.id]
  85. end
  86. # Add in the selected
  87. if selected && !versions.include?(selected)
  88. grouped[selected.project.name] << [selected.name, selected.id]
  89. end
  90. if grouped.keys.size > 1
  91. grouped_options_for_select(grouped, selected && selected.id)
  92. else
  93. options_for_select((grouped.values.first || []), selected && selected.id)
  94. end
  95. end
  96. def format_version_sharing(sharing)
  97. sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
  98. l("label_version_sharing_#{sharing}")
  99. end
  100. end