diff --git a/app/controllers/admin/claims_controller.rb b/app/controllers/admin/claims_controller.rb index 6f26e3cb2a..9787b588ea 100644 --- a/app/controllers/admin/claims_controller.rb +++ b/app/controllers/admin/claims_controller.rb @@ -5,23 +5,15 @@ class Admin::ClaimsController < Admin::BaseAdminController def index @filter_form = Admin::ClaimsFilterForm.new( - team_member: params[:team_member], - policy: params[:policy], - status: params[:status] + filters: filter_params, + session: ) + @filter_form.save_to_session! - @total_claim_count = @filter_form.count @pagy, @claims = pagy(@filter_form.claims) respond_to do |format| - format.html { - claims_backlink_path!(admin_claims_path( - team_member: params[:team_member], - policy: params[:policy], - status: params[:status], - commit: params[:commit] - )) - } + format.html format.csv { # "Download report request file" button (doesn't use the filters) report_request_claims = Claim.includes(:decisions).awaiting_decision @@ -82,4 +74,10 @@ def claims_backlink_path!(source_path) def hold_params params.require(:hold).permit(:body).merge(claim: @claim) end + + def filter_params + params + .fetch(:filter, {}) + .permit(:team_member, :policy, :status, :reset) + end end diff --git a/app/forms/admin/claims_filter_form.rb b/app/forms/admin/claims_filter_form.rb index 524874e267..9e37bb314e 100644 --- a/app/forms/admin/claims_filter_form.rb +++ b/app/forms/admin/claims_filter_form.rb @@ -2,9 +2,40 @@ class Admin::ClaimsFilterForm include ActiveModel::Model include ActiveModel::Attributes - attribute :team_member, :string - attribute :policy, :string - attribute :status, :string + attribute :filters + attribute :session + + def initialize(args) + super + + session[:filter] ||= {} + end + + def team_member + return if reset? + + @team_member ||= filters[:team_member] || session[:filter]["team_member"] + end + + def policy + return if reset? + + @policy ||= filters[:policy] || session[:filter]["policy"] + end + + def status + return if reset? + + @status ||= filters[:status] || session[:filter]["status"] + end + + def filters_applied? + team_member.present? || policy.present? || status.present? + end + + def reset? + filters[:reset].present? + end def claims return @claims if @claims @@ -45,6 +76,47 @@ def count claims.count end + def policy_select_options + array = [OpenStruct.new(id: nil, name: "All")] + + array + Policies.all.map do |policy| + OpenStruct.new(id: policy.policy_type, name: policy.short_name) + end + end + + def status_select_options + [ + ["Awaiting decision - not on hold", nil], + ["Awaiting provider verification", "awaiting_provider_verification"], + ["Awaiting decision - on hold", "held"], + ["Awaiting decision - failed bank details", "failed_bank_validation"], + ["Approved awaiting QA", "approved_awaiting_qa"], + ["Approved awaiting payroll", "approved_awaiting_payroll"], + ["Automatically approved awaiting payroll", "automatically_approved_awaiting_payroll"], + ["Approved", "approved"], + ["Rejected", "rejected"] + ].map do |name, id| + OpenStruct.new(id:, name:) + end + end + + def team_member_select_options + array = [["All", nil], ["Unassigned", "unassigned"]] + array += DfeSignIn::User.options_for_select + + array.map do |name, id| + OpenStruct.new(id:, name:) + end + end + + def save_to_session! + session[:filter] = { + team_member:, + policy:, + status: + } + end + private def approved_awaiting_payroll diff --git a/app/helpers/admin/claims_helper.rb b/app/helpers/admin/claims_helper.rb index 37c76943d7..49e98b2c2b 100644 --- a/app/helpers/admin/claims_helper.rb +++ b/app/helpers/admin/claims_helper.rb @@ -189,21 +189,6 @@ def status(claim) end end - STATUS_FILTERS = [ - ["Awaiting provider verification", "awaiting_provider_verification"], - ["Awaiting decision - on hold", "held"], - ["Awaiting decision - failed bank details", "failed_bank_validation"], - ["Approved awaiting QA", "approved_awaiting_qa"], - ["Approved awaiting payroll", "approved_awaiting_payroll"], - ["Automatically approved awaiting payroll", "automatically_approved_awaiting_payroll"], - ["Approved", "approved"], - ["Rejected", "rejected"] - ] - - def claim_status_filters - STATUS_FILTERS - end - def index_status_filter(status) return "awaiting a decision" unless status.present? diff --git a/app/views/admin/claims/index.html.erb b/app/views/admin/claims/index.html.erb index 2d50ef1ff0..4802e5db41 100644 --- a/app/views/admin/claims/index.html.erb +++ b/app/views/admin/claims/index.html.erb @@ -18,34 +18,29 @@ <%= render "allocations_form" %> -