Browse Source

feat: update helper logic

pull/1998/head
natdeanlewissoftwire 3 years ago
parent
commit
65663905bc
  1. 14
      app/helpers/filters_helper.rb
  2. 6
      app/views/logs/_log_filters.html.erb

14
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?) user.support? || org.stock_owners.count > 1 || (org.holds_own_stock? && org.stock_owners.count.positive?)
end end
def has_logs_for_both_needstypes? def logs_for_both_needstypes_present?
[1, 2].all? { |needstype| current_user.lettings_logs.where(needstype:).count.positive? } [1, 2].all? { |needstype| current_user.lettings_logs.where(needstype:).count.positive? }
end end
def multiple_owning_orgs? def non_support_with_multiple_owning_orgs?
current_user.support? || current_user.organisation.stock_owners.count > 1 current_user.organisation.stock_owners.count > 1 && user_lettings_path?
end end
def multiple_managing_orgs? def non_support_with_multiple_managing_orgs?
current_user.support? || current_user.organisation.managing_agents.count > 1 current_user.organisation.managing_agents.count > 1 && user_lettings_path?
end
def user_lettings_path?
request.path == "/lettings-logs"
end end
def user_or_org_lettings_path? def user_or_org_lettings_path?

6
app/views/logs/_log_filters.html.erb

@ -42,7 +42,7 @@
category: "status", category: "status",
} %> } %>
<% if has_logs_for_both_needstypes? && user_or_org_lettings_path? %> <% if logs_for_both_needstypes_present? && user_or_org_lettings_path? %>
<%= render partial: "filters/checkbox_filter", <%= render partial: "filters/checkbox_filter",
locals: { locals: {
f:, f:,
@ -73,7 +73,7 @@
category: "assigned_to", category: "assigned_to",
} %> } %>
<% if multiple_owning_orgs? && user_or_org_lettings_path? %> <% if current_user.support? || non_support_with_multiple_owning_orgs? %>
<%= render partial: "filters/radio_filter", locals: { <%= render partial: "filters/radio_filter", locals: {
f:, f:,
options: { options: {
@ -93,7 +93,7 @@
} %> } %>
<% end %> <% end %>
<% if multiple_managing_orgs? && user_or_org_lettings_path? %> <% if current_user.support? || non_support_with_multiple_managing_orgs? %>
<%= render partial: "filters/radio_filter", locals: { <%= render partial: "filters/radio_filter", locals: {
f:, f:,
options: { options: {

Loading…
Cancel
Save