diff options
| author | Teddy Wing | 2018-01-25 13:11:31 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-25 17:18:03 +0100 | 
| commit | 9ee14d84ccfd19fb6a53c83826f352088f06b57c (patch) | |
| tree | d044c068a2599cb70cd8d919e45a61cd21066563 | |
| parent | 9a0a0a8398eda742df6793b6981bef037968604d (diff) | |
| download | chouette-core-9ee14d84ccfd19fb6a53c83826f352088f06b57c.tar.bz2 | |
ComplianceControlSetDecorator: Convert to new action links interface
Refs #5586
| -rw-r--r-- | app/controllers/compliance_control_sets_controller.rb | 5 | ||||
| -rw-r--r-- | app/decorators/compliance_control_set_decorator.rb | 43 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/index.html.slim | 4 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/show.html.slim | 12 | ||||
| -rw-r--r-- | app/views/imports/show.html.slim | 1 | 
5 files changed, 18 insertions, 47 deletions
| diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index 2d3d03ad0..0173838a2 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -38,10 +38,7 @@ class ComplianceControlSetsController < ChouetteController    private    def decorate_compliance_control_sets(compliance_control_sets) -    ModelDecorator.decorate( -      compliance_control_sets, -      with: ComplianceControlSetDecorator -    ) +    ComplianceControlSetDecorator.decorate(compliance_control_sets)    end    def decorate_compliance_controls(compliance_controls) diff --git a/app/decorators/compliance_control_set_decorator.rb b/app/decorators/compliance_control_set_decorator.rb index 73d65d54a..01f51133d 100644 --- a/app/decorators/compliance_control_set_decorator.rb +++ b/app/decorators/compliance_control_set_decorator.rb @@ -1,35 +1,26 @@ -class ComplianceControlSetDecorator < Draper::Decorator -  delegate_all +class ComplianceControlSetDecorator < AF83::Decorator +  decorates ComplianceControlSet -  def action_links -    policy = h.policy(object) -    links = [] +  create_action_link do |l| +    l.content t('compliance_control_sets.actions.new') +    l.href h.new_compliance_control_set_path +  end -    if policy.edit? -      links << Link.new( -        content: h.t('compliance_control_sets.actions.edit'), -        href:  h.edit_compliance_control_set_path(object.id) -      ) +  with_instance_decorator do |instance_decorator| +    instance_decorator.edit_action_link do |l| +      l.content t('compliance_control_sets.actions.edit') +      l.href { h.edit_compliance_control_set_path(object.id) }      end -    if policy.clone? -      links << Link.new( -        content: h.t('actions.clone'), -        href: h.clone_compliance_control_set_path(object.id) -      ) +    instance_decorator.action_link policy: :clone, secondary: :show do |l| +      l.content t('actions.clone') +      l.href { h.clone_compliance_control_set_path(object.id) }      end -    if policy.destroy? -      links << Link.new( -        content: h.destroy_link_content, -        href: h.compliance_control_set_path(object.id), -        method: :delete, -        data: { confirm: h.t('compliance_control_sets.actions.destroy_confirm') } -      ) +    instance_decorator.destroy_action_link do |l| +      l.content h.destroy_link_content +      l.href { h.compliance_control_set_path(object.id) } +      l.data confirm: h.t('compliance_control_sets.actions.destroy_confirm')      end - -    links    end -  end - diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim index 28d2254bf..144a4e5b9 100644 --- a/app/views/compliance_control_sets/index.html.slim +++ b/app/views/compliance_control_sets/index.html.slim @@ -1,7 +1,4 @@  - breadcrumb :compliance_control_sets -- content_for :page_header_actions do -  - if policy(ComplianceControlSet).create? -    = link_to(t('compliance_control_sets.actions.new'), new_compliance_control_set_path, class: 'btn btn-default')  .page_content    .container-fluid @@ -38,7 +35,6 @@                  ) \                ],                sortable: true, -              links: [:show],                cls: 'table has-filter has-search'            = new_pagination @compliance_control_sets, 'pull-right' diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index d915bbdaf..59100681d 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -1,17 +1,5 @@  - breadcrumb :compliance_control_set, @compliance_control_set  - page_header_content_for @compliance_control_set -- content_for :page_header_content do -  .row.mb-sm -    .col-lg-12.text-right -      - @compliance_control_set.action_links.each do |link| -        - if link.is_a?(HTMLElement) -          = link.to_html(class: 'btn btn-primary') -        - else -          = link_to link.href, -              method: link.method, -              data: link.data, -              class: 'btn btn-primary' do -            = link.content  .page_content    .container-fluid diff --git a/app/views/imports/show.html.slim b/app/views/imports/show.html.slim index e59c0c8f6..7a9d02077 100644 --- a/app/views/imports/show.html.slim +++ b/app/views/imports/show.html.slim @@ -45,7 +45,6 @@                  sortable: false, \                ) \              ], -            links: [],              cls: 'table',              overhead: [ \                {}, \ | 
