Files
2026-03-03 13:38:43 +00:00

113 lines
3.9 KiB
Ruby

# frozen_string_literal: true
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# 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.
#
# 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.
#
# 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.
#
# See COPYRIGHT and LICENSE files for more details.
#++
module ProjectsHelper
include WorkPackagesFilterHelper
PROJECTS_QUERY_PARAM_NAMES = %i[query_id filters columns sortBy per_page page].freeze
PROJECTS_FILTER_FOR_COLUMN_MAPPING = {
"description" => nil,
"identifier" => nil,
"name" => "id",
"project_status" => "project_status_code",
"required_disk_space" => nil,
"status_explanation" => nil
}.freeze
# Just like sort_header tag but removes sorting by
# lft from the sort criteria as lft is mutually exclusive with
# the other criteria.
def projects_sort_header_tag(column, all_column_attributes, **)
former_criteria = @sort_criteria.criteria.dup
@sort_criteria.criteria.reject! { |a, _| a == "lft" }
filter_column_mapping = PROJECTS_FILTER_FOR_COLUMN_MAPPING
if column.is_a?(::Queries::Projects::Selects::CustomComment)
filter_column_mapping = filter_column_mapping.merge(column.attribute.to_s => nil)
end
sort_header_with_action_menu(column, all_column_attributes, filter_column_mapping, **,
allowed_params: projects_query_param_names_for_sort)
ensure
@sort_criteria.criteria = former_criteria
end
def short_project_description(project, length = 255)
if project.description.blank?
return ""
end
project.description.gsub(/\A(.{#{length}}[^\n\r]*).*\z/m, '\1...').strip
end
def projects_columns_options
@projects_columns_options ||= ::ProjectQuery
.new
.available_selects
.reject { |c| c.attribute == :hierarchy }
.sort_by(&:caption)
.map { |c| { id: c.attribute, name: c.caption } }
end
def selected_projects_columns_options
Setting
.enabled_projects_columns
.filter_map { |c| projects_columns_options.find { |o| o[:id].to_s == c } }
end
def protected_projects_columns_options
projects_columns_options
.select { |c| c[:id] == :name }
end
def projects_query_param_names_for_sort = PROJECTS_QUERY_PARAM_NAMES - %i[sortBy page]
def projects_query_params
safe_query_params(PROJECTS_QUERY_PARAM_NAMES)
end
def supported_export_formats
::Exports::Register.list_formats(Project).map(&:to_s)
end
def project_creation_wizard_name(project)
I18n.t(project.project_creation_wizard_artifact_name,
default: :project_initiation_request,
scope: "settings.project_initiation_request.name.options")
end
def portfolio_management_feature_required? = params[:workspace_type].in?(%w[portfolio program])
def portfolio_management_feature_missing?
portfolio_management_feature_required? && !EnterpriseToken.allows_to?(:portfolio_management)
end
end