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/evaluations/quick_edits_controller.rb b/app/controllers/frameworks/evaluations/quick_edits_controller.rb new file mode 100644 index 000000000..cf782b8a2 --- /dev/null +++ b/app/controllers/frameworks/evaluations/quick_edits_controller.rb @@ -0,0 +1,38 @@ +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 frameworks_root_path(anchor: "evaluations"), notice: "Evaluation updated" + else + render :edit + end + end + +private + + 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/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 75273c6fe..1a0b21cbe 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..af6fa99d0 --- /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)) + 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 7530f0c54..e197ac557 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/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..99afdee5a --- /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 %> + <%= activity.loaded_data.body %> +<% 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 @@
+ <%= 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" %> +