diff options
| author | Teddy Wing | 2018-01-24 12:43:50 +0100 | 
|---|---|---|
| committer | Zog | 2018-01-25 17:18:01 +0100 | 
| commit | 766dd36e253cfe00f0cec96e7fa55687428b0f2a (patch) | |
| tree | 6df5985cdcf50782f1efe1db9c71db7571f2c4e5 | |
| parent | 990ca5807a3237dc72f2b66630261118d81696bc (diff) | |
| download | chouette-core-766dd36e253cfe00f0cec96e7fa55687428b0f2a.tar.bz2 | |
RouteDecorator: Convert to new action links interface
Important to add the `action: :index` argument on the table builder in
the `ReferentialLines#show` page so that the gear menu links render
correctly.
Refs #5586
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 3 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb | 107 | ||||
| -rw-r--r-- | app/views/referential_lines/show.html.slim | 4 | ||||
| -rw-r--r-- | app/views/routes/show.html.slim | 13 | 
4 files changed, 68 insertions, 59 deletions
| diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index 9e8f5c512..37051faeb 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -28,9 +28,8 @@ class ReferentialLinesController < ChouetteController      @routes = @routes.paginate(page: params[:page], per_page: 10) -    @routes = ModelDecorator.decorate( +    @routes = RouteDecorator.decorate(        @routes, -      with: RouteDecorator,        context: {          referential: referential,          line: @line diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index ec7f0d6aa..7e3ea889f 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -1,75 +1,98 @@ -class RouteDecorator < Draper::Decorator +class RouteDecorator < AF83::Decorator    decorates Chouette::Route -  delegate_all - -  # Requires: +  # Action links require:    #   context: {    #     referential: ,    #     line:    #   } -  def action_links -    links = [] -    if object.stop_points.any? -      links << Link.new( -        content: h.t('journey_patterns.actions.index'), -        href: [ +  with_instance_decorator do |instance_decorator| +    instance_decorator.show_action_link do |l| +      l.href do +        h.referential_line_route_path( +          context[:referential], +          context[:line], +          object +        ) +      end +    end + +    instance_decorator.edit_action_link do |l| +      l.href do +        h.edit_referential_line_route_path( +          context[:referential], +          context[:line], +          object +        ) +      end +    end + +    instance_decorator.action_link( +      if: ->() { object.stop_points.any? }, +      secondary: :show +    ) do |l| +      l.content h.t('journey_patterns.actions.index') +      l.href do +        [            context[:referential],            context[:line],            object,            :journey_patterns_collection          ] -      ) +      end      end -    if object.journey_patterns.present? -      links << Link.new( -        content: h.t('vehicle_journeys.actions.index'), -        href: [ +    instance_decorator.action_link( +      if: ->() { object.journey_patterns.present? }, +      secondary: :show +    ) do |l| +      l.content h.t('vehicle_journeys.actions.index') +      l.href do +        [            context[:referential],            context[:line],            object,            :vehicle_journeys          ] -      ) +      end      end -    links << Link.new( -      content: h.t('vehicle_journey_exports.new.title'), -      href: h.referential_line_route_vehicle_journey_exports_path( -        context[:referential], -        context[:line], -        object, -        format: :zip -      ) -    ) +    instance_decorator.action_link secondary: :show do |l| +      l.content h.t('vehicle_journey_exports.new.title') +      l.href do +        h.referential_line_route_vehicle_journey_exports_path( +          context[:referential], +          context[:line], +          object, +          format: :zip +        ) +      end +    end -    if h.policy(object).duplicate? -      links << Link.new( -        content: h.t('routes.duplicate.title'), -        href: h.duplicate_referential_line_route_path( +    instance_decorator.action_link( +      secondary: :show, +      policy: :duplicate +    ) do |l| +      l.content h.t('routes.duplicate.title') +      l.href do +        h.duplicate_referential_line_route_path(            context[:referential],            context[:line],            object -        ), -        method: :post -      ) +        ) +      end      end -    if h.policy(object).destroy? -      links << Link.new( -        content: h.destroy_link_content, -        href: h.referential_line_route_path( +    instance_decorator.destroy_action_link do |l| +      l.href do +        h.referential_line_route_path(            context[:referential],            context[:line],            object -        ), -        method: :delete, -        data: { confirm: h.t('routes.actions.destroy_confirm') } -      ) +        ) +      end +      l.data confirm: h.t('routes.actions.destroy_confirm')      end - -    links    end  end diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index cfba8cab3..70f4048b3 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -79,8 +79,8 @@                      attribute: Proc.new{ |r| r.try(:journey_patterns).count } \                    ) \                  ], -                links: [:show, :edit], -                cls: 'table has-search' +                cls: 'table has-search', +                action: :index                = new_pagination @routes, 'pull-right' diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 644f79022..4d5963cd1 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -1,18 +1,5 @@  - breadcrumb :route, @referential, @route  - page_header_content_for @route -- content_for :page_header_actions do -  - if policy(@route).edit? -    = link_to(t('actions.edit'), edit_referential_line_route_path(@referential, @line, @route), class: 'btn btn-default') - -- content_for :page_header_content do -  .row.mb-sm -    .col-lg-12.text-right -      - @route.action_links.each do |link| -        = link_to link.href, -            method: link.method, -            data: link.data, -            class: 'btn btn-primary' do -              = link.content  .page_content    .container-fluid | 
