aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/compliance_control_sets_controller.rb5
-rw-r--r--app/decorators/compliance_control_decorator.rb51
-rw-r--r--app/helpers/compliance_control_sets_helper.rb3
-rw-r--r--app/helpers/table_builder_helper.rb25
-rw-r--r--app/views/compliance_controls/show.html.slim2
5 files changed, 44 insertions, 42 deletions
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb
index 0173838a2..ae1d01feb 100644
--- a/app/controllers/compliance_control_sets_controller.rb
+++ b/app/controllers/compliance_control_sets_controller.rb
@@ -42,10 +42,7 @@ class ComplianceControlSetsController < ChouetteController
end
def decorate_compliance_controls(compliance_controls)
- ModelDecorator.decorate(
- compliance_controls,
- with: ComplianceControlDecorator,
- )
+ ComplianceControlDecorator.decorate(compliance_controls)
end
def compliance_control_set_params
diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb
index f56e80417..a0445faa2 100644
--- a/app/decorators/compliance_control_decorator.rb
+++ b/app/decorators/compliance_control_decorator.rb
@@ -1,30 +1,33 @@
-class ComplianceControlDecorator < Draper::Decorator
- delegate_all
-
- def action_links
- policy = h.policy(object)
- links = []
-
- links << Link.new(
- content: h.t('compliance_control_sets.actions.show'),
- href: h.compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id)
- )
+class ComplianceControlDecorator < AF83::Decorator
+ with_instance_decorator do |instance_decorator|
+ instance_decorator.show_action_link do |l|
+ l.content h.t('compliance_control_sets.actions.show')
+ l.href do
+ h.compliance_control_set_compliance_control_path(
+ object.compliance_control_set.id,
+ object.id
+ )
+ end
+ end
- if policy.edit?
- links << Link.new(
- content: h.t('compliance_controls.actions.edit'),
- href: h.edit_compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id)
- )
+ instance_decorator.edit_action_link do |l|
+ l.href do
+ h.edit_compliance_control_set_compliance_control_path(
+ object.compliance_control_set_id,
+ object.id
+ )
+ end
end
- if policy.destroy?
- links << Link.new(
- content: h.destroy_link_content,
- href: h.compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id),
- method: :delete,
- data: { confirm: h.t('compliance_controls.actions.destroy_confirm') }
- )
+ instance_decorator.destroy_action_link do |l|
+ l.content h.destroy_link_content
+ l.href do
+ h.compliance_control_set_compliance_control_path(
+ object.compliance_control_set.id,
+ object.id
+ )
+ end
+ l.data confirm: h.t('compliance_controls.actions.destroy_confirm')
end
- links
end
end
diff --git a/app/helpers/compliance_control_sets_helper.rb b/app/helpers/compliance_control_sets_helper.rb
index 57e6d9608..448d5c008 100644
--- a/app/helpers/compliance_control_sets_helper.rb
+++ b/app/helpers/compliance_control_sets_helper.rb
@@ -100,7 +100,8 @@ module ComplianceControlSetsHelper
],
sortable: true,
cls: 'table has-filter has-search',
- model: ComplianceControl
+ model: ComplianceControl,
+ action: :index
end
metas = content_tag :div, I18n.t('compliance_control_blocks.metas.control', count: compliance_controls.count), class: 'pull-right'
table + metas
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index 5c9da3d36..b123da802 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -94,18 +94,21 @@ module TableBuilderHelper
)
content_tag :table,
thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model, action || params[:action]) +
- tbody(collection, columns, selectable, links, overhead, action || params[:action]),
+ tbody(collection, columns, selectable, links, overhead, model, action || params[:action]),
class: cls
end
- def self.item_row_class_name collection
- if collection.respond_to?(:model)
- model_name = collection.model.name
- elsif collection.respond_to?(:first)
- model_name = collection.first.class.name
- else
- model_name = "item"
- end
+ def self.item_row_class_name collection, model
+ model_name = model&.name
+
+ model_name ||=
+ if collection.respond_to?(:model)
+ collection.model.name
+ elsif collection.respond_to?(:first)
+ collection.first.class.name
+ else
+ "item"
+ end
model_name.split("::").last.parameterize
end
@@ -286,8 +289,8 @@ module TableBuilderHelper
end
end
- def tbody(collection, columns, selectable, links, overhead, action)
- model_name = TableBuilderHelper.item_row_class_name collection
+ def tbody(collection, columns, selectable, links, overhead, model = nil, action)
+ model_name = TableBuilderHelper.item_row_class_name collection, model
content_tag :tbody do
collection.map do |item|
diff --git a/app/views/compliance_controls/show.html.slim b/app/views/compliance_controls/show.html.slim
index 54b07abf1..8a65bb864 100644
--- a/app/views/compliance_controls/show.html.slim
+++ b/app/views/compliance_controls/show.html.slim
@@ -1,6 +1,4 @@
- breadcrumb :compliance_control, @compliance_control
-- content_for :page_header_actions do
- = link_to(t('actions.edit'), edit_compliance_control_set_compliance_control_path(params[:compliance_control_set_id], params[:id]), class: 'btn btn-default')
- page_header_content_for @compliance_control