diff options
| author | Teddy Wing | 2018-01-23 11:42:15 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-25 17:18:01 +0100 | 
| commit | 759699cec33a06b931c50f4473460fb79290e356 (patch) | |
| tree | 12492d1a95491c6f619a07e638451e78ca7f307a | |
| parent | 9f4584ef7427575fce4b8294b79f2368b130d8b6 (diff) | |
| download | chouette-core-759699cec33a06b931c50f4473460fb79290e356.tar.bz2 | |
Imports#index: Move 'New import' button to action links
Begin the process of converting the `ImportDecorator` to the new action
links interface.
For now, only the "New import" button on the top right of the index page
is converted. The rest of the links are commented out for now and will
be treated in a subsequent commit.
Add a new `#class?` method to `AF83::Decorator::Link` that tells callers
whether a CSS class has been defined on the link. This allows us to
determine whether we should force a class or use the one provided in
`_page_header.html.slim`.
We need a way to specify the class of the link in the header because the
"New import" button is supposed to be blue (`.btn-primary`), but the
default for primary action links is white.
Refs #5586
| -rw-r--r-- | app/controllers/imports_controller.rb | 3 | ||||
| -rw-r--r-- | app/decorators/import_decorator.rb | 54 | ||||
| -rw-r--r-- | app/views/imports/index.html.slim | 2 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_page_header.html.slim | 6 | ||||
| -rw-r--r-- | lib/af83/decorator/link.rb | 4 | 
5 files changed, 38 insertions, 31 deletions
| diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 46d34efda..7a999d657 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -84,9 +84,8 @@ class ImportsController < ChouetteController    end    def decorate_imports(imports) -    ModelDecorator.decorate( +    ImportDecorator.decorate(        imports, -      with: ImportDecorator,        context: {          workbench: @workbench        } diff --git a/app/decorators/import_decorator.rb b/app/decorators/import_decorator.rb index 8b00234d2..440501fc1 100644 --- a/app/decorators/import_decorator.rb +++ b/app/decorators/import_decorator.rb @@ -1,8 +1,6 @@ -class ImportDecorator < Draper::Decorator +class ImportDecorator < AF83::Decorator    decorates Import -  delegate_all -    def import_status_css_class      cls =''      cls = 'overheaded-success' if object.status == 'successful' @@ -11,28 +9,34 @@ class ImportDecorator < Draper::Decorator      cls    end -  def action_links -    policy = h.policy(object) -    links = [] - -    links << Link.new( -      content: h.t('imports.actions.download'), -      href: object.file.url -    ) - -    if policy.destroy? -      links << Link.new( -        content: h.destroy_link_content, -        href: h.workbench_import_path( -          context[:workbench], -          object -        ), -        method: :delete, -        data: { confirm: h.t('imports.actions.destroy_confirm') } -      ) -    end - -    links +  create_action_link do |l| +    l.content t('imports.actions.new') +    l.href { h.new_workbench_import_path(workbench_id: context[:workbench]) } +    l.class 'btn btn-primary'    end +  # def action_links +  #   policy = h.policy(object) +  #   links = [] +  # +  #   links << Link.new( +  #     content: h.t('imports.actions.download'), +  #     href: object.file.url +  #   ) +  # +  #   if policy.destroy? +  #     links << Link.new( +  #       content: h.destroy_link_content, +  #       href: h.workbench_import_path( +  #         context[:workbench], +  #         object +  #       ), +  #       method: :delete, +  #       data: { confirm: h.t('imports.actions.destroy_confirm') } +  #     ) +  #   end +  # +  #   links +  # end +  end diff --git a/app/views/imports/index.html.slim b/app/views/imports/index.html.slim index 856b715e0..951910d18 100644 --- a/app/views/imports/index.html.slim +++ b/app/views/imports/index.html.slim @@ -1,6 +1,4 @@  - breadcrumb :imports, @workbench -- content_for :page_header_actions do -  = link_to(t('imports.actions.new'), new_workbench_import_path(workbench_id: @workbench), class: 'btn btn-primary')  .page_content    .container-fluid diff --git a/app/views/layouts/navigation/_page_header.html.slim b/app/views/layouts/navigation/_page_header.html.slim index e407e53da..23bc64db0 100644 --- a/app/views/layouts/navigation/_page_header.html.slim +++ b/app/views/layouts/navigation/_page_header.html.slim @@ -24,13 +24,15 @@            - if action_links&.primary&.any?              - action_links.primary.each do |link|                = link.to_html do |l| -                - l.class "btn btn-default #{l.disabled ? "disabled" : ""}" +                - if !l.class? +                  - l.class "btn btn-default #{l.disabled ? "disabled" : ""}"      - if action_links&.secondary&.any?        .row.mb-sm          .col-lg-12.text-right            - action_links.secondary.each do |link|              = link.to_html do |l| -              - l.class "btn btn-primary #{l.disabled ? "disabled" : ""}" +              - if !l.class? +                - l.class "btn btn-primary #{l.disabled ? "disabled" : ""}"      - if content_for? :page_header_content        = yield :page_header_content diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index 55db3f5bb..10e6091aa 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -25,6 +25,10 @@ class AF83::Decorator::Link      link_class args    end +  def class? +    @options[:link_class] && !@options[:link_class].empty? +  end +    def method_missing name, *args, &block      if block_given?        @options[name] = block | 
