Browse Source

Deduplicate filter views

pull/2403/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
e0b9d249e9
  1. 3
      app/controllers/lettings_logs_filters_controller.rb
  2. 2
      app/controllers/organisations_controller.rb
  3. 3
      app/controllers/sales_logs_filters_controller.rb
  4. 4
      app/views/filters/assigned_to.html.erb
  5. 30
      app/views/filters/lettings_log_filters/owned_by.html.erb
  6. 20
      app/views/filters/lettings_log_filters/status.html.erb
  7. 4
      app/views/filters/managed_by.html.erb
  8. 4
      app/views/filters/needstype.html.erb
  9. 4
      app/views/filters/owned_by.html.erb
  10. 32
      app/views/filters/sales_log_filters/assigned_to.html.erb
  11. 30
      app/views/filters/sales_log_filters/managed_by.html.erb
  12. 36
      app/views/filters/sales_log_filters/years.html.erb
  13. 4
      app/views/filters/status.html.erb
  14. 4
      app/views/filters/years.html.erb
  15. 4
      config/routes.rb
  16. 2
      spec/requests/lettings_logs_controller_spec.rb

3
app/controllers/lettings_logs_filters_controller.rb

@ -5,7 +5,8 @@ class LettingsLogsFiltersController < ApplicationController
%w[years status needstype assigned_to owned_by managed_by].each do |filter|
define_method(filter) do
@filter_type = "lettings_logs"
render "filters/lettings_log_filters/#{filter}"
@filter = filter
render "filters/#{filter}"
end
end

2
app/controllers/organisations_controller.rb

@ -188,7 +188,7 @@ class OrganisationsController < ApplicationController
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters)
codes_only = params.require(:codes_only) == "true"
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: sales_logs_email_csv_organisation_path, codes_only:, session_filters:, filter_type: "lettings_logs" }
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: sales_logs_email_csv_organisation_path, codes_only:, session_filters:, filter_type: "sales_logs" }
end
def email_sales_csv

3
app/controllers/sales_logs_filters_controller.rb

@ -5,7 +5,8 @@ class SalesLogsFiltersController < ApplicationController
%w[years status assigned_to owned_by managed_by].each do |filter|
define_method(filter) do
@filter_type = "sales_logs"
render "filters/sales_log_filters/#{filter}"
@filter = filter
render "filters/#{filter}"
end
end

4
app/views/filters/lettings_log_filters/assigned_to.html.erb → app/views/filters/assigned_to.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_assigned_to_lettings_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<%= render partial: "filters/radio_filter",
locals: {
f:,
@ -26,6 +26,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_lettings_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
<%= govuk_button_link_to "Cancel", send("csv_download_#{@filter_type}_path", search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

30
app/views/filters/lettings_log_filters/owned_by.html.erb

@ -1,30 +0,0 @@
<%= form_with html: { method: :get }, url: filters_update_owned_by_lettings_logs_path do |f| %>
<%= render partial: "filters/radio_filter", locals: {
f:,
options: {
"all": { label: "Any owning organisation" },
"specific_org": {
label: "Specific owning organisation",
conditional_filter: {
type: "select",
label: "Owning Organisation",
category: "owning_organisation",
options: owning_organisation_filter_options(current_user),
},
},
},
label: "Owned by",
category: "owning_organisation_select",
size: "l",
} %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.hidden_field :codes_only, value: request.params["codes_only"] %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_lettings_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

20
app/views/filters/lettings_log_filters/status.html.erb

@ -1,20 +0,0 @@
<%= form_with html: { method: :get }, url: filters_update_status_lettings_logs_path do |f| %>
<%= render partial: "filters/checkbox_filter",
locals: {
f:,
options: status_filters,
label: "Status",
category: "status",
size: "l",
} %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.hidden_field :codes_only, value: request.params["codes_only"] %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_lettings_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

4
app/views/filters/lettings_log_filters/managed_by.html.erb → app/views/filters/managed_by.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_managed_by_lettings_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<%= render partial: "filters/radio_filter", locals: {
f:,
options: {
@ -25,6 +25,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_lettings_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
<%= govuk_button_link_to "Cancel", send("csv_download_#{@filter_type}_path", search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

4
app/views/filters/lettings_log_filters/needstype.html.erb → app/views/filters/needstype.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_needstype_lettings_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<%= render partial: "filters/checkbox_filter",
locals: {
f:,
@ -15,6 +15,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_lettings_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
<%= govuk_button_link_to "Cancel", send("csv_download_#{@filter_type}_path", search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

4
app/views/filters/sales_log_filters/owned_by.html.erb → app/views/filters/owned_by.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_owned_by_sales_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<%= render partial: "filters/radio_filter", locals: {
f:,
options: {
@ -25,6 +25,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_sales_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
<%= govuk_button_link_to "Cancel", send("csv_download_#{@filter_type}_path", search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

32
app/views/filters/sales_log_filters/assigned_to.html.erb

@ -1,32 +0,0 @@
<%= form_with html: { method: :get }, url: filters_update_assigned_to_sales_logs_path do |f| %>
<%= render partial: "filters/radio_filter",
locals: {
f:,
options: {
"all": { label: "Any user" },
"you": { label: "You" },
"specific_user": {
label: "Specific user",
conditional_filter: {
type: "select",
label: "User",
category: "user",
options: assigned_to_filter_options(current_user),
},
},
},
label: "Assigned to",
category: "assigned_to",
size: "l",
} %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.hidden_field :codes_only, value: request.params["codes_only"] %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_sales_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

30
app/views/filters/sales_log_filters/managed_by.html.erb

@ -1,30 +0,0 @@
<%= form_with html: { method: :get }, url: filters_update_manaed_by_sales_logs_path do |f| %>
<%= render partial: "filters/radio_filter", locals: {
f:,
options: {
"all": { label: "Any managing organisation" },
"specific_org": {
label: "Specific managing organisation",
conditional_filter: {
type: "select",
label: "Reported by",
category: "managing_organisation",
options: managing_organisation_filter_options(current_user),
},
},
},
label: "Reported by",
category: "managing_organisation_select",
size: "l",
} %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.hidden_field :codes_only, value: request.params["codes_only"] %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_sales_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

36
app/views/filters/sales_log_filters/years.html.erb

@ -1,36 +0,0 @@
<%= form_with html: { method: :get }, url: filters_update_years_sales_logs_path do |f| %> <% if params["error"].present? %>
<div class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
<h2 class="govuk-error-summary__title">
There is a problem
</h2>
<div class="govuk-error-summary__body">
<ul class="govuk-list govuk-error-summary__list">
<li>
<a href="#"><%= params["error"] %></a>
</li>
</ul>
</div>
</div>
</div>
<% end %>
<%= render partial: "filters/radio_filter",
locals: {
f:,
options: collection_year_radio_options,
label: "Which financial year do you want to download data for?",
category: "years",
size: "l",
} %>
<% if request.params["search"].present? %>
<%= f.hidden_field :search, value: request.params["search"] %>
<% end %>
<%= f.hidden_field :codes_only, value: request.params["codes_only"] %>
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", sales_logs_path, secondary: true %>
</div>
<% end %>

4
app/views/filters/sales_log_filters/status.html.erb → app/views/filters/status.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_status_sales_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<%= render partial: "filters/checkbox_filter",
locals: {
f:,
@ -15,6 +15,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", csv_download_sales_logs_path(search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
<%= govuk_button_link_to "Cancel", send("csv_download_#{@filter_type}_path", search: request.params["search"], codes_only: request.params["codes_only"]), secondary: true %>
</div>
<% end %>

4
app/views/filters/lettings_log_filters/years.html.erb → app/views/filters/years.html.erb

@ -1,4 +1,4 @@
<%= form_with html: { method: :get }, url: filters_update_years_lettings_logs_path do |f| %>
<%= form_with html: { method: :get }, url: send("filters_update_#{@filter}_#{@filter_type}_path") do |f| %>
<% if params["error"].present? %>
<div class="govuk-error-summary" data-module="govuk-error-summary">
<div role="alert">
@ -32,6 +32,6 @@
<div class="govuk-button-group">
<%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", lettings_logs_path, secondary: true %>
<%= govuk_button_link_to "Cancel", send("#{@filter_type}_path"), secondary: true %>
</div>
<% end %>

4
config/routes.rb

@ -216,7 +216,7 @@ Rails.application.routes.draw do
%w[years status needstype assigned-to owned-by managed-by].each do |filter|
get "filters/#{filter}", to: "lettings_logs_filters##{filter.underscore}"
get "filters/update_#{filter}", to: "lettings_logs_filters#update_#{filter.underscore}"
get "filters/update-#{filter}", to: "lettings_logs_filters#update_#{filter.underscore}"
end
resources :bulk_upload_lettings_logs, path: "bulk-upload-logs", only: %i[show update] do
@ -286,7 +286,7 @@ Rails.application.routes.draw do
%w[years status assigned-to owned-by managed-by].each do |filter|
get "filters/#{filter}", to: "sales_logs_filters##{filter.underscore}"
get "filters/update_#{filter}", to: "sales_logs_filters#update_#{filter.underscore}"
get "filters/update-#{filter}", to: "sales_logs_filters#update_#{filter.underscore}"
end
resources :bulk_upload_sales_logs, path: "bulk-upload-logs" do

2
spec/requests/lettings_logs_controller_spec.rb

@ -983,7 +983,7 @@ RSpec.describe LettingsLogsController, type: :request do
end
end
xcontext "when on the second page" do
context "when on the second page" do
before do
get "/lettings-logs?page=2", headers:, params: {}
end

Loading…
Cancel
Save