Skip to content

Commit

Permalink
Merge pull request #1689 from DFE-Digital/application-form-stage
Browse files Browse the repository at this point in the history
Add application form stage
  • Loading branch information
thomasleese authored Sep 27, 2023
2 parents 247b051 + fbaa384 commit 1676c9b
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/components/status_tag/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def classes

COLOURS = {
accepted: "green",
assessment: "blue",
assessment_in_progress: "blue",
awarded: "green",
awarded_pending_checks: "turquoise",
Expand All @@ -37,6 +38,7 @@ def classes
overdue_qualification: "pink",
overdue_reference: "pink",
potential_duplicate_in_dqt: "pink",
pre_assessment: "pink",
preliminary_check: "pink",
received: "purple",
received_further_information: "purple",
Expand All @@ -45,8 +47,10 @@ def classes
received_reference: "purple",
rejected: "red",
requested: "yellow",
review: "purple",
submitted: "grey",
valid: "green",
verification: "yellow",
waiting_on: "yellow",
waiting_on_further_information: "yellow",
waiting_on_professional_standing: "yellow",
Expand Down
19 changes: 19 additions & 0 deletions app/components/timeline_entry/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,24 @@ def action_required_by_changed_vars
end,
}
end

def stage_changed_vars
{
old_stage:
render(
StatusTag::Component.new(
status: timeline_event.old_value,
class_context: "timeline-event",
),
).strip,
new_stage:
render(
StatusTag::Component.new(
status: timeline_event.new_value,
class_context: "timeline-event",
),
).strip,
}
end
end
end
43 changes: 43 additions & 0 deletions app/lib/application_form_status_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ def call
new_value: action_required_by,
)
end

if (old_stage = application_form.stage) != stage
application_form.update!(stage:)
create_timeline_event(
event_type: "stage_changed",
old_value: old_stage,
new_value: stage,
)
end
end
end

Expand Down Expand Up @@ -182,6 +191,40 @@ def action_required_by
end
end

def stage
@stage ||=
if application_form.withdrawn_at.present? ||
application_form.declined_at.present? ||
application_form.awarded_at.present?
"completed"
elsif dqt_trn_request.present?
"review"
elsif preliminary_check? ||
(
teaching_authority_provides_written_statement &&
waiting_on_professional_standing
)
"pre_assessment"
elsif overdue_professional_standing || overdue_qualification ||
overdue_reference ||
(
!teaching_authority_provides_written_statement &&
received_professional_standing
) || received_qualification || received_reference ||
waiting_on_professional_standing || waiting_on_qualification ||
waiting_on_reference
"verification"
elsif overdue_further_information || received_further_information ||
waiting_on_further_information ||
assessment&.any_not_preliminary_section_finished?
"assessment"
elsif application_form.submitted_at.present?
"not_started"
else
"draft"
end
end

delegate :assessment,
:dqt_trn_request,
:region,
Expand Down
13 changes: 13 additions & 0 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
# registration_number :text
# registration_number_status :string default("not_started"), not null
# requires_preliminary_check :boolean default(FALSE), not null
# stage :string default("draft"), not null
# status :string default("draft"), not null
# subjects :text default([]), not null, is an Array
# subjects_status :string default("not_started"), not null
Expand Down Expand Up @@ -76,6 +77,7 @@
# index_application_forms_on_reference (reference) UNIQUE
# index_application_forms_on_region_id (region_id)
# index_application_forms_on_reviewer_id (reviewer_id)
# index_application_forms_on_stage (stage)
# index_application_forms_on_status (status)
# index_application_forms_on_teacher_id (teacher_id)
#
Expand Down Expand Up @@ -132,6 +134,17 @@ class ApplicationForm < ApplicationRecord
},
_prefix: true

enum stage: {
draft: "draft",
pre_assessment: "pre_assessment",
not_started: "not_started",
assessment: "assessment",
verification: "verification",
review: "review",
completed: "completed",
},
_suffix: true

enum status: {
draft: "draft",
submitted: "submitted",
Expand Down
11 changes: 9 additions & 2 deletions app/models/timeline_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TimelineEvent < ApplicationRecord
requestable_received: "requestable_received",
requestable_requested: "requestable_requested",
reviewer_assigned: "reviewer_assigned",
stage_changed: "stage_changed",
state_changed: "state_changed",
}

Expand Down Expand Up @@ -152,11 +153,17 @@ class TimelineEvent < ApplicationRecord
validates :old_value,
:new_value,
presence: true,
if: -> { action_required_by_changed? || information_changed? }
if: -> do
action_required_by_changed? || information_changed? ||
stage_changed?
end
validates :old_value,
:new_value,
absence: true,
unless: -> { action_required_by_changed? || information_changed? }
unless: -> do
action_required_by_changed? || information_changed? ||
stage_changed?
end
validates :column_name, presence: true, if: :information_changed?
validates :work_history_id,
:column_name,
Expand Down
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- registration_number_status
- requires_preliminary_check
- reviewer_id
- stage
- status
- subjects
- subjects_status
Expand Down
26 changes: 16 additions & 10 deletions config/locales/components.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ en:
components:
status_tag:
accepted: Accepted
assessment: Assessment
assessment_in_progress: Assessment in progress
awarded: Awarded
awarded_pending_checks: Award pending
Expand All @@ -19,6 +20,7 @@ en:
overdue_qualification: Overdue qualification
overdue_reference: Overdue reference
potential_duplicate_in_dqt: Potential duplication in DQT
pre_assessment: Pre-assessment
preliminary_check: Preliminary check
received: Received
received_further_information: Received further information
Expand All @@ -27,8 +29,10 @@ en:
received_reference: Received reference
rejected: Rejected
requested: Waiting on
review: Review
submitted: Not started
valid: Valid
verification: Verification
waiting_on: Waiting on
waiting_on_further_information: Waiting on further information
waiting_on_professional_standing: Waiting on professional standing
Expand All @@ -39,14 +43,14 @@ en:
timeline_entry:
title:
action_required_by_changed: Action required by changed
assessor_assigned: Assessor assigned
reviewer_assigned: Reviewer assigned
state_changed: Status changed
assessment_section_completed: Section completed
note_created: Note created
email_sent: Email sent
age_range_subjects_verified: Age range and subjects verified
assessment_section_completed: Section completed
assessment_section_recorded: Assessment section recorded
assessor_assigned: Assessor assigned
email_sent: Email sent
information_changed: Information changed after submission
note_created: Note created
reviewer_assigned: Reviewer assigned
requestable_requested:
FurtherInformationRequest: Further information requested
ProfessionalStandingRequest: Professional standing requested
Expand All @@ -67,14 +71,14 @@ en:
ProfessionalStandingRequest: Professional standing assessed
QualificationRequest: Qualification assessed
ReferenceRequest: Reference assessed
information_changed: Information changed after submission
stage_changed: Stage changed
state_changed: Status changed
description:
action_required_by_changed: Application requires %{action} action.
assessor_assigned: "%{assignee_name} is assigned as the assessor."
reviewer_assigned: "%{assignee_name} is assigned as the reviewer."
state_changed: Status changed from %{old_state} to %{new_state}.
note_created: "%{text}"
email_sent: "%{subject}"
note_created: "%{text}"
reviewer_assigned: "%{assignee_name} is assigned as the reviewer."
requestable_requested:
FurtherInformationRequest: Further information has been requested.
ProfessionalStandingRequest: The professional standing has been requested.
Expand All @@ -95,6 +99,8 @@ en:
ProfessionalStandingRequest: The professional standing request has been assessed.
QualificationRequest: A qualification has been assessed.
ReferenceRequest: A reference has been assessed.
stage_changed: Stage changed from %{old_stage} to %{new_stage}.
state_changed: Status changed from %{old_state} to %{new_state}.
columns:
contact_email: Reference email address
contact_job: Reference job
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20230914084340_add_stage_to_application_forms.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddStageToApplicationForms < ActiveRecord::Migration[7.0]
def change
add_column :application_forms,
:stage,
:string,
default: "draft",
null: false
add_index :application_forms, :stage
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions spec/components/timeline_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,4 +518,24 @@
expect(component.text).to include(creator.name)
end
end

context "stage changed" do
let(:timeline_event) { create(:timeline_event, :stage_changed) }
let(:old_stage) do
I18n.t("components.status_tag.#{timeline_event.old_value}")
end
let(:new_stage) do
I18n.t("components.status_tag.#{timeline_event.new_value}")
end

it "describes the event" do
expect(component.text.squish).to include(
"Stage changed from #{old_stage} to #{new_stage}",
)
end

it "attributes to the creator" do
expect(component.text).to include(creator.name)
end
end
end
Loading

0 comments on commit 1676c9b

Please sign in to comment.