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 editing of provider contact
- Loading branch information
Showing
21 changed files
with
261 additions
and
63 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
27 changes: 27 additions & 0 deletions
27
app/controllers/frameworks/provider_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
13 changes: 4 additions & 9 deletions
13
app/models/frameworks/activity_loggable/activity_log_presentable.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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
module Frameworks::ActivityLoggable::ActivityLogPresentable | ||
extend ActiveSupport::Concern | ||
|
||
def activity_log_association_display_name(association:, id:) | ||
self.class.reflections[association].klass.find_by(id:).try(:activity_log_display_name) | ||
end | ||
|
||
def activity_log_display_type | ||
self.class.to_s.demodulize.underscore.humanize | ||
included do | ||
delegate :version_at, to: :paper_trail | ||
end | ||
|
||
def activity_log_display_name | ||
try(:full_name) || try(:short_name) || try(:name) | ||
end | ||
|
||
def activity_log_display(field) | ||
return send("activity_log_#{field}") if respond_to?("activity_log_#{field}") | ||
return send("display_#{field}") if respond_to?("display_#{field}") | ||
def activity_log_display_type | ||
self.class.to_s.demodulize.underscore.humanize | ||
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
class Frameworks::ActivityLoggableVersion < PaperTrail::Version | ||
def presentable_chages | ||
PresentableChanges.new(self) | ||
include Presentable | ||
|
||
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 | ||
end |
23 changes: 23 additions & 0 deletions
23
app/models/frameworks/activity_loggable_version/presentable.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,23 @@ | ||
module Frameworks::ActivityLoggableVersion::Presentable | ||
extend ActiveSupport::Concern | ||
|
||
def presentable_changes | ||
Frameworks::ActivityLoggableVersion::PresentableChanges.new(self) | ||
end | ||
|
||
def display_field_version(field:, value:) | ||
display_value = | ||
if field.ends_with?("_id") | ||
display_field_version_for_association(association: field.split("_id").first, id: value) | ||
else | ||
item.try("display_field_version_#{field}", value) | ||
end | ||
|
||
display_value.presence || value | ||
end | ||
|
||
def display_field_version_for_association(association:, id:) | ||
record = item_association_at_version_or_current(association:, id:) | ||
record.try(:activity_log_display_name).presence || record.try(:full_name).presence || record.try(:name) | ||
end | ||
end |
25 changes: 9 additions & 16 deletions
25
app/models/frameworks/activity_loggable_version/presentable_changes.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 |
---|---|---|
@@ -1,27 +1,20 @@ | ||
class Frameworks::ActivityLoggableVersion::PresentableChanges | ||
PresentableChange = Struct.new(:field, :from, :to, keyword_init: true) | ||
|
||
include Enumerable | ||
|
||
def initialize(version) | ||
@version = version | ||
end | ||
|
||
def each(&block) | ||
if block_given? | ||
non_common_object_changes.each(&block) | ||
else | ||
to_enum(:each) | ||
end | ||
end | ||
|
||
private | ||
def each | ||
return to_enum(:each) unless block_given? | ||
|
||
def non_common_object_changes | ||
@version.object_changes | ||
.except("id", "created_at", "updated_at") | ||
.map { |field, changes| change_type(field).new(@version, field, changes) } | ||
end | ||
@version.object_changes.except("id", "created_at", "updated_at").each do |field, changes| | ||
from = @version.display_field_version(field:, value: changes.first) | ||
to = @version.display_field_version(field:, value: changes.last) | ||
|
||
def change_type(field) | ||
field.ends_with?("_id") ? BelongsToAssociationChange : FieldChange | ||
yield PresentableChange.new(field:, from:, to:) | ||
end | ||
end | ||
end |
15 changes: 0 additions & 15 deletions
15
...frameworks/activity_loggable_version/presentable_changes/belongs_to_association_change.rb
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
app/models/frameworks/framework/activity_log_presentable.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,11 @@ | ||
module Frameworks::Framework::ActivityLogPresentable | ||
extend ActiveSupport::Concern | ||
|
||
def display_field_version_dfe_start_date(date) | ||
Date.parse(date).strftime("%d/%m/%y") if date.present? | ||
end | ||
|
||
def display_field_version_dfe_end_date(date) | ||
display_field_version_dfe_start_date(date) | ||
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
17 changes: 10 additions & 7 deletions
17
app/views/frameworks/activity_log_items/activity/_activity_loggable_version.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
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,21 @@ | ||
<%= content_for :title, "GHBS | Provider Contacts | Edit #{@provider_contact.name}" %> | ||
|
||
<%= turbo_frame_tag dom_id(@provider_contact) do %> | ||
<span class="govuk-caption-l">Edit Framework Provider Contact</span> | ||
<h1 class="govuk-heading-l"><%= @provider_contact.name %></h2> | ||
|
||
<h2 class="govuk-heading-m">Details</h2> | ||
|
||
<div class="govuk-!-width-two-thirds"> | ||
<%= form_for @provider_contact do |f| %> | ||
<%= f.govuk_text_field :name %> | ||
<%= f.govuk_text_field :email %> | ||
<%= f.govuk_text_field :phone %> | ||
|
||
<div class="govuk-button-group flex-align-center"> | ||
<%= f.govuk_submit "Save changes" %> | ||
<%= link_to "Cancel", @provider_contact, class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% 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,40 @@ | ||
<%= content_for :title, "GHBS | Provider Contacts | #{@provider_contact.name}" %> | ||
|
||
<%= turbo_frame_tag dom_id(@provider_contact) do %> | ||
<span class="govuk-caption-l">Framework Provider Contact</span> | ||
<h1 class="govuk-heading-l"><%= @provider_contact.name %></h2> | ||
|
||
<h2 class="govuk-heading-m">Details</h2> | ||
<dl class="govuk-summary-list govuk-!-width-two-thirds"> | ||
<div class="govuk-summary-list__row"> | ||
<dt class="govuk-summary-list__key">Name</dt> | ||
<dd class="govuk-summary-list__value"><%= @provider_contact.name %></dd> | ||
</div> | ||
|
||
<div class="govuk-summary-list__row"> | ||
<dt class="govuk-summary-list__key">Email</dt> | ||
<dd class="govuk-summary-list__value"><%= @provider_contact.email %></dd> | ||
</div> | ||
|
||
<div class="govuk-summary-list__row"> | ||
<dt class="govuk-summary-list__key">Phone</dt> | ||
<dd class="govuk-summary-list__value"><%= @provider_contact.phone %></dd> | ||
</div> | ||
|
||
<div class="govuk-summary-list__row"> | ||
<dt class="govuk-summary-list__key">Provider</dt> | ||
<dd class="govuk-summary-list__value"><%= @provider_contact.provider_name %></dd> | ||
</div> | ||
</dl> | ||
|
||
<h2 class="govuk-heading-m">Actions</h2> | ||
<ul class="govuk-list"> | ||
<li><%= link_to "Edit Contact", edit_frameworks_provider_contact_path(@provider_contact), class: "govuk-link" %></li> | ||
<li><%= link_to "View Owned Frameworks", frameworks_frameworks_path(frameworks_filter: { provider_contact: [@provider_contact.id] }), class: "govuk-link", "data-turbo" => false %></li> | ||
</ul> | ||
|
||
<h2 class="govuk-heading-m">History</h2> | ||
<div class="govuk-!-width-two-thirds"> | ||
<%= render "frameworks/activity_log_items/list", activity_log_items: @provider_contact.activity_log_items %> | ||
</div> | ||
<% end %> |
Oops, something went wrong.