From ce4c889d82a5d78217f9f2eec88ed9f0d8beb369 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 20 Oct 2023 13:52:21 +0100 Subject: [PATCH] feat: update helper methods, and show managing and owning filters as well in support secondary nav --- app/helpers/filters_helper.rb | 16 ++++++++++------ app/views/logs/_log_filters.html.erb | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb index 345b7f45c..61afb573b 100644 --- a/app/helpers/filters_helper.rb +++ b/app/helpers/filters_helper.rb @@ -116,16 +116,20 @@ module FiltersHelper user.support? || org.stock_owners.count > 1 || (org.holds_own_stock? && org.stock_owners.count.positive?) end - def show_needstype_filter? - [1,2].all?{ |needstype| current_user.lettings_logs.where(needstype:).count.positive? } && request.path.include?("/lettings-logs") + def has_logs_for_both_needstypes? + [1, 2].all? { |needstype| current_user.lettings_logs.where(needstype:).count.positive? } end - def show_owning_org_filter? - (current_user.support? || current_user.organisation.stock_owners.count > 1) && request.path == "/lettings-logs" + def multiple_owning_orgs? + current_user.support? || current_user.organisation.stock_owners.count > 1 end - def show_managing_org_filter? - (current_user.support? || current_user.organisation.managing_agents.count > 1) && request.path == "/lettings-logs" + def multiple_managing_orgs? + current_user.support? || current_user.organisation.managing_agents.count > 1 + end + + def user_or_org_lettings_path? + request.path.include?("/lettings-logs") end private diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index b03d79318..d8cb1d7d7 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -42,7 +42,7 @@ category: "status", } %> - <% if show_needstype_filter? %> + <% if has_logs_for_both_needstypes? && user_or_org_lettings_path? %> <%= render partial: "filters/checkbox_filter", locals: { f:, @@ -73,7 +73,7 @@ category: "assigned_to", } %> - <% if show_owning_org_filter? %> + <% if multiple_owning_orgs? && user_or_org_lettings_path? %> <%= render partial: "filters/radio_filter", locals: { f:, options: { @@ -93,7 +93,7 @@ } %> <% end %> - <% if show_managing_org_filter? %> + <% if multiple_managing_orgs? && user_or_org_lettings_path? %> <%= render partial: "filters/radio_filter", locals: { f:, options: {