generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fworks): quick edit framework evaluations
- Loading branch information
1 parent
86ee5f7
commit 971741a
Showing
43 changed files
with
346 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
app/controllers/framework_requests/contract_start_dates_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
app/controllers/frameworks/evaluations/contacts_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
app/controllers/frameworks/evaluations/quick_edits_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...port/case/validation/has_next_key_date.rb → .../concerns/validation/has_next_key_date.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
7 changes: 7 additions & 0 deletions
7
...ws/frameworks/activity_log_items/activity/activity_event/evaluations/_note_added.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
4 changes: 2 additions & 2 deletions
4
...frameworks/activity_log_items/activity/activity_event/frameworks/_category_added.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
6 changes: 1 addition & 5 deletions
6
...eworks/activity_log_items/activity/activity_event/frameworks/_evaluation_started.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
Oops, something went wrong.