7 changed files with 185 additions and 61 deletions
@ -0,0 +1,8 @@ |
|||||||
|
module FiltersHelper |
||||||
|
def filter_selected?(filter) |
||||||
|
return true unless cookies[:case_logs_filters] |
||||||
|
|
||||||
|
selected_filters = JSON.parse(cookies[:case_logs_filters]) |
||||||
|
selected_filters["status"].present? && selected_filters["status"].include?(filter.to_s) |
||||||
|
end |
||||||
|
end |
@ -1,61 +1,88 @@ |
|||||||
<figure class="app-figure"> |
<div class="govuk-grid-row"> |
||||||
<figcaption id="<%= title.dasherize %>" class="app-figure__caption"> |
<div class="govuk-grid-column-one-quarter"> |
||||||
<span class="govuk-!-margin-right-4"> |
<div class="app-filter"> |
||||||
<strong><%= pagy.count %></strong> total <%= title.downcase %> |
<div class="app-filter__header"> |
||||||
</span> |
<h2 class="govuk-heading-m">Filters</h2> |
||||||
<a class="govuk-link" download href="/logs.csv" type="text/csv">Download (CSV)</a> |
</div> |
||||||
</figcaption> |
<div class="app-filter__content"> |
||||||
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> |
<div class="govuk-form-group app-filter__group"> |
||||||
<table class="govuk-table"> |
<%= form_with url: "/logs/filter", html: { method: :post }, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> |
||||||
<thead class="govuk-table__head"> |
<%= f.govuk_check_boxes_fieldset :status do %> |
||||||
<tr class="govuk-table__row"> |
<% statuses = {in_progress: "In progress", submitted: "Completed", archived: "Not started"} %> |
||||||
<th class="govuk-table__header" scope="col">Log</th> |
<% statuses.map do |key, option| %> |
||||||
<th class="govuk-table__header" scope="col">Tenant</th> |
<%= f.govuk_check_box "status", "#{key}", |
||||||
<th class="govuk-table__header" scope="col">Property</th> |
label: { text: option }, |
||||||
<th class="govuk-table__header" scope="col">Tenancy starts</th> |
checked: filter_selected?(key), |
||||||
<th class="govuk-table__header" scope="col">Log created</th> |
class: "govuk-checkboxes govuk-checkboxes--small" %> |
||||||
<th class="govuk-table__header" scope="col">Completed</th> |
<% end %> |
||||||
<% if current_user.support? %> |
<% end %> |
||||||
<th class="govuk-table__header" scope="col">Owning organisation</th> |
<%= f.govuk_submit "Apply filters"%> |
||||||
<th class="govuk-table__header" scope="col">Managing organisation</th> |
|
||||||
<% end %> |
<% end %> |
||||||
</tr> |
</div> |
||||||
</thead> |
</div> |
||||||
<tbody class="govuk-table__body"> |
</div> |
||||||
<% case_logs.map do |log| %> |
</div> |
||||||
<tr class="govuk-table__row"> |
<div class="govuk-grid-column-three-quarters"> |
||||||
<th class="govuk-table__header" scope="row"> |
<figure class="app-figure"> |
||||||
<%= govuk_link_to log.id, case_log_path(log) %> |
<figcaption id="<%= title.dasherize %>" class="app-figure__caption"> |
||||||
</th> |
<span class="govuk-!-margin-right-4"> |
||||||
<td class="govuk-table__cell app-!-font-tabular"> |
<strong><%= pagy.count %></strong> total <%= title.downcase %> |
||||||
<%= log.tenant_code? ? log.tenant_code : '–' %> |
</span> |
||||||
</td> |
<a class="govuk-link" download href="/logs.csv" type="text/csv">Download (CSV)</a> |
||||||
<td class="govuk-table__cell app-!-font-tabular"> |
</figcaption> |
||||||
<%= log.propcode? ? log.propcode : '–' %> |
<section class="app-table-group" tabindex="0" aria-labelledby="<%= title.dasherize %>"> |
||||||
</td> |
<table class="govuk-table"> |
||||||
<td class="govuk-table__cell"> |
<thead class="govuk-table__head"> |
||||||
<%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : '–' %> |
<tr class="govuk-table__row"> |
||||||
</td> |
<th class="govuk-table__header" scope="col">Log</th> |
||||||
<td class="govuk-table__cell"> |
<th class="govuk-table__header" scope="col">Tenant</th> |
||||||
<%= log.created_at.to_formatted_s(:govuk_date) %> |
<th class="govuk-table__header" scope="col">Property</th> |
||||||
</td> |
<th class="govuk-table__header" scope="col">Tenancy starts</th> |
||||||
<td class="govuk-table__cell"> |
<th class="govuk-table__header" scope="col">Log created</th> |
||||||
<%= govuk_tag( |
<th class="govuk-table__header" scope="col">Completed</th> |
||||||
colour: log.status == 'completed' ? 'blue' : 'grey', |
<% if current_user.support? %> |
||||||
text: log.status.humanize |
<th class="govuk-table__header" scope="col">Owning organisation</th> |
||||||
) %> |
<th class="govuk-table__header" scope="col">Managing organisation</th> |
||||||
</td> |
<% end %> |
||||||
<% if current_user.support? %> |
</tr> |
||||||
<td class="govuk-table__cell"> |
</thead> |
||||||
<%= log.owning_organisation.name %> |
<tbody class="govuk-table__body"> |
||||||
</td> |
<% case_logs.map do |log| %> |
||||||
<td class="govuk-table__cell"> |
<tr class="govuk-table__row"> |
||||||
<%= log.managing_organisation.name %> |
<th class="govuk-table__header" scope="row"> |
||||||
</td> |
<%= govuk_link_to log.id, case_log_path(log) %> |
||||||
<% end %> |
</th> |
||||||
</tr> |
<td class="govuk-table__cell app-!-font-tabular"> |
||||||
<% end %> |
<%= log.tenant_code? ? log.tenant_code : '–' %> |
||||||
</tbody> |
</td> |
||||||
</table> |
<td class="govuk-table__cell app-!-font-tabular"> |
||||||
</section> |
<%= log.propcode? ? log.propcode : '–' %> |
||||||
</figure> |
</td> |
||||||
|
<td class="govuk-table__cell"> |
||||||
|
<%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : '–' %> |
||||||
|
</td> |
||||||
|
<td class="govuk-table__cell"> |
||||||
|
<%= log.created_at.to_formatted_s(:govuk_date) %> |
||||||
|
</td> |
||||||
|
<td class="govuk-table__cell"> |
||||||
|
<%= govuk_tag( |
||||||
|
colour: log.status == 'completed' ? 'blue' : 'grey', |
||||||
|
text: log.status.humanize |
||||||
|
) %> |
||||||
|
</td> |
||||||
|
<% if current_user.support? %> |
||||||
|
<td class="govuk-table__cell"> |
||||||
|
<%= log.owning_organisation.name %> |
||||||
|
</td> |
||||||
|
<td class="govuk-table__cell"> |
||||||
|
<%= log.managing_organisation.name %> |
||||||
|
</td> |
||||||
|
<% end %> |
||||||
|
</tr> |
||||||
|
<% end %> |
||||||
|
</tbody> |
||||||
|
</table> |
||||||
|
</section> |
||||||
|
</figure> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
@ -0,0 +1,26 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe FiltersHelper do |
||||||
|
describe "#filter_selected?" do |
||||||
|
context "when no filters are selected" do |
||||||
|
it "returns true for all filters" do |
||||||
|
expect(filter_selected?("completed")).to be_truthy |
||||||
|
expect(filter_selected?("in_progress")).to be_truthy |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "one filter is selected" do |
||||||
|
before do |
||||||
|
cookies[:case_logs_filters] = { "status": "in_progress" }.to_json |
||||||
|
end |
||||||
|
|
||||||
|
it "returns false for non selected filters" do |
||||||
|
expect(filter_selected?("completed")).to be_falsey |
||||||
|
end |
||||||
|
|
||||||
|
it "returns true for selected filter" do |
||||||
|
expect(filter_selected?("in_progress")).to be_truthy |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue