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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Set selected menu item based on filter
Oliver Günther17f73b6308ec
diff --git a/app/components/individual_principal_base_filter_component.rb b/app/components/individual_principal_base_filter_component.rbindex c8b80f07256..e99ce0aabe2 100644--- a/app/components/individual_principal_base_filter_component.rb+++ b/app/components/individual_principal_base_filter_component.rb@@ -42,8 +42,12 @@ class IndividualPrincipalBaseFilterComponent < ApplicationComponentquery(params).resultsend+ def filter_param_keys+ %i(name status group_id role_id)+ end+def filtered?(params)- %i(name status group_id role_id).any? { |name| params[name].present? }+ filter_param_keys.any? { |name| params[name].present? }enddef filter_name(query, name)diff --git a/app/components/open_project/common/submenu_component.html.erb b/app/components/open_project/common/submenu_component.html.erbindex f33bd2cdbfd..b45a03c6113 100644--- a/app/components/open_project/common/submenu_component.html.erb+++ b/app/components/open_project/common/submenu_component.html.erb@@ -6,7 +6,8 @@<ul class="op-sidemenu--items"><% top_level_sidebar_menu_items.first[:children].each do |menu_item| %><li class="op-sidemenu--item">- <a class="op-sidemenu--item-action" href="<%= menu_item[:href] %>">+ <% selected = menu_item[:selected] ? 'selected' : '' %>+ <a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item[:href] %>"><%= menu_item[:title] %></a></li>@@ -37,7 +38,8 @@data-menus--expandable-sidemenu-target="container"><% menu_item[:children].each do |child_item| %><li class="op-sidemenu--item">- <a class="op-sidemenu--item-action" href="<%= child_item[:href] %>">+ <% selected = child_item[:selected] ? 'selected' : '' %>+ <a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item[:href] %>"><%= child_item[:title] %></a></li>diff --git a/app/controllers/members/menus_controller.rb b/app/controllers/members/menus_controller.rbindex 153ed632b87..b0eb2e42dff 100644--- a/app/controllers/members/menus_controller.rb+++ b/app/controllers/members/menus_controller.rb@@ -36,13 +36,29 @@ module Membersdef first_level_menu_items[{- header: nil,- children: [- { title: I18n.t('members.menu.all'), href: '' }, # TODO- { title: I18n.t('members.menu.locked'), href: '' }, # TODO- { title: I18n.t('members.menu.invited'), href: '' } # TODO- ]- }]+ header: nil,+ children: user_status_options+ }]+ end++ def user_status_options+ [+ {+ title: I18n.t('members.menu.all'),+ href: project_members_path,+ selected: active_filter_count == 0+ },+ {+ title: I18n.t('members.menu.locked'),+ href: project_members_path(status: :locked),+ selected: selected?(:status, :locked)+ },+ {+ title: I18n.t('members.menu.invited'),+ href: project_members_path(status: :invited),+ selected: selected?(:status, :invited)+ }+ ]enddef nested_menu_items@@ -72,7 +88,25 @@ module Members.groups.order(lastname: :asc).pluck(:id, :lastname)- .map { |id, name| { title: name, href: project_members_path(group_id: id) } }+ .map { |id, name| group_entry(id, name) }+ end++ def group_entry(id, name)+ {+ title: name,+ href: project_members_path(group_id: id),+ selected: selected?(:group_id, id)+ }+ end++ def selected?(filter_key, value)+ return false if active_filter_count > 1++ params[filter_key] == value.to_s+ end++ def active_filter_count+ @active_filter_count ||= (params.keys & Members::UserFilterComponent.filter_param_keys.map(&:to_s)).countendendenddiff --git a/app/views/members/menus/_menu.html.erb b/app/views/members/menus/_menu.html.erbindex e7046ff3b9a..e00f6733074 100644--- a/app/views/members/menus/_menu.html.erb+++ b/app/views/members/menus/_menu.html.erb@@ -1,5 +1,5 @@<%= turbo_frame_tag "members_menu",- src: project_members_menu_path(@project),+ src: project_members_menu_path(@project, params.permit(*Members::UserFilterComponent.filter_param_keys)),target: '_top',data: { turbo: false },loading: :lazy do %>