Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Do not preload all values for user, project and WP filter

Klaus Zanders063041574f7c
diff --git a/modules/reporting/app/models/cost_query/filter/assigned_to_id.rb b/modules/reporting/app/models/cost_query/filter/assigned_to_id.rb
index 82ed5c6ddd6..a8def53488a 100644
--- a/modules/reporting/app/models/cost_query/filter/assigned_to_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/assigned_to_id.rb
@@ -36,6 +36,6 @@ class CostQuery::Filter::AssignedToId < CostQuery::Filter::UserId
end
def self.available_values(*)
- CostQuery::Filter::UserId.available_values
+ []
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/author_id.rb b/modules/reporting/app/models/cost_query/filter/author_id.rb
index 910eac962a6..9c148f36987 100644
--- a/modules/reporting/app/models/cost_query/filter/author_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/author_id.rb
@@ -35,6 +35,6 @@ class CostQuery::Filter::AuthorId < CostQuery::Filter::UserId
end
def self.available_values(*)
- CostQuery::Filter::UserId.available_values
+ []
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/logged_by_id.rb b/modules/reporting/app/models/cost_query/filter/logged_by_id.rb
index 3ee3b8d2ebb..a1dc7624af7 100644
--- a/modules/reporting/app/models/cost_query/filter/logged_by_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/logged_by_id.rb
@@ -37,8 +37,7 @@ class CostQuery::Filter::LoggedById < Report::Filter::Base
def transformed_values
# Map the special 'me' value
- super
- .filter_map { |val| replace_me_value(val) }
+ super.filter_map { |val| replace_me_value(val) }
end
def replace_me_value(value)
@@ -49,19 +48,7 @@ class CostQuery::Filter::LoggedById < Report::Filter::Base
end
end
- # rubocop:disable Metrics/AbcSize
def self.available_values(*)
- # All users which are members in projects the user can see.
- # Excludes the anonymous user
- users = User.joins(members: :project)
- .merge(Project.visible)
- .human
- .select(User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s) << :id)
- .distinct
-
- values = users.map { |u| [u.name, u.id] }
- values.unshift [::I18n.t(:label_me), me_value] if User.current.logged?
- values
+ []
end
- # rubocop:enable Metrics/AbcSize
end
diff --git a/modules/reporting/app/models/cost_query/filter/project_id.rb b/modules/reporting/app/models/cost_query/filter/project_id.rb
index de88d8515b7..3bfc4931e3a 100644
--- a/modules/reporting/app/models/cost_query/filter/project_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/project_id.rb
@@ -37,21 +37,7 @@ class CostQuery::Filter::ProjectId < Report::Filter::Base
["=", "!", "=_child_projects", "!_child_projects"].map(&:to_operator)
end
- ##
- # Calculates the available values for this filter.
- # Gives a map of [project_name, project_id, nesting_level_of_project].
- # The map is sorted such that projects appear in alphabetical order within a nesting level
- # and so that descendant projects appear after their ancestors.
def self.available_values(*)
- map = []
- ancestors = []
- Project.visible.sort_by(&:lft).each do |project|
- while ancestors.any? && !project.is_descendant_of?(ancestors.last)
- ancestors.pop
- end
- map << [project.name, project.id, { level: ancestors.size }]
- ancestors << project
- end
- map
+ []
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/responsible_id.rb b/modules/reporting/app/models/cost_query/filter/responsible_id.rb
index 97f0ef79131..b57870e5232 100644
--- a/modules/reporting/app/models/cost_query/filter/responsible_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/responsible_id.rb
@@ -36,6 +36,6 @@ class CostQuery::Filter::ResponsibleId < CostQuery::Filter::UserId
end
def self.available_values(*)
- CostQuery::Filter::UserId.available_values
+ []
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/user_id.rb b/modules/reporting/app/models/cost_query/filter/user_id.rb
index ade49625889..dd5759d2591 100644
--- a/modules/reporting/app/models/cost_query/filter/user_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/user_id.rb
@@ -50,15 +50,6 @@ class CostQuery::Filter::UserId < Report::Filter::Base
end
def self.available_values(*)
- # All users which are members in projects the user can see.
- # Excludes the anonymous user
- users = User.in_visible_project
- .human
- .ordered_by_name
- .select(User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s) << :id)
-
- values = users.map { |u| [u.name, u.id] }
- values.unshift [::I18n.t(:label_me), me_value] if User.current.logged?
- values
+ []
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/work_package_id.rb b/modules/reporting/app/models/cost_query/filter/work_package_id.rb
index 7c195d09730..2a899f9a4dd 100644
--- a/modules/reporting/app/models/cost_query/filter/work_package_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/work_package_id.rb
@@ -40,11 +40,7 @@ class CostQuery::Filter::WorkPackageId < Report::Filter::Base
end
def self.available_values(*)
- WorkPackage
- .where(project_id: Project.allowed_to(User.current, :view_work_packages))
- .order(:id)
- .pluck(:id, :subject)
- .map { |id, subject| [text_for_tuple(id, subject), id] }
+ []
end
##
@@ -53,7 +49,7 @@ class CostQuery::Filter::WorkPackageId < Report::Filter::Base
def self.label_for_value(value)
return nil unless value.to_i.to_s == value.to_s # we expect an work_package-id
- work_package = WorkPackage.find(value.to_i)
+ work_package = WorkPackage.visible.find(value.to_i)
[text_for_work_package(work_package), work_package.id] if work_package&.visible?(User.current)
end
diff --git a/modules/reporting/lib/widget/filters.rb b/modules/reporting/lib/widget/filters.rb
index f78003b762a..04e57a544bf 100644
--- a/modules/reporting/lib/widget/filters.rb
+++ b/modules/reporting/lib/widget/filters.rb
@@ -97,22 +97,29 @@ class Widget::Filters < Widget::Base
render_widget Label, f, to: html
render_widget Operators, f, to: html
- if f_cls.heavy?
+ # Handling for custom widgets first
+ if f_cls == CostQuery::Filter::ProjectId
+ render_widget Project, f, to: html, lazy: true
+ elsif f_cls.in?([CostQuery::Filter::UserId, CostQuery::Filter::LoggedById, CostQuery::Filter::AssignedToId,
+ CostQuery::Filter::ResponsibleId, CostQuery::Filter::AuthorId])
+ render_widget User, f, to: html, lazy: true
+ elsif f_cls == CostQuery::Filter::WorkPackageId
+ render_widget WorkPackage, f, to: html, lazy: true
+ # Handling of generic widgets
+ elsif f_cls.heavy?
render_widget Heavy, f, to: html
elsif engine::Operator.string_operators.all? { |o| f_cls.available_operators.include? o }
render_widget TextBox, f, to: html
elsif engine::Operator.time_operators.all? { |o| f_cls.available_operators.include? o }
render_widget Date, f, to: html
elsif engine::Operator.integer_operators.all? { |o| f_cls.available_operators.include? o }
- if f_cls.available_values.nil? || f_cls.available_values.empty?
+ if f_cls.available_values.blank?
render_widget TextBox, f, to: html
else
render_widget MultiValues, f, to: html, lazy: true
end
elsif f_cls.is_multiple_choice?
render_widget MultiChoice, f, to: html
- elsif f_cls == CostQuery::Filter::ProjectId
- render_widget Project, f, to: html, lazy: true
else
render_widget MultiValues, f, to: html, lazy: true
end
diff --git a/modules/reporting/lib/widget/filters/project.rb b/modules/reporting/lib/widget/filters/project.rb
index 5fe41f75bca..72c957fc6f2 100644
--- a/modules/reporting/lib/widget/filters/project.rb
+++ b/modules/reporting/lib/widget/filters/project.rb
@@ -70,16 +70,12 @@ class Widget::Filters::Project < Widget::Filters::Base
# When live testing, these IDs came out as integers.
# However, when running the specs, they came out as strings.
- int_id = Integer(id)
- available_value = filter_class.available_values.detect { |val| Integer(val[1]) === int_id }
+ project = Project.visible.find_by(id: id)
- if available_value.nil?
+ if project.nil?
nil
else
- {
- id: int_id,
- name: available_value[0]
- }
+ { id: id, name: project.name }
end
end
end
diff --git a/modules/reporting/lib/widget/filters/user.rb b/modules/reporting/lib/widget/filters/user.rb
new file mode 100644
index 00000000000..420235846a9
--- /dev/null
+++ b/modules/reporting/lib/widget/filters/user.rb
@@ -0,0 +1,93 @@
+# 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.
+#++
+
+class Widget::Filters::User < Widget::Filters::Base
+ include AngularHelper
+
+ def render # rubocop:disable Metrics/AbcSize
+ write(content_tag(:div, id: "#{filter_class.underscore_name}_arg_1", class: "advanced-filters--filter-value") do
+ label = html_label
+
+ selected_values = map_filter_values
+
+ box = angular_component_tag "opce-user-autocompleter",
+ inputs: {
+ InputName: "values[#{filter_class.underscore_name}]",
+ hiddenFieldAction: "change->reporting--page#selectValueChanged",
+ multiple: true,
+ model: selected_values.compact,
+ resource: "principals",
+ url: ::API::V3::Utilities::PathHelper::ApiV3Path.principals,
+ filters: [
+ { name: "type", operator: "=", values: ["User"] },
+ { name: "status", operator: "!", values: [Principal.statuses["locked"].to_s] }
+ ],
+ additionalOptions: [
+ { id: CostQuery::Filter::UserId.me_value, name: I18n.t(:label_me) }
+ ]
+ },
+ id: "#{filter_class.underscore_name}_select_1",
+ class: "filter-value"
+
+ content_tag(:span, class: "inline-label") do
+ label + box
+ end
+ end)
+ end
+
+ private
+
+ def html_label
+ label_tag "#{filter_class.underscore_name}_arg_1_val",
+ "#{h(filter_class.label)} #{I18n.t(:label_filter_value)}",
+ class: "sr-only"
+ end
+
+ def map_filter_values # rubocop:disable Metrics/AbcSize
+ # In case the filter values are all written in a single string (e.g. ["12, 33"])
+ if filter.values.length === 1 && filter.values[0].instance_of?(String)
+ filter.values = filter.values[0].split(",")
+ end
+
+ filter.values.map do |id|
+ if id == CostQuery::Filter::UserId.me_value
+ { id: CostQuery::Filter::UserId.me_value, name: I18n.t(:label_me) }
+ else
+ user = User.visible.find_by(id: id)
+
+ if user.nil?
+ nil
+ else
+ { id: id, name: user.name }
+ end
+ end
+ end
+ end
+end
diff --git a/modules/reporting/lib/widget/filters/work_package.rb b/modules/reporting/lib/widget/filters/work_package.rb
new file mode 100644
index 00000000000..2e81329a57a
--- /dev/null
+++ b/modules/reporting/lib/widget/filters/work_package.rb
@@ -0,0 +1,83 @@
+# 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.
+#++
+
+class Widget::Filters::WorkPackage < Widget::Filters::Base
+ include AngularHelper
+
+ def render
+ write(content_tag(:div, id: "#{filter_class.underscore_name}_arg_1", class: "advanced-filters--filter-value") do
+ label = html_label
+
+ selected_values = map_filter_values
+
+ box = angular_component_tag "opce-autocompleter",
+ inputs: {
+ filters: [],
+ InputName: "values[#{filter_class.underscore_name}]",
+ hiddenFieldAction: "change->reporting--page#selectValueChanged",
+ multiple: true,
+ model: selected_values.compact,
+ resource: "work_packages",
+ searchKey: "subjectOrId"
+ },
+ id: "#{filter_class.underscore_name}_select_1",
+ class: "filter-value"
+
+ content_tag(:span, class: "inline-label") do
+ label + box
+ end
+ end)
+ end
+
+ private
+
+ def html_label
+ label_tag "#{filter_class.underscore_name}_arg_1_val",
+ "#{h(filter_class.label)} #{I18n.t(:label_filter_value)}",
+ class: "sr-only"
+ end
+
+ def map_filter_values # rubocop:disable Metrics/AbcSize
+ # In case the filter values are all written in a single string (e.g. ["12, 33"])
+ if filter.values.length === 1 && filter.values[0].instance_of?(String)
+ filter.values = filter.values[0].split(",")
+ end
+
+ filter.values.each.map do |id|
+ work_package = WorkPackage.visible.find_by(id: id)
+
+ if work_package.nil?
+ nil
+ else
+ { id: id, name: work_package.subject }
+ end
+ end
+ end
+end