Skip to content

Commit

Permalink
feat(fworks): quick edit framework evaluations
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwinKruglov authored and ryantk committed Nov 3, 2023
1 parent 86ee5f7 commit 971741a
Show file tree
Hide file tree
Showing 43 changed files with 346 additions and 96 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
2 changes: 1 addition & 1 deletion app/controllers/frameworks/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions app/controllers/frameworks/evaluation_contacts_controller.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/controllers/frameworks/evaluations/contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Frameworks::Evaluations::ContactsController < Frameworks::ApplicationController
def edit; end

def update; end
end
47 changes: 47 additions & 0 deletions app/controllers/frameworks/evaluations/quick_edits_controller.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions app/controllers/frameworks/evaluations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
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)) if details[:next_key_date_description].present?
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
4 changes: 2 additions & 2 deletions app/views/frameworks/activity_log_items/_history.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
</p>

<% if content_for?(:"#{activity_log_item.activity_id}_description") %>
<p class="hods-timeline__description">
<div class="hods-timeline__description">
<%= yield :"#{activity_log_item.activity_id}_description" %>
</p>
</div>
<% end %>
</div>
<% end %>
Expand Down
Empty file.
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 %>
<%= simple_format(activity.loaded_data.body) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -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 %>
Original file line number Diff line number Diff line change
@@ -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 %>
Loading

0 comments on commit 971741a

Please sign in to comment.