Skip to content

Commit

Permalink
feat(fworks): quick edit framework evaluations
Browse files Browse the repository at this point in the history
Jira: PWNN-1694
  • Loading branch information
EdwinKruglov authored and ryantk committed Nov 2, 2023
1 parent 84b69e5 commit 085a7f9
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 60 deletions.
15 changes: 15 additions & 0 deletions app/controllers/concerns/has_date_params.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FrameworkRequests
class ContractStartDatesController < BaseController
include Support::Concerns::HasDateParams
include HasDateParams

skip_before_action :authenticate_user!

Expand Down
38 changes: 38 additions & 0 deletions app/controllers/frameworks/evaluations/quick_edits_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/controllers/support/cases/contracts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support/cases/quick_edits_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/support/cases/summaries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions app/controllers/support/concerns/has_date_params.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Support::Case::Validation::HasNextKeyDate
module Validation::HasNextKeyDate
extend ActiveSupport::Concern

included do
Expand Down
2 changes: 2 additions & 0 deletions app/models/frameworks/activity_event.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/frameworks/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions app/models/frameworks/evaluation/noteable.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions app/models/frameworks/evaluation/presentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions app/models/frameworks/evaluation/quick_editable.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions app/models/frameworks/evaluation/quick_editor.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/models/support/case/quick_editor.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/models/support/case/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% content_for :"#{activity.id}_subject" do %>
Note Added
<% end %>

<% content_for :"#{activity.id}_description" do %>
<%= activity.loaded_data.body %>
<% end %>
104 changes: 73 additions & 31 deletions app/views/frameworks/evaluations/_evaluation.html.erb
Original file line number Diff line number Diff line change
@@ -1,44 +1,86 @@
<div class="govuk-grid-row case-panel">
<div class="govuk-grid-column-one-half govuk-!-margin-bottom-3">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Case ID</dt>
<dd class="govuk-summary-list__value"><%= link_to evaluation.reference, frameworks_evaluation_path(evaluation, back_to: current_url_b64(:evaluations)), class: "govuk-link", "data-turbo" => false %></dd>
</div>
<div class="govuk-grid-column-full">
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half govuk-!-margin-bottom-3">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Case ID</dt>
<dd class="govuk-summary-list__value"><%= link_to evaluation.reference, frameworks_evaluation_path(evaluation, back_to: current_url_b64(:evaluations)), class: "govuk-link", "data-turbo" => false %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Name</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_name %></dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Name</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_name %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Provider</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_provider_name %></dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Framework Provider</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_provider_name %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Categories</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_category_names %></dd>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Categories</dt>
<dd class="govuk-summary-list__value"><%= evaluation.framework_category_names %></dd>
</div>
</dl>
</div>
</dl>
</div>

<div class="govuk-grid-column-one-half">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Status</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_status %></dd>
<div class="govuk-grid-column-one-half">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Status</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_status %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Assignee</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_assignee %></dd>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Updated</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_last_updated %></dd>
</div>
</dl>
</div>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Assignee</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_assignee %></dd>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<p class="govuk-body">
<%= 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" %>
</p>
</div>
</div>

<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Updated</dt>
<dd class="govuk-summary-list__value"><%= evaluation.display_last_updated %></dd>
<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<% if evaluation.latest_note.present? %>
<%= simple_format("<b>Note:</b> #{evaluation.latest_note.date} #{evaluation.latest_note.author} - " + evaluation.latest_note.body, class: "govuk-body") %>
<% end %>
</div>
<div class="govuk-grid-column-one-half">
<% if evaluation.next_key_date.present? %>
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.next_key_date.label") %>
</dt>
<dd class="govuk-summary-list__value">
<%= evaluation.next_key_date_formatted %>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case.label.next_key_date.description2") %>
</dt>
<dd class="govuk-summary-list__value">
<%= simple_format(evaluation.next_key_date_description, class: "govuk-body") %>
</dd>
</div>
</dl>
<% end %>
</div>
</dl>
</div>
</div>
</div>
22 changes: 22 additions & 0 deletions app/views/frameworks/evaluations/quick_edits/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%= content_for :title, "GHBS | Frameworks | Evaluation #{@evaluation.reference} | Quick edit" %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-third">
<h1 class="govuk-heading-l"><%= I18n.t("frameworks.evaluation.quick_edit.header", reference: @evaluation.reference) %></h1>
<%= form_with model: @quick_edit,
scope: :quick_edit,
url: frameworks_evaluation_quick_edit_path(back_to: Base64.encode64(@back_url)),
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 %>

<div class="govuk-button-group">
<%= 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" %>
</div>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,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
Expand Down
4 changes: 4 additions & 0 deletions config/locales/validation/support/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 085a7f9

Please sign in to comment.