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 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. module ProjectsHelper
  19. def project_settings_tabs
  20. tabs = [{:name => 'info', :action => :edit_project, :partial => 'projects/edit', :label => :label_project},
  21. {:name => 'members', :action => :manage_members, :partial => 'projects/settings/members', :label => :label_member_plural},
  22. {:name => 'issues', :action => :edit_project, :module => :issue_tracking, :partial => 'projects/settings/issues', :label => :label_issue_tracking},
  23. {:name => 'versions', :action => :manage_versions, :partial => 'projects/settings/versions', :label => :label_version_plural,
  24. :url => {:tab => 'versions', :version_status => params[:version_status], :version_name => params[:version_name]}},
  25. {:name => 'categories', :action => :manage_categories, :partial => 'projects/settings/issue_categories', :label => :label_issue_category_plural},
  26. {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
  27. {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
  28. {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :label_time_tracking}
  29. ]
  30. tabs.
  31. select {|tab| User.current.allowed_to?(tab[:action], @project)}.
  32. select {|tab| tab[:module].nil? || @project.module_enabled?(tab[:module])}
  33. end
  34. def parent_project_select_tag(project)
  35. selected = project.parent
  36. # retrieve the requested parent project
  37. parent_id = (params[:project] && params[:project][:parent_id]) || params[:parent_id]
  38. if parent_id
  39. selected = (parent_id.blank? ? nil : Project.find(parent_id))
  40. end
  41. options = +''
  42. options << "<option value=''>&nbsp;</option>" if project.allowed_parents.include?(nil)
  43. options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
  44. content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
  45. end
  46. def render_project_action_links
  47. links = (+"").html_safe
  48. if User.current.allowed_to?(:add_project, nil, :global => true)
  49. links << link_to(l(:label_project_new), new_project_path, :class => 'icon icon-add')
  50. end
  51. links
  52. end
  53. # Renders the projects index
  54. def render_project_hierarchy(projects)
  55. render_project_nested_lists(projects) do |project|
  56. s = link_to_project(project, {}, :class => "#{project.css_classes} #{User.current.member_of?(project) ? 'icon icon-user my-project' : nil}")
  57. if project.description.present?
  58. s << content_tag('div', textilizable(project.short_description, :project => project), :class => 'wiki description')
  59. end
  60. s
  61. end
  62. end
  63. # Returns a set of options for a select field, grouped by project.
  64. def version_options_for_select(versions, selected=nil)
  65. grouped = Hash.new {|h,k| h[k] = []}
  66. versions.each do |version|
  67. grouped[version.project.name] << [version.name, version.id]
  68. end
  69. selected = selected.is_a?(Version) ? selected.id : selected
  70. if grouped.keys.size > 1
  71. grouped_options_for_select(grouped, selected)
  72. else
  73. options_for_select((grouped.values.first || []), selected)
  74. end
  75. end
  76. def project_default_version_options(project)
  77. versions = project.shared_versions.open.to_a
  78. if project.default_version && !versions.include?(project.default_version)
  79. versions << project.default_version
  80. end
  81. version_options_for_select(versions, project.default_version)
  82. end
  83. def project_default_assigned_to_options(project)
  84. assignable_users = (project.assignable_users.to_a + [project.default_assigned_to]).uniq.compact
  85. principals_options_for_select(assignable_users, project.default_assigned_to)
  86. end
  87. def format_version_sharing(sharing)
  88. sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
  89. l("label_version_sharing_#{sharing}")
  90. end
  91. def render_boards_tree(boards, parent=nil, level=0, &block)
  92. selection = boards.select {|b| b.parent == parent}
  93. return '' if selection.empty?
  94. s = ''.html_safe
  95. selection.each do |board|
  96. node = capture(board, level, &block)
  97. node << render_boards_tree(boards, board, level+1, &block)
  98. s << content_tag('div', node)
  99. end
  100. content_tag('div', s, :class => 'sort-level')
  101. end
  102. def render_api_includes(project, api)
  103. api.array :trackers do
  104. project.trackers.each do |tracker|
  105. api.tracker(:id => tracker.id, :name => tracker.name)
  106. end
  107. end if include_in_api_response?('trackers')
  108. api.array :issue_categories do
  109. project.issue_categories.each do |category|
  110. api.issue_category(:id => category.id, :name => category.name)
  111. end
  112. end if include_in_api_response?('issue_categories')
  113. api.array :time_entry_activities do
  114. project.activities.each do |activity|
  115. api.time_entry_activity(:id => activity.id, :name => activity.name)
  116. end
  117. end if include_in_api_response?('time_entry_activities')
  118. api.array :enabled_modules do
  119. project.enabled_modules.each do |enabled_module|
  120. api.enabled_module(:id => enabled_module.id, :name => enabled_module.name)
  121. end
  122. end if include_in_api_response?('enabled_modules')
  123. end
  124. def bookmark_link(project, user = User.current)
  125. return '' unless user && user.logged?
  126. @jump_box ||= Redmine::ProjectJumpBox.new user
  127. bookmarked = @jump_box.bookmark?(project)
  128. css = +"icon bookmark "
  129. if bookmarked
  130. css << "icon-bookmark"
  131. method = "delete"
  132. text = l(:button_project_bookmark_delete)
  133. else
  134. css << "icon-bookmark-off"
  135. method = "post"
  136. text = l(:button_project_bookmark)
  137. end
  138. url = bookmark_project_url(project)
  139. link_to text, url, remote: true, method: method, class: css
  140. end
  141. def grouped_project_list(projects, query, &block)
  142. ancestors = []
  143. grouped_query_results(projects, query) do |project, group_name, group_count, group_totals|
  144. ancestors.pop while ancestors.any? && !project.is_descendant_of?(ancestors.last)
  145. yield project, ancestors.size, group_name, group_count, group_totals
  146. ancestors << project unless project.leaf?
  147. end
  148. end
  149. end