From 971741ac89328814c58bfa5b6e67cd99713bb610 Mon Sep 17 00:00:00 2001 From: Edwin Kruglov Date: Tue, 31 Oct 2023 13:46:50 +0000 Subject: [PATCH] feat(fworks): quick edit framework evaluations --- app/controllers/concerns/has_date_params.rb | 15 +++ .../contract_start_dates_controller.rb | 2 +- .../frameworks/application_controller.rb | 2 +- .../evaluation_contacts_controller.rb | 2 - .../evaluations/contacts_controller.rb | 5 + .../evaluations/quick_edits_controller.rb | 47 ++++++++ .../frameworks/evaluations_controller.rb | 19 +++- .../support/cases/contracts_controller.rb | 2 +- .../cases/procurement_details_controller.rb | 2 +- .../support/cases/quick_edits_controller.rb | 2 +- .../support/cases/summaries_controller.rb | 2 +- .../support/concerns/has_date_params.rb | 19 ---- .../validation/has_next_key_date.rb | 2 +- app/models/frameworks/activity_event.rb | 2 + app/models/frameworks/evaluation.rb | 2 + app/models/frameworks/evaluation/noteable.rb | 18 +++ .../frameworks/evaluation/presentable.rb | 6 + .../frameworks/evaluation/quick_editable.rb | 14 +++ .../frameworks/evaluation/quick_editor.rb | 15 +++ app/models/support/case/quick_editor.rb | 2 +- app/models/support/case/summary.rb | 2 +- .../activity_log_items/_history.html.erb | 4 +- .../evaluations/_evaluation_started.html.erb | 0 .../evaluations/_note_added.html.erb | 7 ++ .../frameworks/_category_added.html.erb | 4 +- .../frameworks/_evaluation_started.html.erb | 6 +- .../evaluations/_evaluation.html.erb | 104 ++++++++++++------ .../frameworks/evaluations/_form.html.erb | 21 ++++ .../frameworks/evaluations/edit.html.erb | 8 ++ app/views/frameworks/evaluations/new.html.erb | 15 +-- .../evaluations/quick_edits/edit.html.erb | 22 ++++ .../frameworks/evaluations/show.html.erb | 4 +- .../evaluations/show/_framework.html.erb | 4 +- config/locales/en.yml | 5 + config/locales/validation/support/en.yml | 4 + config/routes.rb | 1 + ...d_description_to_frameworks_evaluations.rb | 8 ++ db/schema.rb | 4 +- ...nt_can_create_framework_evaluation_spec.rb | 2 +- ...an_quick_edit_framework_evaluation_spec.rb | 29 +++++ ...ent_can_browse_frameworks_register_spec.rb | 1 - .../agent_can_categorise_framework_spec.rb | 5 +- .../case/validation/has_next_key_date_spec.rb | 2 +- 43 files changed, 346 insertions(+), 96 deletions(-) create mode 100644 app/controllers/concerns/has_date_params.rb delete mode 100644 app/controllers/frameworks/evaluation_contacts_controller.rb create mode 100644 app/controllers/frameworks/evaluations/contacts_controller.rb create mode 100644 app/controllers/frameworks/evaluations/quick_edits_controller.rb delete mode 100644 app/controllers/support/concerns/has_date_params.rb rename app/models/{support/case => concerns}/validation/has_next_key_date.rb (91%) create mode 100644 app/models/frameworks/evaluation/noteable.rb create mode 100644 app/models/frameworks/evaluation/quick_editable.rb create mode 100644 app/models/frameworks/evaluation/quick_editor.rb delete mode 100644 app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_evaluation_started.html.erb create mode 100644 app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_note_added.html.erb create mode 100644 app/views/frameworks/evaluations/_form.html.erb create mode 100644 app/views/frameworks/evaluations/edit.html.erb create mode 100644 app/views/frameworks/evaluations/quick_edits/edit.html.erb create mode 100644 db/migrate/20231027145735_add_next_key_date_and_description_to_frameworks_evaluations.rb create mode 100644 spec/features/frameworks/evaluations/agent_can_quick_edit_framework_evaluation_spec.rb diff --git a/app/controllers/concerns/has_date_params.rb b/app/controllers/concerns/has_date_params.rb new file mode 100644 index 000000000..260a6af7f --- /dev/null +++ b/app/controllers/concerns/has_date_params.rb @@ -0,0 +1,15 @@ +# Parse date fields as Dates +# +# Useful for extracting dates out of govuk_date_fields +module HasDateParams + extend ActiveSupport::Concern + + # @param form_param [Symbol] + # @param date_field [Symbol] + # + # @return [Hash] + def date_param(form_param, date_field) + date = params.fetch(form_param, {}).permit(date_field) + { day: date["#{date_field}(3i)"], month: date["#{date_field}(2i)"], year: date["#{date_field}(1i)"] } + end +end diff --git a/app/controllers/framework_requests/contract_start_dates_controller.rb b/app/controllers/framework_requests/contract_start_dates_controller.rb index 63dc0794d..b1195283a 100644 --- a/app/controllers/framework_requests/contract_start_dates_controller.rb +++ b/app/controllers/framework_requests/contract_start_dates_controller.rb @@ -1,6 +1,6 @@ module FrameworkRequests class ContractStartDatesController < BaseController - include Support::Concerns::HasDateParams + include HasDateParams skip_before_action :authenticate_user! diff --git a/app/controllers/frameworks/application_controller.rb b/app/controllers/frameworks/application_controller.rb index dcb0564e0..118248493 100644 --- a/app/controllers/frameworks/application_controller.rb +++ b/app/controllers/frameworks/application_controller.rb @@ -8,6 +8,6 @@ def authorize_agent_scope = :access_frameworks_portal? def portal_namespace = :frameworks def set_back_url - @back_url = back_link_param if back_link_param.present? + @back_url = back_link_param || request.referer end end diff --git a/app/controllers/frameworks/evaluation_contacts_controller.rb b/app/controllers/frameworks/evaluation_contacts_controller.rb deleted file mode 100644 index 1ea0bd09f..000000000 --- a/app/controllers/frameworks/evaluation_contacts_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class Frameworks::EvaluationContactsController < Frameworks::ApplicationController -end diff --git a/app/controllers/frameworks/evaluations/contacts_controller.rb b/app/controllers/frameworks/evaluations/contacts_controller.rb new file mode 100644 index 000000000..ee38515c8 --- /dev/null +++ b/app/controllers/frameworks/evaluations/contacts_controller.rb @@ -0,0 +1,5 @@ +class Frameworks::Evaluations::ContactsController < Frameworks::ApplicationController + def edit; end + + def update; end +end diff --git a/app/controllers/frameworks/evaluations/quick_edits_controller.rb b/app/controllers/frameworks/evaluations/quick_edits_controller.rb new file mode 100644 index 000000000..f06cb125b --- /dev/null +++ b/app/controllers/frameworks/evaluations/quick_edits_controller.rb @@ -0,0 +1,47 @@ +class Frameworks::Evaluations::QuickEditsController < Frameworks::ApplicationController + include HasDateParams + + before_action :evaluation, only: %i[edit update] + + def edit + @quick_edit = @evaluation.quick_editor + end + + def update + @quick_edit = @evaluation.quick_editor(**quick_edit_params) + + if @quick_edit.valid? + @quick_edit.save! + + redirect_to(after_update_redirect_path, notice: "Evaluation updated") + else + render :edit + end + end + +private + + def after_update_redirect_path + if params[:redirect_back].present? + Base64.decode64(params[:redirect_back]) + else + frameworks_root_path(anchor: "evaluations") + end + end + + def evaluation + @evaluation = Frameworks::Evaluation.find(params[:evaluation_id]) + 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(:quick_edit, :next_key_date).compact_blank) + .to_h + .symbolize_keys + end + + def form_params + params.require(:quick_edit).permit(:note, :next_key_date, :next_key_date_description) + end +end diff --git a/app/controllers/frameworks/evaluations_controller.rb b/app/controllers/frameworks/evaluations_controller.rb index 4bdf2e547..ef385a23e 100644 --- a/app/controllers/frameworks/evaluations_controller.rb +++ b/app/controllers/frameworks/evaluations_controller.rb @@ -1,6 +1,6 @@ class Frameworks::EvaluationsController < Frameworks::ApplicationController before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index - before_action :set_form_options, only: %i[new create] + before_action :set_form_options, only: %i[new edit create update] content_security_policy do |policy| policy.style_src_attr :unsafe_inline @@ -30,11 +30,26 @@ def create end end + def edit + @evaluation = Frameworks::Evaluation.find(params[:id]) + end + + def update + @evaluation = Frameworks::Evaluation.find(params[:id]) + + if @evaluation.update(evaluation_params) + redirect_to @evaluation + else + render :edit + end + end + private def set_form_options @frameworks = Frameworks::Framework.for_evaluation @agents = Support::Agent.framework_evaluators + @contacts = Frameworks::ProviderContact.all end def filter_form_params @@ -45,7 +60,7 @@ def filter_form_params end def evaluation_params - params.require(:frameworks_evaluation).permit(:framework_id, :assignee_id) + params.require(:frameworks_evaluation).permit(:framework_id, :assignee_id, :contact_id) end def redirect_to_register_tab diff --git a/app/controllers/support/cases/contracts_controller.rb b/app/controllers/support/cases/contracts_controller.rb index fae5114e4..ee97f377a 100644 --- a/app/controllers/support/cases/contracts_controller.rb +++ b/app/controllers/support/cases/contracts_controller.rb @@ -2,7 +2,7 @@ module Support class Cases::ContractsController < Cases::ApplicationController before_action :set_back_url, only: %i[edit update] - include Concerns::HasDateParams + include HasDateParams include Concerns::HasInteraction def edit diff --git a/app/controllers/support/cases/procurement_details_controller.rb b/app/controllers/support/cases/procurement_details_controller.rb index eb1db7af7..98251ab05 100644 --- a/app/controllers/support/cases/procurement_details_controller.rb +++ b/app/controllers/support/cases/procurement_details_controller.rb @@ -2,7 +2,7 @@ module Support class Cases::ProcurementDetailsController < Cases::ApplicationController before_action :set_back_url, :set_enums - include Concerns::HasDateParams + include HasDateParams include Concerns::HasInteraction def edit diff --git a/app/controllers/support/cases/quick_edits_controller.rb b/app/controllers/support/cases/quick_edits_controller.rb index 5bf4ba25f..593399022 100644 --- a/app/controllers/support/cases/quick_edits_controller.rb +++ b/app/controllers/support/cases/quick_edits_controller.rb @@ -1,7 +1,7 @@ module Support module Cases class QuickEditsController < Cases::ApplicationController - include Concerns::HasDateParams + include HasDateParams before_action :back_url, only: %i[edit update] helper_method :back_to_param diff --git a/app/controllers/support/cases/summaries_controller.rb b/app/controllers/support/cases/summaries_controller.rb index 817fffce8..a932ec556 100644 --- a/app/controllers/support/cases/summaries_controller.rb +++ b/app/controllers/support/cases/summaries_controller.rb @@ -2,7 +2,7 @@ module Support class Cases::SummariesController < ::Support::Cases::ApplicationController before_action :set_back_url - include Concerns::HasDateParams + include HasDateParams def edit @case_summary = fields_pre_filled_in_params? ? current_case.summary(summary_params) : current_case.summary diff --git a/app/controllers/support/concerns/has_date_params.rb b/app/controllers/support/concerns/has_date_params.rb deleted file mode 100644 index 4ace263d9..000000000 --- a/app/controllers/support/concerns/has_date_params.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Parse date fields as Dates -# -# Useful for extracting dates out of govuk_date_fields -module Support - module Concerns - module HasDateParams - extend ActiveSupport::Concern - - # @param form_param [Symbol] - # @param date_field [Symbol] - # - # @return [Hash] - def date_param(form_param, date_field) - date = params.fetch(form_param, {}).permit(date_field) - { day: date["#{date_field}(3i)"], month: date["#{date_field}(2i)"], year: date["#{date_field}(1i)"] } - end - end - end -end diff --git a/app/models/support/case/validation/has_next_key_date.rb b/app/models/concerns/validation/has_next_key_date.rb similarity index 91% rename from app/models/support/case/validation/has_next_key_date.rb rename to app/models/concerns/validation/has_next_key_date.rb index ee957aa31..4322f4b64 100644 --- a/app/models/support/case/validation/has_next_key_date.rb +++ b/app/models/concerns/validation/has_next_key_date.rb @@ -1,4 +1,4 @@ -module Support::Case::Validation::HasNextKeyDate +module Validation::HasNextKeyDate extend ActiveSupport::Concern included do diff --git a/app/models/frameworks/activity_event.rb b/app/models/frameworks/activity_event.rb index cb19aba88..e0689d030 100644 --- a/app/models/frameworks/activity_event.rb +++ b/app/models/frameworks/activity_event.rb @@ -1,6 +1,8 @@ class Frameworks::ActivityEvent < ApplicationRecord include Frameworks::Activity + scope :added_notes, ->(subject) { joins(:activity_log_item).where(event: "note_added", activity_log_item: { subject: }) } + def loaded_data OpenStruct.new(**data, **activity_log_item.subject.try(:activity_event_data_for, self).presence || {}) end diff --git a/app/models/frameworks/evaluation.rb b/app/models/frameworks/evaluation.rb index e1d2c67d5..3d22f83d6 100644 --- a/app/models/frameworks/evaluation.rb +++ b/app/models/frameworks/evaluation.rb @@ -6,6 +6,8 @@ class Frameworks::Evaluation < ApplicationRecord include StatusChangeable include Presentable include ActivityLogPresentable + include Noteable + include QuickEditable belongs_to :framework has_one :provider, through: :framework diff --git a/app/models/frameworks/evaluation/noteable.rb b/app/models/frameworks/evaluation/noteable.rb new file mode 100644 index 000000000..9d5e1b941 --- /dev/null +++ b/app/models/frameworks/evaluation/noteable.rb @@ -0,0 +1,18 @@ +module Frameworks::Evaluation::Noteable + extend ActiveSupport::Concern + + def add_note(note) + log_activity_event("note_added", body: note) + end + + def latest_note + event = Frameworks::ActivityEvent.added_notes(self).last + return if event.nil? + + OpenStruct.new( + body: event.loaded_data.body, + author: event.activity_log_item.actor.initials, + date: event.created_at.strftime("%d %b %y"), + ) + end +end diff --git a/app/models/frameworks/evaluation/presentable.rb b/app/models/frameworks/evaluation/presentable.rb index 969e71c59..52e45f1d2 100644 --- a/app/models/frameworks/evaluation/presentable.rb +++ b/app/models/frameworks/evaluation/presentable.rb @@ -40,4 +40,10 @@ def contact_email def contact_phone contact.try(:phone) end + + def next_key_date_formatted + return "Not set" if next_key_date.blank? + + next_key_date.strftime("%d/%m/%Y") + end end diff --git a/app/models/frameworks/evaluation/quick_editable.rb b/app/models/frameworks/evaluation/quick_editable.rb new file mode 100644 index 000000000..afe084e07 --- /dev/null +++ b/app/models/frameworks/evaluation/quick_editable.rb @@ -0,0 +1,14 @@ +module Frameworks::Evaluation::QuickEditable + extend ActiveSupport::Concern + + def quick_editor(note: latest_note&.body, next_key_date: self.next_key_date, next_key_date_description: self.next_key_date_description) + Frameworks::Evaluation::QuickEditor.new(frameworks_evaluation: self, note:, next_key_date:, next_key_date_description:) + end + + def quick_edit(details) + transaction do + update!(details.except(:note)) if details[:next_key_date_description].present? + add_note(details[:note]) if details[:note].present? && details[:note] != latest_note&.body + end + end +end diff --git a/app/models/frameworks/evaluation/quick_editor.rb b/app/models/frameworks/evaluation/quick_editor.rb new file mode 100644 index 000000000..e05b9f831 --- /dev/null +++ b/app/models/frameworks/evaluation/quick_editor.rb @@ -0,0 +1,15 @@ +class Frameworks::Evaluation::QuickEditor + include ActiveModel::Model + include ActiveModel::Attributes + include ActiveModel::Validations + include Validation::HasNextKeyDate + + attribute :frameworks_evaluation + attribute :note + attribute :next_key_date + attribute :next_key_date_description + + def save! + frameworks_evaluation.quick_edit(note:, next_key_date:, next_key_date_description:) + end +end diff --git a/app/models/support/case/quick_editor.rb b/app/models/support/case/quick_editor.rb index de99e267e..049362825 100644 --- a/app/models/support/case/quick_editor.rb +++ b/app/models/support/case/quick_editor.rb @@ -1,7 +1,7 @@ class Support::Case::QuickEditor include ActiveModel::Model include ActiveModel::Validations - include Support::Case::Validation::HasNextKeyDate + include Validation::HasNextKeyDate attr_accessor( :support_case, diff --git a/app/models/support/case/summary.rb b/app/models/support/case/summary.rb index 1137ddd43..477a50bd3 100644 --- a/app/models/support/case/summary.rb +++ b/app/models/support/case/summary.rb @@ -2,7 +2,7 @@ class Support::Case::Summary include ActiveModel::Model include ActiveModel::Attributes include ActiveModel::Validations - include Support::Case::Validation::HasNextKeyDate + include Validation::HasNextKeyDate attribute :support_case attribute :request_type, :boolean diff --git a/app/views/frameworks/activity_log_items/_history.html.erb b/app/views/frameworks/activity_log_items/_history.html.erb index f5838a4fd..93bb1d5d5 100644 --- a/app/views/frameworks/activity_log_items/_history.html.erb +++ b/app/views/frameworks/activity_log_items/_history.html.erb @@ -23,9 +23,9 @@

<% if content_for?(:"#{activity_log_item.activity_id}_description") %> -

+

<%= yield :"#{activity_log_item.activity_id}_description" %> -

+
<% end %> <% end %> diff --git a/app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_evaluation_started.html.erb b/app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_evaluation_started.html.erb deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_note_added.html.erb b/app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_note_added.html.erb new file mode 100644 index 000000000..879c528ab --- /dev/null +++ b/app/views/frameworks/activity_log_items/activity/activity_event/evaluations/_note_added.html.erb @@ -0,0 +1,7 @@ +<% content_for :"#{activity.id}_subject" do %> + Note Added +<% end %> + +<% content_for :"#{activity.id}_description" do %> + <%= simple_format(activity.loaded_data.body) %> +<% end %> diff --git a/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_category_added.html.erb b/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_category_added.html.erb index 408a2bc0f..d77e1d2be 100644 --- a/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_category_added.html.erb +++ b/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_category_added.html.erb @@ -1,3 +1,3 @@ -% content_for :"#{activity.id}_subject" do %> - Added category "<%= activity.loaded_data.support_category.title %>" +<% content_for :"#{activity.id}_subject" do %> + Category "<%= activity.loaded_data.support_category.title %>" added <% end %> diff --git a/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_evaluation_started.html.erb b/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_evaluation_started.html.erb index f714f8b21..02fe09338 100644 --- a/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_evaluation_started.html.erb +++ b/app/views/frameworks/activity_log_items/activity/activity_event/frameworks/_evaluation_started.html.erb @@ -1,7 +1,3 @@ <% content_for :"#{activity.id}_subject" do %> - Evaluation started -<% end %> - -<% content_for :"#{activity.id}_description" do %> - <%= link_to "View Evalutaion #{activity.loaded_data.evaluation.reference}", activity.loaded_data.evaluation, class: "govuk-link", "data-turbo" => false %> + Evaluation started: <%= link_to activity.loaded_data.evaluation.reference, activity.loaded_data.evaluation, class: "govuk-link", "data-turbo" => false %> <% end %> diff --git a/app/views/frameworks/evaluations/_evaluation.html.erb b/app/views/frameworks/evaluations/_evaluation.html.erb index 2d85d247d..75815dfb6 100644 --- a/app/views/frameworks/evaluations/_evaluation.html.erb +++ b/app/views/frameworks/evaluations/_evaluation.html.erb @@ -1,44 +1,86 @@
-
-
-
-
Case ID
-
<%= link_to evaluation.reference, frameworks_evaluation_path(evaluation, back_to: current_url_b64(:evaluations)), class: "govuk-link", "data-turbo" => false %>
-
+
+
+
+
+
+
Case ID
+
<%= link_to evaluation.reference, frameworks_evaluation_path(evaluation, back_to: current_url_b64(:evaluations)), class: "govuk-link", "data-turbo" => false %>
+
-
-
Framework Name
-
<%= evaluation.framework_name %>
-
+
+
Framework Name
+
<%= evaluation.framework_name %>
+
-
-
Framework Provider
-
<%= evaluation.framework_provider_name %>
-
+
+
Framework Provider
+
<%= evaluation.framework_provider_name %>
+
-
-
Categories
-
<%= evaluation.framework_category_names %>
+
+
Categories
+
<%= evaluation.framework_category_names %>
+
+
-
-
-
-
-
-
Status
-
<%= evaluation.display_status %>
+
+
+
+
Status
+
<%= evaluation.display_status %>
+
+ +
+
Assignee
+
<%= evaluation.display_assignee %>
+
+ +
+
Updated
+
<%= evaluation.display_last_updated %>
+
+
+
-
-
Assignee
-
<%= evaluation.display_assignee %>
+
+
+

+ <%= link_to "Quick edit", edit_frameworks_evaluation_quick_edit_path(evaluation, back_to: current_url_b64(:evaluations)), class: "govuk-link govuk-link--no-visited-state", "target" => "_top" %> +

+
-
-
Updated
-
<%= evaluation.display_last_updated %>
+
+
+ <% if evaluation.latest_note.present? %> + <%= simple_format("Note: #{evaluation.latest_note.date} #{evaluation.latest_note.author} - " + evaluation.latest_note.body, class: "govuk-body") %> + <% end %> +
+
+ <% if evaluation.next_key_date.present? %> +
+
+
+ <%= I18n.t("support.case.label.next_key_date.label") %> +
+
+ <%= evaluation.next_key_date_formatted %> +
+
+
+
+ <%= I18n.t("support.case.label.next_key_date.description2") %> +
+
+ <%= simple_format(evaluation.next_key_date_description, class: "govuk-body") %> +
+
+
+ <% end %>
-
+
diff --git a/app/views/frameworks/evaluations/_form.html.erb b/app/views/frameworks/evaluations/_form.html.erb new file mode 100644 index 000000000..e3b3ae28d --- /dev/null +++ b/app/views/frameworks/evaluations/_form.html.erb @@ -0,0 +1,21 @@ +<% edit ||= false %> + +<%= form_for @evaluation do |f| %> + <%= f.govuk_select :framework_id, @frameworks.map {|framework| ["#{framework.reference_and_name} (#{framework.provider_name})", framework.id] }, + disabled: edit, + options: { include_blank: "Select a framework" }, + label: { text: "Framework", size: "m" } %> + + <%= f.govuk_select :contact_id, @contacts.map {|contact| ["#{contact.name} (#{contact.provider_name})", contact.id] }, + options: { include_blank: "Select a contact" }, + label: { text: "Contact at provider", size: "m" } %> + + <%= f.govuk_select :assignee_id, @agents.map {|agent| [agent.full_name, agent.id] }, + options: { include_blank: "Select an agent" }, + label: { text: "Case Owner", size: "m" } %> + +
+ <%= f.govuk_submit edit ? "Save changes" : "Create evaluation" %> + <%= link_to "Cancel", @back_url, class: "govuk-link govuk-link--no-visited-state" %> +
+<% end %> diff --git a/app/views/frameworks/evaluations/edit.html.erb b/app/views/frameworks/evaluations/edit.html.erb new file mode 100644 index 000000000..fd6b9029b --- /dev/null +++ b/app/views/frameworks/evaluations/edit.html.erb @@ -0,0 +1,8 @@ +<%= content_for :title, "GHBS | Frameworks | Evaluation | #{@evaluation.reference} | Edit" %> + +[<%= @evaluation.reference %>] Framework Evaluation +

Edit Basic Details

+ +
+ <%= render "form", edit: true %> +
diff --git a/app/views/frameworks/evaluations/new.html.erb b/app/views/frameworks/evaluations/new.html.erb index 818343c60..477388515 100644 --- a/app/views/frameworks/evaluations/new.html.erb +++ b/app/views/frameworks/evaluations/new.html.erb @@ -3,18 +3,5 @@

New Framework Evaluation

- <%= form_for @evaluation do |f| %> - <%= f.govuk_select :framework_id, @frameworks.map {|framework| [framework.reference_and_name, framework.id] }, - options: { include_blank: "Select a framework" }, - label: { text: "Framework" } %> - - <%= f.govuk_select :assignee_id, @agents.map {|agent| [agent.full_name, agent.id] }, - options: { include_blank: "Select an agent" }, - label: { text: "Assignee" } %> - -
- <%= f.govuk_submit "Create evaluation" %> - <%= link_to "Cancel", @back_url, class: "govuk-link govuk-link--no-visited-state" %> -
- <% end %> + <%= render "form" %>
diff --git a/app/views/frameworks/evaluations/quick_edits/edit.html.erb b/app/views/frameworks/evaluations/quick_edits/edit.html.erb new file mode 100644 index 000000000..feb1bda84 --- /dev/null +++ b/app/views/frameworks/evaluations/quick_edits/edit.html.erb @@ -0,0 +1,22 @@ +<%= content_for :title, "GHBS | Frameworks | Evaluation #{@evaluation.reference} | Quick edit" %> + +
+
+

<%= I18n.t("frameworks.evaluation.quick_edit.header", reference: @evaluation.reference) %>

+ <%= form_with model: @quick_edit, + scope: :quick_edit, + url: frameworks_evaluation_quick_edit_path(back_to: Base64.encode64(@back_url), redirect_back: params[:redirect_back]), + method: :patch do |form| %> + <%= form.govuk_error_summary %> + + <%= form.govuk_text_area :note, rows: 5, label: { text: I18n.t("frameworks.evaluation.quick_edit.add_note"), size: "m" } %> + + <%= render "support/cases/components/next_key_date", form: form %> + +
+ <%= form.submit I18n.t("generic.button.save"), class: "govuk-button", role: "button" %> + <%= link_to "Exit without saving", @back_url, class: "govuk-link govuk-link--no-visited-state" %> +
+ <% end %> +
+
diff --git a/app/views/frameworks/evaluations/show.html.erb b/app/views/frameworks/evaluations/show.html.erb index 640b1e263..10d8bc49c 100644 --- a/app/views/frameworks/evaluations/show.html.erb +++ b/app/views/frameworks/evaluations/show.html.erb @@ -10,7 +10,7 @@ ACTION <% end %> <%= @evaluation.display_status %> - Case Owner: <%= @evaluation.display_assignee %> + Case Owner: <%= @evaluation.display_assignee %> (<%= link_to "Change", edit_frameworks_evaluation_path(@evaluation, back_to: current_url_b64, redirect_back: current_url_b64), class: "govuk-link govuk-link--no-visited-state", "target" => "_top" %>)
@@ -50,7 +50,7 @@

Actions

diff --git a/app/views/frameworks/evaluations/show/_framework.html.erb b/app/views/frameworks/evaluations/show/_framework.html.erb index ea266b3bb..45847571d 100644 --- a/app/views/frameworks/evaluations/show/_framework.html.erb +++ b/app/views/frameworks/evaluations/show/_framework.html.erb @@ -18,7 +18,9 @@ <%= link_to @evaluation.contact_name, frameworks_provider_contact_path(@evaluation.contact, back_to: current_url_b64(:framework)), class: "govuk-link", "data-turbo" => false %> <% end %> -
<%= link_to "Change", "#", class: "govuk-link", "data-turbo" => false %>
+
+ <%= link_to "Change", edit_frameworks_evaluation_path(@evaluation, back_to: current_url_b64, redirect_back: current_url_b64), class: "govuk-link govuk-link--no-visited-state", "target" => "_top" %> +
diff --git a/config/locales/en.yml b/config/locales/en.yml index ae65711af..911db46a9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -692,6 +692,11 @@ en: email: Email full_name: Full name header: Enter your contact details + frameworks: + evaluation: + quick_edit: + header: Quick edit evaluation %{reference} + add_note: Add a note generic: button: back: Back diff --git a/config/locales/validation/support/en.yml b/config/locales/validation/support/en.yml index aa239b586..edf750c30 100644 --- a/config/locales/validation/support/en.yml +++ b/config/locales/validation/support/en.yml @@ -41,6 +41,10 @@ en: attributes: next_key_date: blank: Enter a date for the description + frameworks/evaluation/quick_editor: + attributes: + next_key_date: + blank: Enter a date for the description forms: rules: diff --git a/config/routes.rb b/config/routes.rb index 3d5f0125a..76ef9a8fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -351,6 +351,7 @@ resources :evaluations do scope module: :evaluations do resource :contacts, only: %i[edit update] + resource :quick_edit, only: %i[edit update] end end resources :frameworks do diff --git a/db/migrate/20231027145735_add_next_key_date_and_description_to_frameworks_evaluations.rb b/db/migrate/20231027145735_add_next_key_date_and_description_to_frameworks_evaluations.rb new file mode 100644 index 000000000..01bbb42e1 --- /dev/null +++ b/db/migrate/20231027145735_add_next_key_date_and_description_to_frameworks_evaluations.rb @@ -0,0 +1,8 @@ +class AddNextKeyDateAndDescriptionToFrameworksEvaluations < ActiveRecord::Migration[7.0] + def change + change_table :frameworks_evaluations, bulk: true do |t| + t.column :next_key_date, :date + t.column :next_key_date_description, :string + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 31a4fb6d8..85db6259b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2023_10_19_085509) do +ActiveRecord::Schema[7.1].define(version: 2023_10_27_145735) do create_sequence "evaluation_refs" create_sequence "framework_refs" @@ -289,6 +289,8 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.boolean "action_required", default: false + t.date "next_key_date" + t.string "next_key_date_description" end create_table "frameworks_framework_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| diff --git a/spec/features/frameworks/evaluations/agent_can_create_framework_evaluation_spec.rb b/spec/features/frameworks/evaluations/agent_can_create_framework_evaluation_spec.rb index 108f20d0d..a60a07b50 100644 --- a/spec/features/frameworks/evaluations/agent_can_create_framework_evaluation_spec.rb +++ b/spec/features/frameworks/evaluations/agent_can_create_framework_evaluation_spec.rb @@ -9,7 +9,7 @@ visit frameworks_framework_path(framework) click_on "Evaluations" click_on "Add Evaluation" - select agent.full_name, from: "Assignee" + select agent.full_name, from: "Case Owner" expect { click_on "Create evaluation" }.to change { framework.reload.evaluations.count }.from(0).to(1) end diff --git a/spec/features/frameworks/evaluations/agent_can_quick_edit_framework_evaluation_spec.rb b/spec/features/frameworks/evaluations/agent_can_quick_edit_framework_evaluation_spec.rb new file mode 100644 index 000000000..14e469a4a --- /dev/null +++ b/spec/features/frameworks/evaluations/agent_can_quick_edit_framework_evaluation_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe "Agent can quick edit a framework evaluation", js: true do + include_context "with a framework evaluation agent" + + let!(:framework_evaluation) { create(:frameworks_evaluation, reference: "FE1") } + + before do + visit frameworks_root_path(anchor: "evaluations") + within("#evaluations") { click_link "Quick edit" } + end + + context "when changing the note and next key date" do + before do + fill_in "Add a note", with: "New note" + fill_in "Day", with: "10" + fill_in "Month", with: "08" + fill_in "Year", with: "2023" + fill_in "Description of next key date", with: "Key event" + click_button "Save" + end + + it "persists the changes" do + expect(framework_evaluation.latest_note.body).to eq("New note") + expect(framework_evaluation.reload.next_key_date).to eq(Date.parse("2023-08-10")) + expect(framework_evaluation.reload.next_key_date_description).to eq("Key event") + end + end +end diff --git a/spec/features/frameworks/register/agent_can_browse_frameworks_register_spec.rb b/spec/features/frameworks/register/agent_can_browse_frameworks_register_spec.rb index 5a4efc599..c80f64862 100644 --- a/spec/features/frameworks/register/agent_can_browse_frameworks_register_spec.rb +++ b/spec/features/frameworks/register/agent_can_browse_frameworks_register_spec.rb @@ -22,7 +22,6 @@ it "can view the details of a framework" do visit frameworks_root_path - puts Frameworks::ActivityLogItem.pluck :activity_type click_on "books" expect(page).to have_title("Books & Stationary") end diff --git a/spec/features/frameworks/register/agent_can_categorise_framework_spec.rb b/spec/features/frameworks/register/agent_can_categorise_framework_spec.rb index ab8fbee4a..6075c1284 100644 --- a/spec/features/frameworks/register/agent_can_categorise_framework_spec.rb +++ b/spec/features/frameworks/register/agent_can_categorise_framework_spec.rb @@ -17,8 +17,7 @@ click_on "Save changes" expect(page).to have_summary("Categories", "Laptops, Electricity") - click_on "History" - expect(page).to have_content('Added category "Laptops" to framework') - expect(page).to have_content('Added category "Electricity" to framework') + expect(page).to have_content('Category "Laptops" added') + expect(page).to have_content('Category "Electricity" added') end end diff --git a/spec/models/support/case/validation/has_next_key_date_spec.rb b/spec/models/support/case/validation/has_next_key_date_spec.rb index f4316314e..a40e4e732 100644 --- a/spec/models/support/case/validation/has_next_key_date_spec.rb +++ b/spec/models/support/case/validation/has_next_key_date_spec.rb @@ -1,6 +1,6 @@ require "rails_helper" -describe Support::Case::Validation::HasNextKeyDate do +describe Validation::HasNextKeyDate do subject(:has_next_key_date) { Support::Case::QuickEditor.new(params) } let(:next_key_date) { nil }