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

Add filter option "All shares" for the members "Work package shares" filter

Henriette Dargee30f44eca4b4
diff --git a/app/components/individual_principal_base_filter_component.html.erb b/app/components/individual_principal_base_filter_component.html.erb
index 3ee164d8374..07e384bab2a 100644
--- a/app/components/individual_principal_base_filter_component.html.erb
+++ b/app/components/individual_principal_base_filter_component.html.erb
@@ -90,7 +90,7 @@ See COPYRIGHT and LICENSE files for more details.
:shared_role_id,
options_for_select(
shares,
- params[:shared_role_id].to_i
+ params[:shared_role_id]
),
{
include_blank: true,
diff --git a/app/components/members/user_filter_component.rb b/app/components/members/user_filter_component.rb
index d3c42c7ed55..9fd16eb3723 100644
--- a/app/components/members/user_filter_component.rb
+++ b/app/components/members/user_filter_component.rb
@@ -30,6 +30,8 @@
module Members
class UserFilterComponent < ::UserFilterComponent
+ ALL_SHARED_FILTER_KEY = 'all'
+
def initially_visible?
false
end
@@ -82,10 +84,12 @@ module Members
end
def share_options
- WorkPackageRole
+ share_options = WorkPackageRole
.where(builtin: builtin_share_roles)
.order(builtin: :asc)
.map { |role| [mapped_shared_role_name(role), role.id] }
+
+ share_options.unshift([I18n.t('members.filters.all_shares'), ALL_SHARED_FILTER_KEY])
end
def builtin_share_roles
@@ -112,14 +116,20 @@ module Members
protected
def filter_shares(query, role_id)
- return unless role_id > 0
-
- query.where(:role_id, '=', role_id)
+ if role_id === ALL_SHARED_FILTER_KEY
+ ids = WorkPackageRole
+ .where(builtin: builtin_share_roles)
+ .pluck(:id)
+
+ query.where(:role_id, '=', ids.uniq)
+ elsif role_id.to_i > 0
+ query.where(:role_id, '=', role_id.to_i)
+ end
end
def apply_filters(params, query)
super(params, query)
- filter_shares(query, params[:shared_role_id].to_i) if params.key?(:shared_role_id)
+ filter_shares(query, params[:shared_role_id]) if params.key?(:shared_role_id)
query
end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 54aff993b2b..9632ba0f2d6 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -313,6 +313,8 @@ en:
no_results_content_text: Add a member to the project
invite_by_mail: "Send invite to %{mail}"
send_invite_to: "Send invite to"
+ filters:
+ all_shares: 'All shares'
menu:
all: 'All'
invited: 'Invited'