diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb
index 03000dfca..19d12b774 100644
--- a/app/controllers/case_logs_controller.rb
+++ b/app/controllers/case_logs_controller.rb
@@ -7,7 +7,7 @@ class CaseLogsController < ApplicationController
before_action :find_resource, except: %i[create index edit]
def index
- @pagy, @case_logs = pagy(current_user.case_logs)
+ @pagy, @case_logs = pagy(filtered_case_logs)
respond_to do |format|
format.html
@@ -78,6 +78,11 @@ class CaseLogsController < ApplicationController
end
end
+ def filter
+ cookies[:case_logs_filters] = { status: params[:status] }.to_json
+ redirect_back(fallback_location: root_path)
+ end
+
private
API_ACTIONS = %w[create show update destroy].freeze
@@ -117,4 +122,12 @@ private
def find_resource
@case_log = CaseLog.find_by(id: params[:id])
end
+
+ def filtered_case_logs
+ user_case_logs = current_user.case_logs
+ status_filter = JSON.parse(cookies[:case_logs_filters])["status"] if cookies[:case_logs_filters].present?
+ return user_case_logs unless status_filter
+
+ user_case_logs.filter_by_status(status_filter)
+ end
end
diff --git a/app/helpers/filters_helper.rb b/app/helpers/filters_helper.rb
new file mode 100644
index 000000000..aaebeba57
--- /dev/null
+++ b/app/helpers/filters_helper.rb
@@ -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
diff --git a/app/models/case_log.rb b/app/models/case_log.rb
index 6b602362f..aa926d5b4 100644
--- a/app/models/case_log.rb
+++ b/app/models/case_log.rb
@@ -34,6 +34,7 @@ class CaseLog < ApplicationRecord
belongs_to :managing_organisation, class_name: "Organisation"
scope :for_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) }
+ scope :filter_by_status, ->(status) { where status: status }
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze
diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb
index 3cb30289f..bf171cf51 100644
--- a/app/views/case_logs/_log_list.html.erb
+++ b/app/views/case_logs/_log_list.html.erb
@@ -1,61 +1,88 @@
-
-
-
-
-
-
-
- <% case_logs.map do |log| %>
- Log
- Tenant
- Property
- Tenancy starts
- Log created
- Completed
- <% if current_user.support? %>
- Owning organisation
- Managing organisation
+Filters
+
-
- <% end %>
-
-
- <%= govuk_link_to log.id, case_log_path(log) %>
-
-
- <%= log.tenant_code? ? log.tenant_code : '–' %>
-
-
- <%= log.propcode? ? log.propcode : '–' %>
-
-
- <%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : '–' %>
-
-
- <%= log.created_at.to_formatted_s(:govuk_date) %>
-
-
- <%= govuk_tag(
- colour: log.status == 'completed' ? 'blue' : 'grey',
- text: log.status.humanize
- ) %>
-
- <% if current_user.support? %>
-
- <%= log.owning_organisation.name %>
-
-
- <%= log.managing_organisation.name %>
-
- <% end %>
-
Log | +Tenant | +Property | +Tenancy starts | +Log created | +Completed | + <% if current_user.support? %> +Owning organisation | +Managing organisation | + <% end %> +
---|---|---|---|---|---|---|---|
+ <%= govuk_link_to log.id, case_log_path(log) %> + | ++ <%= log.tenant_code? ? log.tenant_code : '–' %> + | ++ <%= log.propcode? ? log.propcode : '–' %> + | ++ <%= log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : '–' %> + | ++ <%= log.created_at.to_formatted_s(:govuk_date) %> + | ++ <%= govuk_tag( + colour: log.status == 'completed' ? 'blue' : 'grey', + text: log.status.humanize + ) %> + | + <% if current_user.support? %> ++ <%= log.owning_organisation.name %> + | ++ <%= log.managing_organisation.name %> + | + <% end %> +