Browse Source

refactor: removal of logic from erbs

pull/1327/head
natdeanlewissoftwire 3 years ago
parent
commit
2da30e21c0
  1. 2
      app/components/search_component.rb
  2. 16
      app/helpers/logs_helper.rb
  3. 19
      app/views/logs/index.html.erb

2
app/components/search_component.rb

@ -23,7 +23,7 @@ class SearchComponent < ViewComponent::Base
user_path(current_user)
elsif request.path.include?("organisations")
organisations_path
elsif FeatureToggle.sales_log_enabled? && request.path.include?("sales-logs")
elsif request.path.include?("sales-logs")
sales_logs_path
elsif request.path.include?("logs")
lettings_logs_path

16
app/helpers/logs_helper.rb

@ -23,4 +23,20 @@ module LogsHelper
array = bulk_upload ? [bulk_upload.id] : []
array.index_with { |_bulk_upload_id| "With logs from bulk upload" }
end
def search_label_for_controller(controller)
case log_type_for_controller(controller)
when "lettings"
"Search by log ID, tenant code, property reference or postcode"
when "sales"
"Search by log ID, purchaser code or postcode"
end
end
def csv_download_url_for_controller(controller)
case log_type_for_controller(controller)
when "lettings"
csv_download_lettings_logs_path(search: @search_term)
end
end
end

19
app/views/logs/index.html.erb

@ -64,24 +64,9 @@
<%= render partial: "log_filters" %>
<div class="app-filter-layout__content">
<% if current_page?(controller: 'lettings_logs', action: 'index') %>
<%= render SearchComponent.new(current_user:, search_label: "Search by log ID, tenant code, property reference or postcode", value: @searched) %>
<% end %>
<% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %>
<%= render SearchComponent.new(current_user:, search_label: "Search by log ID, purchaser code or postcode", value: @searched) %>
<% end %>
<%= render SearchComponent.new(current_user:, search_label: search_label_for_controller(controller), value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %>
<% if current_page?(controller: 'lettings_logs', action: 'index') %>
<%= render partial: "log_list", locals: { logs: @logs, title: "Logs", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, csv_download_url: csv_download_lettings_logs_path(search: @search_term) } %>
<% end %>
<% if FeatureToggle.sales_log_enabled? && current_page?(controller: 'sales_logs', action: 'index') %>
<%= render partial: "log_list", locals: { logs: @logs, title: "Logs", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<% end %>
<%= render partial: "log_list", locals: { logs: @logs, title: "Logs", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count, csv_download_url: csv_download_url_for_controller(controller) } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "logs" } %>
</div>
</div>

Loading…
Cancel
Save