diff options
| author | Zog | 2018-01-22 09:54:20 +0100 |
|---|---|---|
| committer | Zog | 2018-01-25 17:18:01 +0100 |
| commit | ff5d96b530a41669c394b7b0dc138e29da48e97d (patch) | |
| tree | cc731e14383ef8f47302478faebac493dadacdf8 /app | |
| parent | 872f9476971d3bde6e6f470153af09ed87af1b28 (diff) | |
| download | chouette-core-ff5d96b530a41669c394b7b0dc138e29da48e97d.tar.bz2 | |
Refs #5586 @2h; Fix specs
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 3 | ||||
| -rw-r--r-- | app/decorators/company_decorator.rb | 4 | ||||
| -rw-r--r-- | app/decorators/referential_decorator.rb | 9 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 27 | ||||
| -rw-r--r-- | app/views/layouts/navigation/_page_header.html.slim | 13 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 4 |
6 files changed, 32 insertions, 28 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index b2dac9e67..2a71fe811 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -18,9 +18,8 @@ class WorkbenchesController < ChouetteController @q_for_form = scope.ransack(params[:q]) @q_for_result = scope.ransack(ransack_params) @wbench_refs = sort_result(@q_for_result.result).paginate(page: params[:page], per_page: 30) - @wbench_refs = ModelDecorator.decorate( + @wbench_refs = ReferentialDecorator.decorate( @wbench_refs, - with: ReferentialDecorator, context: { current_workbench_id: params[:id] } diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index 3737b851e..aadce68bb 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -7,7 +7,9 @@ class CompanyDecorator < AF83::Decorator end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link + instance_decorator.show_action_link do |l| + l.href { [context[:referential], object] } + end instance_decorator.edit_action_link do |l| l.content {|l| l.action == "show" ? h.t('actions.edit') : h.t('companies.actions.edit') } diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb index 226f8269e..3132cbf92 100644 --- a/app/decorators/referential_decorator.rb +++ b/app/decorators/referential_decorator.rb @@ -2,14 +2,15 @@ class ReferentialDecorator < AF83::Decorator decorates Referential with_instance_decorator do |instance_decorator| + instance_decorator.show_action_link instance_decorator.edit_action_link - instance_decorator.action_link feature: :referential_vehicle_journeys, secondary: :show do |l| + instance_decorator.action_link feature: :referential_vehicle_journeys, secondary: :show, on: :show do |l| l.content t('referential_vehicle_journeys.index.title') l.href { h.referential_vehicle_journeys_path(object) } end - instance_decorator.action_link feature: :purchase_windows, secondary: :show do |l| + instance_decorator.action_link feature: :purchase_windows, secondary: :show, on: :show do |l| l.content t('purchase_windows.index.title') l.href { h.referential_purchase_windows_path(object) } end @@ -35,13 +36,13 @@ class ReferentialDecorator < AF83::Decorator l.method :put end - instance_decorator.action_link policy: :unarchive, secondary: :show do |l| + instance_decorator.action_link policy: :unarchive, secondary: :show, on: :show do |l| l.content t('actions.unarchive') l.href { h.unarchive_referential_path(object.id) } l.method :put end - instance_decorator.action_link policy: :edit, secondary: :show do |l| + instance_decorator.action_link policy: :edit, secondary: :show, on: :show do |l| l.content 'Purger' l.href '#' l.type 'button' diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index e29695b55..5c9da3d36 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -86,12 +86,15 @@ module TableBuilderHelper overhead: [], # Possibility to override the result of collection.model - model: nil + model: nil, + + #overrides the params[:action] value + action: nil ) content_tag :table, - thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model) + - tbody(collection, columns, selectable, links, overhead), + thead(collection, columns, sortable, selectable, links.any?, overhead, model || collection.model, action || params[:action]) + + tbody(collection, columns, selectable, links, overhead, action || params[:action]), class: cls end @@ -109,7 +112,7 @@ module TableBuilderHelper private - def thead(collection, columns, sortable, selectable, has_links, overhead, model ) + def thead(collection, columns, sortable, selectable, has_links, overhead, model, action) content_tag :thead do # Inserts overhead content if any specified over_head = '' @@ -189,7 +192,7 @@ module TableBuilderHelper # Inserts a blank column for the gear menu last_item = collection.last - action_links = last_item && last_item.respond_to?(:action_links) && (last_item&.action_links&.is_a?(AF83::Decorator::ActionLinks) ? last_item.action_links(params[:action]) : last_item.action_links) + action_links = last_item && last_item.respond_to?(:action_links) && (last_item&.action_links&.is_a?(AF83::Decorator::ActionLinks) ? last_item.action_links(action) : last_item.action_links) if has_links || action_links.try(:any?) hcont << content_tag(:th, '') end @@ -201,7 +204,7 @@ module TableBuilderHelper end end - def tr item, columns, selectable, links, overhead, model_name + def tr item, columns, selectable, links, overhead, model_name, action klass = "#{model_name}-#{item.id}" content_tag :tr, class: klass do bcont = [] @@ -269,12 +272,12 @@ module TableBuilderHelper end end - action_links = item && item.respond_to?(:action_links) && (item.action_links.is_a?(AF83::Decorator::ActionLinks) ? item.action_links(params[:action]) : item.action_links) + action_links = item && item.respond_to?(:action_links) && (item.action_links.is_a?(AF83::Decorator::ActionLinks) ? item.action_links(action) : item.action_links) if links.any? || action_links.try(:any?) bcont << content_tag( :td, - build_links(item, links), + build_links(item, links, action), class: 'actions' ) end @@ -283,12 +286,12 @@ module TableBuilderHelper end end - def tbody(collection, columns, selectable, links, overhead) + def tbody(collection, columns, selectable, links, overhead, action) model_name = TableBuilderHelper.item_row_class_name collection content_tag :tbody do collection.map do |item| - tr item, columns, selectable, links, overhead, model_name + tr item, columns, selectable, links, overhead, model_name, action end.join.html_safe end end @@ -301,7 +304,7 @@ module TableBuilderHelper end end - def build_links(item, links) + def build_links(item, links, action) trigger = content_tag( :div, class: 'btn dropdown-toggle', @@ -313,7 +316,7 @@ module TableBuilderHelper action_links = item.action_links if action_links.is_a?(AF83::Decorator::ActionLinks) menu = content_tag :div, class: 'dropdown-menu' do - item.action_links(params[:action]).grouped_by(:primary, :secondary, :footer).map do |group, _links| + item.action_links(action).grouped_by(:primary, :secondary, :footer).map do |group, _links| if _links.any? content_tag :ul, class: group do _links.map{|link| gear_menu_link(link)}.join.html_safe diff --git a/app/views/layouts/navigation/_page_header.html.slim b/app/views/layouts/navigation/_page_header.html.slim index 8240aa4c0..e407e53da 100644 --- a/app/views/layouts/navigation/_page_header.html.slim +++ b/app/views/layouts/navigation/_page_header.html.slim @@ -26,12 +26,11 @@ = link.to_html do |l| - l.class "btn btn-default #{l.disabled ? "disabled" : ""}" - - if action_links&.secondary&.any? || content_for?(:page_header_content) - .container-fluid - .row - .col-lg-12.text-right.mb-sm - - action_links && action_links.secondary.each do |link| + - 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 content_for? :page_header_content - = yield :page_header_content + - if content_for? :page_header_content + = yield :page_header_content diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 8907f3f08..a162ca334 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -59,8 +59,8 @@ ) \ ], selectable: ->(ref){ @workbench.referentials.include?(ref) }, - links: [:show, :edit], - cls: 'table has-filter has-search' + cls: 'table has-filter has-search', + action: :index = multiple_selection_toolbox([:delete], collection_name: 'referentials') |
