Skip to content

Commit

Permalink
feat(cms): next key date
Browse files Browse the repository at this point in the history
Jira: PWNN-1234
  • Loading branch information
EdwinKruglov committed Aug 14, 2023
1 parent 44a0c55 commit a388ec4
Show file tree
Hide file tree
Showing 45 changed files with 684 additions and 510 deletions.
13 changes: 11 additions & 2 deletions app/controllers/support/cases/quick_edits_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Support
module Cases
class QuickEditsController < Cases::ApplicationController
include Concerns::HasDateParams

before_action :back_url, only: %i[edit update]
helper_method :back_to_param

Expand All @@ -9,7 +11,7 @@ def edit
end

def update
@case_quick_edit = current_case.quick_editor(form_params)
@case_quick_edit = current_case.quick_editor(quick_edit_params)

if @case_quick_edit.valid?
@case_quick_edit.save!
Expand All @@ -33,8 +35,15 @@ def back_to_param
params[:back_to] || params.dig(:case_quick_edit, :back_to)
end

def quick_edit_params
form_params
.except("next_key_date(3i)", "next_key_date(2i)", "next_key_date(1i)")
.merge(next_key_date: date_param(:case_quick_edit, :next_key_date).compact_blank)
.compact_blank
end

def form_params
params.require(:case_quick_edit).permit(:note, :support_level, :procurement_stage_id, :with_school)
params.require(:case_quick_edit).permit(:note, :support_level, :procurement_stage_id, :with_school, :next_key_date, :next_key_date_description)
end
end
end
Expand Down
42 changes: 20 additions & 22 deletions app/controllers/support/cases/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ module Support
class Cases::SummariesController < ::Support::Cases::ApplicationController
before_action :set_back_url

include Concerns::HasDateParams

def edit
@case_summary_form = case_summary_form
@case_summary = fields_pre_filled_in_params? ? current_case.summary(summary_params) : current_case.summary
@case_summary.validate
end

def update
@case_summary_form = RequestDetailsFormPresenter.new(case_summary_form)
@case_summary = CaseSummaryPresenter.new(current_case.summary(summary_params))

if validation.success?
if @case_summary.valid?
return render :update if submit_action == "confirm"
return render :edit if submit_action == "change"

@case_summary_form.update_case_summary_details(kase: @current_case, agent_id: current_agent.id)
@case_summary.save!

redirect_to support_case_path(@current_case, anchor: "case-details")
else
Expand All @@ -25,7 +28,7 @@ def update

def set_back_url
@back_url = if submit_action == "confirm"
edit_support_case_summary_path(@current_case, case_summary_form: validation.to_h)
edit_support_case_summary_path(@current_case, case_summary: form_params)
else
support_case_path(@current_case, anchor: "case-details")
end
Expand All @@ -35,28 +38,21 @@ def submit_action
params[:button]
end

def validation
CaseSummaryFormSchema.new.call(**case_summary_form_params)
end

def case_summary_form
form = if fields_pre_filled_in_params?
CaseSummaryForm.from_validation(validation)
else
CaseSummaryForm.from_case(@current_case)
end
form.agent_id = current_agent.id
form
end

def fields_pre_filled_in_params?
case_summary_form_params.present?
form_params.present?
rescue ActionController::ParameterMissing
false
end

def case_summary_form_params
params.require(:case_summary_form).permit(
def summary_params
form_params
.except("next_key_date(3i)", "next_key_date(2i)", "next_key_date(1i)")
.merge(next_key_date: date_param(:case_summary, :next_key_date).compact_blank)
.compact_blank
end

def form_params
params.require(:case_summary).permit(
:request_text,
:request_type,
:category_id,
Expand All @@ -67,6 +63,8 @@ def case_summary_form_params
:value,
:support_level,
:procurement_stage_id,
:next_key_date,
:next_key_date_description,
:submit,
)
end
Expand Down
48 changes: 0 additions & 48 deletions app/cores/case_history/handle_case_state_changes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ def case_contact_details_changed(payload)
record_state_change("Case contact details changed", payload)
end

def case_source_changed(payload)
record_state_change("Source changed", payload)
end

def case_value_changed(payload)
record_state_change("Case value changed", payload)
end

def case_categorisation_changed(payload)
if payload[:category_id].present? && payload[:query_id].present?
record_change_of_category_and_query(payload)
elsif payload[:category_id].present?
record_change_of_category(payload)
elsif payload[:query_id].present?
record_change_of_query(payload)
end
end

private

def record_state_change(reason, payload)
Expand All @@ -81,35 +63,5 @@ def record_state_change(reason, payload)
def additional_data_from(payload)
payload.except(:case_id, :agent_id).merge({ format_version: "2" })
end

def record_change_of_category(payload)
from, to = payload[:category_id]
record_categorisation_change(from:, to:, type: :category, case_id: payload[:case_id], agent_id: payload[:agent_id])
end

def record_change_of_query(payload)
from, to = payload[:query_id]
record_categorisation_change(from:, to:, type: :query, case_id: payload[:case_id], agent_id: payload[:agent_id])
end

def record_change_of_category_and_query(payload)
category_from, category_to = payload[:category_id]
query_from, query_to = payload[:query_id]

if category_from.present? && category_to.nil? && query_to.present?
record_categorisation_change(from: category_from, to: query_to, type: :category_to_query, case_id: payload[:case_id], agent_id: payload[:agent_id])
elsif query_from.present? && query_to.nil? && category_to.present?
record_categorisation_change(from: query_from, to: category_to, type: :query_to_category, case_id: payload[:case_id], agent_id: payload[:agent_id])
end
end

def record_categorisation_change(from:, to:, type:, case_id:, agent_id:)
Support::Interaction.case_categorisation_changed.create!(
case_id:,
additional_data: { from:, to:, type: },
agent_id:,
body: "Categorisation change",
)
end
end
end
62 changes: 0 additions & 62 deletions app/cores/case_management/update_case_summary_details.rb

This file was deleted.

58 changes: 0 additions & 58 deletions app/forms/support/case_summary_form.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/forms/support/case_summary_form_schema.rb

This file was deleted.

7 changes: 7 additions & 0 deletions app/helpers/support/case_summary_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Support
module CaseSummaryHelper
def available_sources
I18nOption.from("support.case.label.source.%%key%%", Support::Case.sources.keys)
end
end
end
1 change: 1 addition & 0 deletions app/helpers/support/sort_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def available_sort_options
[I18n.t("support.case.label.category"), "subcategory"],
[I18n.t("support.case.label.status"), "state"],
[I18n.t("support.case.label.updated"), "last_updated"],
[I18n.t("support.case.label.key_action_date"), "next_key_date"],
]
end

Expand Down
1 change: 1 addition & 0 deletions app/models/support/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Case < ApplicationRecord
include ActivityLoggable
include Historyable
include QuickEditable
include Summarisable

belongs_to :category, class_name: "Support::Category", optional: true
belongs_to :query, class_name: "Support::Query", optional: true
Expand Down
Loading

0 comments on commit a388ec4

Please sign in to comment.