Browse Source

extract view variable to helper method

pull/1223/head
Phil Lee 3 years ago
parent
commit
e08cd1b84e
  1. 5
      app/helpers/logs_helper.rb
  2. 7
      app/views/logs/_log_filters.erb

5
app/helpers/logs_helper.rb

@ -18,4 +18,9 @@ module LogsHelper
bulk_upload_sales_log_path(id:) bulk_upload_sales_log_path(id:)
end end
end end
def bulk_upload_options(bulk_upload)
array = bulk_upload ? [bulk_upload.id] : []
array.index_with { |_bulk_upload_id| "With logs from bulk upload" }
end
end end

7
app/views/logs/_log_filters.erb

@ -8,19 +8,18 @@
<%= form_with html: { method: :get } do |f| %> <%= form_with html: { method: :get } do |f| %>
<% years = { "2021": "2021/22", "2022": "2022/23" } %> <% years = { "2021": "2021/22", "2022": "2022/23" } %>
<% all_or_yours = { "all": { label: "All" }, "yours": { label: "Yours" } } %> <% all_or_yours = { "all": { label: "All" }, "yours": { label: "Yours" } } %>
<% bulk_upload_options = (@session_filters["bulk_upload_id"] || []).reject(&:blank?).index_with { |_bulk_upload_id| "With logs from bulk upload" } %>
<% if bulk_upload_options.present? %> <% if bulk_upload_options(@bulk_upload).present? %>
<%= render partial: "filters/checkbox_filter", <%= render partial: "filters/checkbox_filter",
locals: { locals: {
f: f, f: f,
options: bulk_upload_options, options: bulk_upload_options(@bulk_upload),
label: "Bulk upload", label: "Bulk upload",
category: "bulk_upload_id", category: "bulk_upload_id",
} %> } %>
<% end %> <% end %>
<% if bulk_upload_options.blank? %> <% if bulk_upload_options(@bulk_upload).blank? %>
<%= render partial: "filters/checkbox_filter", <%= render partial: "filters/checkbox_filter",
locals: { locals: {
f: f, f: f,

Loading…
Cancel
Save