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): basic framework evaulations crud
- Loading branch information
Showing
70 changed files
with
870 additions
and
50 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
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,2 @@ | ||
class Frameworks::EvaluationContactsController < Frameworks::ApplicationController | ||
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,50 @@ | ||
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] | ||
|
||
def index | ||
@filtering = Frameworks::Evaluation.filtering(filter_form_params) | ||
@evaluations = @filtering.results.paginate(page: params[:evaluations_page]) | ||
end | ||
|
||
def show | ||
@evaluation = Frameworks::Evaluation.find(params[:id]) | ||
@activity_log_items = @evaluation.activity_log_items.paginate(page: params[:history_page]) | ||
end | ||
|
||
def new | ||
@evaluation = Frameworks::Evaluation.new(framework_id: params[:framework_id]) | ||
end | ||
|
||
def create | ||
@evaluation = Frameworks::Evaluation.new(evaluation_params) | ||
|
||
if @evaluation.save | ||
redirect_to @evaluation | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_form_options | ||
@frameworks = Frameworks::Framework.for_evaluation | ||
@agents = Support::Agent.framework_evaluators | ||
end | ||
|
||
def filter_form_params | ||
params.fetch(:evaluations_filter, {}).permit( | ||
:sort_by, :sort_order, | ||
status: [] | ||
) | ||
end | ||
|
||
def evaluation_params | ||
params.require(:frameworks_evaluation).permit(:framework_id, :assignee_id) | ||
end | ||
|
||
def redirect_to_register_tab | ||
redirect_to frameworks_root_path(anchor: "evaluations", **request.params.except(:controller, :action)) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
class Frameworks::ActivityLoggableVersion < PaperTrail::Version | ||
include Presentable | ||
|
||
after_create_commit :save_default_attributes_on_item_created | ||
|
||
def field_changes | ||
object_changes.except("id", "created_at", "updated_at") | ||
end | ||
|
||
def changed_fields_only?(*fields) | ||
field_changes.keys == Array(fields) | ||
end | ||
|
||
def changed_fields_including?(*fields) | ||
field_changes.keys.intersection(Array(fields)).any? | ||
end | ||
|
||
def item_association_at_version_or_current(association:, id:, version_at: created_at) | ||
current_version_of_association = item.class.reflections[association].klass.find_by(id:) | ||
current_version_of_association.try(:version_at, version_at).presence || current_version_of_association | ||
end | ||
|
||
private | ||
|
||
def save_default_attributes_on_item_created | ||
return unless item.id_previously_changed? | ||
|
||
object_changes_including_database_default_values = item.reload.attributes.each_with_object(object_changes) do |(attr, value), all_changes| | ||
all_changes[attr] ||= [nil, value] | ||
end | ||
|
||
update!(object_changes: object_changes_including_database_default_values) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class Frameworks::Evaluation < ApplicationRecord | ||
include Frameworks::ActivityLoggable | ||
include Filterable | ||
include Sortable | ||
include StatusChangeable | ||
include Presentable | ||
include ActivityLogPresentable | ||
|
||
belongs_to :framework | ||
has_one :provider, through: :framework | ||
belongs_to :assignee, class_name: "Support::Agent" | ||
belongs_to :contact, class_name: "Frameworks::ProviderContact", optional: true | ||
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,8 @@ | ||
module Frameworks::Evaluation::ActivityLogPresentable | ||
extend ActiveSupport::Concern | ||
|
||
def specific_change_template_for(activity_loggable_version) | ||
return "evaluations/status" if activity_loggable_version.changed_fields_only?("status") | ||
return "evaluations/contact" if activity_loggable_version.changed_fields_only?("contact_id") | ||
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,13 @@ | ||
module Frameworks::Evaluation::Filterable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :by_status, ->(statuses) { where(status: Array(statuses)) } | ||
end | ||
|
||
class_methods do | ||
def filtering(params = {}) | ||
Frameworks::Evaluation::Filtering.new(params) | ||
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,7 @@ | ||
class Frameworks::Evaluation::Filtering | ||
include FilterForm | ||
|
||
initial_scope -> { Frameworks::Evaluation } | ||
|
||
filter_by :status, options: -> { Frameworks::Evaluation.statuses.map { |label, _id| [label.humanize, label] } } | ||
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,43 @@ | ||
module Frameworks::Evaluation::Presentable | ||
extend ActiveSupport::Concern | ||
|
||
def framework_name | ||
framework.try(:name) | ||
end | ||
|
||
def framework_reference_and_name | ||
framework.try(:reference_and_name) | ||
end | ||
|
||
def framework_provider_name | ||
framework.try(:provider_name) | ||
end | ||
|
||
def framework_category_names | ||
framework.try(:category_names) | ||
end | ||
|
||
def display_status | ||
ApplicationController.render(partial: "frameworks/evaluations/status", locals: { status: }) | ||
end | ||
|
||
def display_assignee | ||
assignee.try(:full_name) | ||
end | ||
|
||
def display_last_updated | ||
"- TODO -" | ||
end | ||
|
||
def contact_name | ||
contact.try(:name) | ||
end | ||
|
||
def contact_email | ||
contact.try(:email) | ||
end | ||
|
||
def contact_phone | ||
contact.try(:phone) | ||
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,27 @@ | ||
module Frameworks::Evaluation::Sortable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
scope :sort_by_updated, ->(direction = "descending") { order("frameworks_evaluations.updated_at #{safe_direction(direction)}") } | ||
scope :sort_by_reference, ->(direction = "descending") { order("frameworks_evaluations.reference #{safe_direction(direction)}") } | ||
end | ||
|
||
class_methods do | ||
def sorted_by(sort_by:, sort_order:) | ||
return sort_by_reference("descending") unless sort_by.present? && sort_order.present? | ||
|
||
public_send("sort_by_#{sort_by}", sort_order) | ||
end | ||
|
||
def available_sort_options | ||
[ | ||
%w[Reference reference], | ||
%w[Updated updated], | ||
] | ||
end | ||
|
||
def safe_direction(direction) | ||
direction == "descending" ? "DESC" : "ASC" | ||
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,53 @@ | ||
module Frameworks::Evaluation::StatusChangeable | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
include AASM | ||
|
||
enum status: { | ||
draft: 0, | ||
in_progress: 1, | ||
approved: 2, | ||
not_approved: 3, | ||
cancelled: 4, | ||
}, _scopes: false | ||
|
||
aasm column: :status do | ||
Frameworks::Evaluation.statuses.each { |status, _| state status.to_sym } | ||
|
||
event :start do | ||
transitions from: :draft, to: :in_progress, after: :after_starting_evaluation | ||
end | ||
|
||
event :approve do | ||
transitions from: :in_progress, to: :approved, after: :after_approving | ||
end | ||
|
||
event :disapprove do | ||
transitions from: :in_progress, to: :not_approved, after: :after_disapproving | ||
end | ||
|
||
event :cancel do | ||
transitions from: :in_progress, to: :cancelled, after: :after_cancelling | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def after_starting_evaluation | ||
framework.start_evaluation!(self) | ||
end | ||
|
||
def after_approving | ||
framework.approve_evaluation!(self) | ||
end | ||
|
||
def after_disapproving | ||
framework.disapprove_evaluation!(self) | ||
end | ||
|
||
def after_cancelling | ||
framework.cancel_evaluation!(self) | ||
end | ||
end |
Oops, something went wrong.