Browse Source

UI init

pull/522/head
baarkerlounger 3 years ago
parent
commit
87e23ab9e4
  1. 2
      app/controllers/case_logs_controller.rb
  2. 6
      app/helpers/filters_helper.rb
  3. 10
      app/views/case_logs/_log_filters.erb
  4. 19
      app/views/filters/_radio_filter.html.erb
  5. 7
      app/views/filters/_select_filter.html.erb
  6. 9
      spec/requests/case_logs_controller_spec.rb

2
app/controllers/case_logs_controller.rb

@ -126,7 +126,7 @@ private
if session[:case_logs_filters].present? if session[:case_logs_filters].present?
filters = JSON.parse(session[:case_logs_filters]) filters = JSON.parse(session[:case_logs_filters])
filters.each do |category, values| filters.each do |category, values|
next if values.reject(&:empty?).blank? next if Array(values).reject(&:empty?).blank?
query = query.public_send("filter_by_#{category}", values, current_user) query = query.public_send("filter_by_#{category}", values, current_user)
end end

6
app/helpers/filters_helper.rb

@ -14,4 +14,10 @@ module FiltersHelper
CaseLog.statuses.keys.map { |status| statuses[status] = status.humanize } CaseLog.statuses.keys.map { |status| statuses[status] = status.humanize }
statuses statuses
end end
def selected_option(filter)
return false unless session[:case_logs_filters]
JSON.parse(session[:case_logs_filters])[filter]
end
end end

10
app/views/case_logs/_log_filters.erb

@ -11,7 +11,15 @@
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %> <%= render partial: "filters/checkbox_filter", locals: { f: f, options: status_filters, label: "Status", category: "status" } %>
<%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %> <%= render partial: "filters/radio_filter", locals: { f: f, options: all_or_yours, label: "Logs", category: "user", } %>
<% if @current_user.support? %> <% if @current_user.support? %>
<%= render partial: "filters/checkbox_filter", locals: { f: f, options: {"all": "All", "yours": "Yours"}, label: "Organisation", category: "organisation" } %> <%= render partial: "filters/radio_filter", locals: {
f: f,
options: {
"all": { label: "All" },
"specific_org": { label: "Specific organisation", conditional_filter: { type: "select", label: "Organisation", category: "organisation" } }
},
label: "Organisation",
category: "organisation"
} %>
<% end %> <% end %>
<%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %> <%= f.govuk_submit "Apply filters", class: "govuk-!-margin-bottom-0" %>
<% end %> <% end %>

19
app/views/filters/_radio_filter.html.erb

@ -1,8 +1,17 @@
<%= f.govuk_radio_buttons_fieldset category.to_sym, legend: { text: label, size: "s" }, small: true, form_group: { classes: "app-filter__group" } do %> <%= f.govuk_radio_buttons_fieldset category.to_sym, legend: { text: label, size: "s" }, small: true, form_group: { classes: "app-filter__group" } do %>
<% options.map do |key, option| %> <% options.map do |key, option| %>
<%= f.govuk_radio_button category, key.to_s, <%= f.govuk_radio_button category, key.to_s,
label: { text: option }, label: { text: option },
checked: filter_selected?(category, key), checked: filter_selected?(category, key),
size: "s" %> size: "s"
%>
<% if option[:conditional_filter] %>
<%= render partial: "filters/#{option[:conditional_filter][:type]}_filter", locals: {
f: f,
collection: Organisation.all,
category: "organisation",
secondary: true
} %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>

7
app/views/filters/_select_filter.html.erb

@ -0,0 +1,7 @@
<%= f.govuk_collection_select category.to_sym,
collection,
:id,
:name,
label: { hidden: secondary },
options: { disabled: [""], selected: selected_option(category) },
"data-controller": "accessible-autocomplete" %>

9
spec/requests/case_logs_controller_spec.rb

@ -186,6 +186,7 @@ RSpec.describe CaseLogsController, type: :request do
context "when filtering" do context "when filtering" do
context "with status filter" do context "with status filter" do
let(:organisation_2) { FactoryBot.create(:organisation) }
let!(:in_progress_case_log) do let!(:in_progress_case_log) do
FactoryBot.create(:case_log, :in_progress, FactoryBot.create(:case_log, :in_progress,
owning_organisation: organisation, owning_organisation: organisation,
@ -193,7 +194,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
let!(:completed_case_log) do let!(:completed_case_log) do
FactoryBot.create(:case_log, :completed, FactoryBot.create(:case_log, :completed,
owning_organisation: organisation, owning_organisation: organisation_2,
managing_organisation: organisation) managing_organisation: organisation)
end end
@ -209,6 +210,12 @@ RSpec.describe CaseLogsController, type: :request do
expect(page).not_to have_link(completed_case_log.id.to_s) expect(page).not_to have_link(completed_case_log.id.to_s)
end end
it "filters on organisation" do
get "/logs?organisation[]=#{organisation_2.id}", headers: headers, params: {}
expect(page).to have_link(completed_case_log.id.to_s)
expect(page).not_to have_link(in_progress_case_log.id.to_s)
end
it "does not reset the filters" do it "does not reset the filters" do
get "/logs?status[]=in_progress", headers: headers, params: {} get "/logs?status[]=in_progress", headers: headers, params: {}
expect(page).to have_link(in_progress_case_log.id.to_s) expect(page).to have_link(in_progress_case_log.id.to_s)

Loading…
Cancel
Save