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 import, register and log
- Loading branch information
Showing
79 changed files
with
1,645 additions
and
263 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,20 @@ | ||
.activity-log-table { | ||
@extend .govuk-\!-font-size-16; | ||
|
||
table { | ||
@extend .govuk-\!-font-size-16; | ||
} | ||
|
||
.activity-log-date { | ||
width: 180px; | ||
} | ||
.activity-log-person { | ||
width: 180px; | ||
} | ||
|
||
.activity-log-change-arrow { | ||
color: #a2a2a2; | ||
margin-left: 5px; | ||
margin-right: 5px; | ||
} | ||
} |
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,30 @@ | ||
class Frameworks::FrameworksController < Frameworks::ApplicationController | ||
before_action :redirect_to_register_tab, unless: :turbo_frame_request?, only: :index | ||
before_action :set_back_url, only: %i[new show] | ||
|
||
def new; end | ||
|
||
def index | ||
@filtering = Frameworks::Framework.filtering(filter_form_params) | ||
@frameworks = @filtering.results.paginate(page: params[:frameworks_page]) | ||
end | ||
|
||
def show | ||
@framework = Frameworks::Framework.find(params[:id]) | ||
@activity_log_items = @framework.activity_log_items.paginate(page: params[:activities_page]) | ||
end | ||
|
||
private | ||
|
||
def filter_form_params | ||
params.fetch(:frameworks_filter, {}).permit(:sort_by, :sort_order, status: [], provider: [], e_and_o_lead: [], proc_ops_lead: [], category: []) | ||
end | ||
|
||
def set_back_url | ||
@back_url = back_link_param | ||
end | ||
|
||
def redirect_to_register_tab | ||
redirect_to frameworks_root_path(anchor: "frameworks-register", **request.params.except(:controller, :action)) | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
app/controllers/frameworks/management/activity_logs_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,11 @@ | ||
class Frameworks::Management::ActivityLogsController < Frameworks::Management::ApplicationController | ||
before_action { @back_url = frameworks_management_path } | ||
|
||
def show | ||
@activity_log_items = Frameworks::ActivityLogItem.paginate(page: params[:page], per_page: 50) | ||
end | ||
|
||
private | ||
|
||
def authorize_agent_scope = [super, :manage_frameworks_activity_log?] | ||
end |
5 changes: 5 additions & 0 deletions
5
app/controllers/frameworks/management/application_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::Management::ApplicationController < Frameworks::ApplicationController | ||
private | ||
|
||
def authorize_agent_scope = [super, :access_admin_settings?] | ||
end |
3 changes: 3 additions & 0 deletions
3
app/controllers/frameworks/management/management_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,3 @@ | ||
class Frameworks::Management::ManagementController < Frameworks::Management::ApplicationController | ||
def index; end | ||
end |
19 changes: 19 additions & 0 deletions
19
app/controllers/frameworks/management/register_uploads_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,19 @@ | ||
class Frameworks::Management::RegisterUploadsController < Frameworks::Management::ApplicationController | ||
before_action { @back_url = frameworks_management_path } | ||
|
||
def new; end | ||
|
||
def create | ||
Frameworks::Framework.import_from_spreadsheet(register_upload_params[:spreadsheet]) | ||
|
||
redirect_to frameworks_management_path | ||
end | ||
|
||
private | ||
|
||
def register_upload_params | ||
params.require(:register_upload).permit(:spreadsheet) | ||
end | ||
|
||
def authorize_agent_scope = [super, :manage_frameworks_register_upload?] | ||
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,3 +1,3 @@ | ||
class Current < ActiveSupport::CurrentAttributes | ||
attribute :user, :agent | ||
attribute :user, :agent, :actor, :request_id | ||
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 @@ | ||
module Frameworks::Activity | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_one :activity_log_item, as: :activity, touch: true | ||
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,12 @@ | ||
class Frameworks::ActivityLogItem < ApplicationRecord | ||
include Presentable | ||
|
||
belongs_to :actor, polymorphic: true, optional: true | ||
belongs_to :subject, polymorphic: true, optional: true | ||
delegated_type :activity, types: %w[PaperTrail::Version] | ||
|
||
before_create do | ||
self.guid ||= Current.request_id | ||
self.actor ||= Current.actor | ||
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,11 @@ | ||
module Frameworks::ActivityLogItem::Presentable | ||
extend ActiveSupport::Concern | ||
|
||
def display_created_at | ||
created_at.strftime("%d/%m/%Y %H:%M:%S") | ||
end | ||
|
||
def display_actor | ||
actor.try(:full_name) | ||
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,19 @@ | ||
module Frameworks::ActivityLoggable | ||
extend ActiveSupport::Concern | ||
include ActivityLogPresentable | ||
|
||
included do | ||
has_paper_trail versions: { class_name: "Frameworks::ActivityLoggableVersion" } | ||
|
||
has_many :activity_log_items, as: :subject | ||
|
||
after_create :log_latest_version_in_activity_log | ||
after_update :log_latest_version_in_activity_log | ||
end | ||
|
||
private | ||
|
||
def log_latest_version_in_activity_log | ||
Frameworks::ActivityLogItem.create!(subject: self, activity: versions.last) | ||
end | ||
end |
20 changes: 20 additions & 0 deletions
20
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 | ||
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}") | ||
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,5 @@ | ||
class Frameworks::ActivityLoggableVersion < PaperTrail::Version | ||
def presentable_chages | ||
PresentableChanges.new(self) | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Frameworks::ActivityLoggableVersion::PresentableChanges | ||
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 non_common_object_changes | ||
@version.object_changes | ||
.except("id", "created_at", "updated_at") | ||
.map { |field, changes| change_type(field).new(@version, field, changes) } | ||
end | ||
|
||
def change_type(field) | ||
field.ends_with?("_id") ? BelongsToAssociationChange : FieldChange | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
...frameworks/activity_loggable_version/presentable_changes/belongs_to_association_change.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,15 @@ | ||
class Frameworks::ActivityLoggableVersion::PresentableChanges::BelongsToAssociationChange < Frameworks::ActivityLoggableVersion::PresentableChanges::FieldChange | ||
private | ||
|
||
def to | ||
item.activity_log_association_display_name(association:, id: changes.last) | ||
end | ||
|
||
def from | ||
item.activity_log_association_display_name(association:, id: changes.first) | ||
end | ||
|
||
def association | ||
field.split("_id").first | ||
end | ||
end |
Oops, something went wrong.