diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 3 | ||||
| -rw-r--r-- | app/decorators/line_decorator.rb | 1 | ||||
| -rw-r--r-- | app/decorators/time_table_decorator.rb | 71 | ||||
| -rw-r--r-- | app/views/time_tables/index.html.slim | 1 | ||||
| -rw-r--r-- | app/views/time_tables/show.html.slim | 15 |
5 files changed, 38 insertions, 53 deletions
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index a0fa168f0..0707b9648 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -167,9 +167,8 @@ class TimeTablesController < ChouetteController end def decorate_time_tables(time_tables) - ModelDecorator.decorate( + TimeTableDecorator.decorate( time_tables, - with: TimeTableDecorator, context: { referential: @referential } diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index cc0e3a605..a8623e7d0 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -7,7 +7,6 @@ class LineDecorator < AF83::Decorator end with_instance_decorator do |instance_decorator| - instance_decorator.delegate_all ### primary (and secondary) can be ### - a single action ### - an array of actions diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index c6eeac176..202a020f7 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -1,55 +1,58 @@ -class TimeTableDecorator < Draper::Decorator +class TimeTableDecorator < AF83::Decorator decorates Chouette::TimeTable - delegate_all + with_instance_decorator do |instance_decorator| + instance_decorator.action_link primary: :index do |l| + l.content { h.t('actions.show') } + l.href { [context[:referential], object] } + end - # Requires: - # context: { - # referential: , - # } - def action_links - links = [] + instance_decorator.action_link primary: %i(show index) do |l| + l.content { h.t('actions.edit') } + l.href { [context[:referential], object] } + end - if object.calendar - links << Link.new( - content: h.t('actions.actualize'), - href: h.actualize_referential_time_table_path( + instance_decorator.action_link if: ->{ object.calendar }, secondary: true do |l| + l.content { h.t('actions.actualize') } + l.href do + h.actualize_referential_time_table_path( context[:referential], object - ), - method: :post - ) + ) + end + l.method :post end - if h.policy(object).edit? - links << Link.new( - content: h.t('actions.combine'), - href: h.new_referential_time_table_time_table_combination_path( + instance_decorator.action_link policy: :edit, secondary: true do |l| + l.content { h.t('actions.combine') } + l.href do + h.new_referential_time_table_time_table_combination_path( context[:referential], object ) - ) + end end - if h.policy(object).duplicate? - links << Link.new( - content: h.t('actions.duplicate'), - href: h.duplicate_referential_time_table_path( + instance_decorator.action_link policy: :duplicate, secondary: true do |l| + l.content { h.t('actions.duplicate') } + l.href do + h.duplicate_referential_time_table_path( context[:referential], object ) - ) + end end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_time_table_path(context[:referential], object), - method: :delete, - data: { confirm: h.t('time_tables.actions.destroy_confirm') } - ) + instance_decorator.action_link policy: :destroy, footer: true, secondary: :show do |l| + l.content { h.destroy_link_content } + l.href do + h.duplicate_referential_time_table_path( + context[:referential], + object + ) + end + l.method { :delete } + l.data {{ confirm: h.t('time_tables.actions.destroy_confirm') }} end - - links end end diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index b684b0bcb..b194dcea1 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -54,7 +54,6 @@ attribute: Proc.new { |tt| l(tt.updated_at, format: :short) } \ ) \ ], - links: [:show, :edit], cls: 'table has-search' = new_pagination @time_tables, 'pull-right' diff --git a/app/views/time_tables/show.html.slim b/app/views/time_tables/show.html.slim index df9789055..6d15323f3 100644 --- a/app/views/time_tables/show.html.slim +++ b/app/views/time_tables/show.html.slim @@ -4,21 +4,6 @@ - content_for :page_header_title, t('time_tables.show.title', name: @time_table.comment), flush: true -- content_for :page_header_actions do - - if policy(@time_table).edit? - = link_to(t('actions.edit'), edit_referential_time_table_path(@referential, @time_table), class: 'btn btn-default') - -- content_for :page_header_content do - .row.mb-sm - .col-lg-12.text-right - - @time_table.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 .row |
