`
in order for the JavaScript part of it to work (otherwise selection
wouldn't activate the link, and likely other stuff would be messed up
too).
Now that the table builder and the selection toolbox are separate, it
makes sense to put the "select_table" `
` in the template.
Refs #3479
---
app/helpers/multiple_selection_toolbox_helper.rb | 39 ++++++++----
app/views/workbenches/show.html.slim | 80 ++++++++++++------------
2 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/app/helpers/multiple_selection_toolbox_helper.rb b/app/helpers/multiple_selection_toolbox_helper.rb
index f8f19fda6..85294af6d 100644
--- a/app/helpers/multiple_selection_toolbox_helper.rb
+++ b/app/helpers/multiple_selection_toolbox_helper.rb
@@ -1,27 +1,40 @@
module MultipleSelectionToolboxHelper
# Box of links that floats at the bottom right of the page
def multiple_selection_toolbox(actions)
- tools = content_tag :ul do
- dPath = nil
- dPath = referentials_workbench_path if params[:controller] = 'workbenches'
+ links = content_tag :ul do
+ delete_path = nil
- actions.collect do |action|
- if action == :edit
- actitem = link_to('#', title: t("actions.#{action}")) do
- content_tag :span, '', class: 'fa fa-pencil'
- end
- elsif action == :delete
- actitem = link_to('#', method: :delete, data: { path: dPath, confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?' }, title: t("actions.#{action}")) do
+ if params[:controller] = 'workbenches'
+ delete_path = referentials_workbench_path
+ end
+
+ actions.map do |action|
+ if action == :delete
+ action_link = link_to(
+ '#',
+ method: :delete,
+ data: {
+ path: delete_path,
+ confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?'
+ },
+ title: t("actions.#{action}")
+ ) do
content_tag :span, '', class: 'fa fa-trash'
end
end
- content_tag :li, actitem, class: 'st_action'
+ content_tag :li, action_link, class: 'st_action'
end.join.html_safe
-
end
+
+ label = content_tag(
+ :span,
+ ("
0 élément(s) sélectionné(s)").html_safe,
+ class: 'info-msg'
+ )
+
content_tag :div, '', class: 'select_toolbox noselect' do
- tools.concat(content_tag(:span, ("
0 élément(s) sélectionné(s)").html_safe, class: 'info-msg'))
+ links + label
end
end
end
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index 6dec68f7a..37c396b46 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -22,45 +22,47 @@
- if @wbench_refs.any?
.row
.col-lg-12
- = table_builder_2 @wbench_refs,
- [ \
- TableBuilderHelper::Column.new( \
- key: :name, \
- attribute: 'name' \
- ), \
- TableBuilderHelper::Column.new( \
- key: :status, \
- attribute: Proc.new {|w| w.archived? ? ("
Conservé
").html_safe : ("
En préparation
").html_safe} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :organisation, \
- attribute: Proc.new {|w| w.organisation.name} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :validity_period, \
- attribute: Proc.new {|w| w.validity_period.nil? ? '-' : t('validity_range', debut: l(w.try(:validity_period).try(:begin), format: :short), end: l(w.try(:validity_period).try(:end), format: :short))} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :lines, \
- attribute: Proc.new {|w| w.lines.count} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :created_at, \
- attribute: Proc.new {|w| l(w.created_at, format: :short)} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :updated_at, \
- attribute: Proc.new {|w| l(w.updated_at, format: :short)} \
- ), \
- TableBuilderHelper::Column.new( \
- key: :published_at, \
- attribute: '' \
- ) \
- ],
- selectable: true,
- links: [:show, :edit],
- cls: 'table has-filter has-search'
- / [:delete],
+ .select_table
+ = table_builder_2 @wbench_refs,
+ [ \
+ TableBuilderHelper::Column.new( \
+ key: :name, \
+ attribute: 'name' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :status, \
+ attribute: Proc.new {|w| w.archived? ? ("
Conservé
").html_safe : ("
En préparation
").html_safe} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :organisation, \
+ attribute: Proc.new {|w| w.organisation.name} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :validity_period, \
+ attribute: Proc.new {|w| w.validity_period.nil? ? '-' : t('validity_range', debut: l(w.try(:validity_period).try(:begin), format: :short), end: l(w.try(:validity_period).try(:end), format: :short))} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :lines, \
+ attribute: Proc.new {|w| w.lines.count} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :created_at, \
+ attribute: Proc.new {|w| l(w.created_at, format: :short)} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :updated_at, \
+ attribute: Proc.new {|w| l(w.updated_at, format: :short)} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :published_at, \
+ attribute: '' \
+ ) \
+ ],
+ selectable: true,
+ links: [:show, :edit],
+ cls: 'table has-filter has-search'
+
+ = multiple_selection_toolbox([:delete])
= new_pagination @wbench_refs, 'pull-right'
--
cgit v1.2.3
From 7887e9f44eef32382fce885d9e3270e390444bad Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 10:47:07 +0200
Subject: TableBuilderHelper::Column: Use `@name` consistently
We were using both the instance variable and the accessor on the same
line. Pick one and be consistent.
Refs #3479
---
app/helpers/table_builder_helper/column.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb
index b2fdf2b73..800a8282e 100644
--- a/app/helpers/table_builder_helper/column.rb
+++ b/app/helpers/table_builder_helper/column.rb
@@ -22,7 +22,7 @@ module TableBuilderHelper
end
def header_label(model = nil)
- return @name unless name.empty?
+ return @name unless @name.empty?
# Transform `Chouette::Line` into "line"
model_key = model.to_s.demodulize.underscore
--
cgit v1.2.3
From 88f1d1c6c4dd82404c124ec15ab56513289c2210 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 11:00:45 +0200
Subject: TableBuilder: Add documentation
Add a few doc comments to the table builder to provide a little more
detailed explanation of the code.
TableBuilderHelper::URL:
* Describe dependency on `current_referential`
TableBuilderHelper:
* Add doc comments to the `collection` and `columns` arguments
* Add a description of the module
* Detail external global variable dependencies
* Provide an example, stolen from one of the tests
Refs #3479
---
app/helpers/table_builder_helper.rb | 48 +++++++++++++++++++++++++++++++--
app/helpers/table_builder_helper/url.rb | 1 +
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index 97370b7e0..ebffb0da6 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -2,12 +2,56 @@ require 'table_builder_helper/column'
require 'table_builder_helper/custom_links'
require 'table_builder_helper/url'
-# TODO: Add doc comment about neeeding to make a decorator for your collections
-# TODO: Document global variables this uses
+# table_builder_2
+# A Rails helper that constructs an HTML table from a collection of objects. It
+# receives the collection and an array of columns that get transformed into
+# `
`s. A column of checkboxes can be added to the left side of the table
+# for multiple selection. Columns are sortable by default, but sorting can be
+# disabled either at the table level or at the column level. An optional
+# `links` argument takes a set of symbols corresponding to controller actions
+# that should be inserted in a gear menu next to each row in the table. That
+# menu will also be populated with links defined in `collection#action_links`,
+# a list of `Link` objects defined in a decorator for the given object.
+#
+# Depends on `params` and `current_referential`.
+#
+# Example:
+# table_builder_2(
+# @companies,
+# [
+# TableBuilderHelper::Column.new(
+# name: 'ID Codif',
+# attribute: Proc.new { |n| n.try(:objectid).try(:local_id) },
+# sortable: false
+# ),
+# TableBuilderHelper::Column.new(
+# key: :name,
+# attribute: 'name'
+# ),
+# TableBuilderHelper::Column.new(
+# key: :phone,
+# attribute: 'phone'
+# ),
+# TableBuilderHelper::Column.new(
+# key: :email,
+# attribute: 'email'
+# ),
+# TableBuilderHelper::Column.new(
+# key: :url,
+# attribute: 'url'
+# ),
+# ],
+# links: [:show, :edit],
+# cls: 'table has-search'
+# )
module TableBuilderHelper
# TODO: rename this after migration from `table_builder`
def table_builder_2(
+ # An `ActiveRecord::Relation`, wrapped in a decorator to provide a list of
+ # `Link` objects via an `#action_links` method
collection,
+
+ # An array of `TableBuilderHelper::Column`s
columns,
# When false, no columns will be sortable
diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb
index 59099ee99..f60864ac1 100644
--- a/app/helpers/table_builder_helper/url.rb
+++ b/app/helpers/table_builder_helper/url.rb
@@ -1,4 +1,5 @@
module TableBuilderHelper
+ # Depends on `current_referential`, defined in object controllers
class URL
def self.polymorphic_url_parts(item)
polymorph_url = []
--
cgit v1.2.3
From a417f0a2f2813fbec7e3c925334433f6a724405d Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 11:27:52 +0200
Subject: TableBuilder spec: Fix hard-coded IDs in expected string
Remove the hard-coded IDs and replace them with the test referential's
ID. I guess I had copied the output from the spec output, because the
test then passed when I ran it individually, causing me to not catch the
error. Only saw it when I ran the full test suite.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 199373e24..a61fd2343 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -79,8 +79,8 @@ describe TableBuilderHelper, type: :helper do
--
cgit v1.2.3
From ad21d8990a99d24b72b45ccc1d261ddc93179bfd Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 12:06:23 +0200
Subject: Add new #action_links decorators for a few priority models
These models are being prioritised for changing their views to use the
new TableBuilderHelper.
We're giving them all action links, copied out of the following files:
* time_tables/show.html.slim
* calendars/show.html.slim
* lines/show.html.slim
* routing_constraint_zones/show.html.slim
* routes/show.html.slim
Created a new namespace in decorators/ for Chouette model decorators for
consistency with the model/ directory. We'll want to move
`CompanyDecorator` in there too because it lives in the `Chouette::`
namespace.
Refs #3479
---
app/decorators/calendar_decorator.rb | 18 +++++++++
app/decorators/chouette/line_decorator.rb | 44 ++++++++++++++++++++++
app/decorators/chouette/route_decorator.rb | 43 +++++++++++++++++++++
.../chouette/routing_constraint_zone_decorator.rb | 35 +++++++++++++++++
app/decorators/chouette/time_table_decorator.rb | 42 +++++++++++++++++++++
app/decorators/company_decorator.rb | 1 +
6 files changed, 183 insertions(+)
create mode 100644 app/decorators/calendar_decorator.rb
create mode 100644 app/decorators/chouette/line_decorator.rb
create mode 100644 app/decorators/chouette/route_decorator.rb
create mode 100644 app/decorators/chouette/routing_constraint_zone_decorator.rb
create mode 100644 app/decorators/chouette/time_table_decorator.rb
diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb
new file mode 100644
index 000000000..37e2cfe80
--- /dev/null
+++ b/app/decorators/calendar_decorator.rb
@@ -0,0 +1,18 @@
+class CalendarDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.calendar_path(object),
+ method: :delete,
+ data: { confirm: h.t('calendars.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/chouette/line_decorator.rb b/app/decorators/chouette/line_decorator.rb
new file mode 100644
index 000000000..30c093dee
--- /dev/null
+++ b/app/decorators/chouette/line_decorator.rb
@@ -0,0 +1,44 @@
+# TODO: figure out @line_referential
+class Chouette::LineDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ links << Link.new(
+ content: h.t('lines.actions.show_network'),
+ href: [@line_referential, object.network]
+ )
+
+ links << Link.new(
+ content: h.t('lines.actions.show_company'),
+ href: [@line_referential, object.company]
+ )
+
+ if h.policy(Chouette::Line).create? &&
+ @line_referential.organisations.include?(current_organisation)
+ links << Link.new(
+ content: h.t('lines.actions.new'),
+ href: h.new_line_referential_line_path(@line_referential)
+ )
+ end
+
+ # TODO: what if false? do we delete this?
+ if false && h.policy(object).update?
+ # = link_to t('lines.actions.edit'), edit_line_referential_line_path(@line_referential, object), class: 'btn btn-primary'
+ end
+
+ if h.policy(object).destroy?
+ links << Link.new(
+# TODO: this translation is different!
+span = t('lines.actions.destroy')
+ content: h.destroy_link_content,
+ href: h.line_referential_line_path(@line_referential, object),
+ method: :delete,
+ data: { confirm: h.t('lines.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/chouette/route_decorator.rb
new file mode 100644
index 000000000..d59179278
--- /dev/null
+++ b/app/decorators/chouette/route_decorator.rb
@@ -0,0 +1,43 @@
+# TODO: Figure out @referential, @line, @route_sp
+class Chouette::RouteDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ if @route_sp.any?
+ links << Link.new(
+ content: h.t('journey_patterns.index.title'),
+ href: [@referential, @line, object, :journey_patterns_collection]
+ )
+ end
+
+ if object.journey_patterns.present?
+ links << Link.new(
+ content: h.t('vehicle_journeys.actions.index'),
+ href: [@referential, @line, object, :vehicle_journeys]
+ )
+ end
+
+ links << Link.new(
+ content: h.t('vehicle_journey_exports.new.title'),
+ href: h.referential_line_route_vehicle_journey_exports_path(
+ @referential,
+ @line,
+ object,
+ format: :zip
+ )
+ )
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.referential_line_route_path(@referential, @line, object),
+ method: :delete,
+ data: { confirm: h.t('routes.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/chouette/routing_constraint_zone_decorator.rb b/app/decorators/chouette/routing_constraint_zone_decorator.rb
new file mode 100644
index 000000000..bcf278dda
--- /dev/null
+++ b/app/decorators/chouette/routing_constraint_zone_decorator.rb
@@ -0,0 +1,35 @@
+# TODO: Figure out @referential, @line
+class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ if h.policy(object).update?
+ links << Link.new(
+ content: h.t('actions.edit'),
+ href: h.edit_referential_line_routing_constraint_zone_path(
+ @referential,
+ @line,
+ object
+ )
+ )
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.referential_line_routing_constraint_zone_path(
+ @referential,
+ @line,
+ object
+ ),
+ method: :delete,
+ data: {
+ confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
+ }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/chouette/time_table_decorator.rb b/app/decorators/chouette/time_table_decorator.rb
new file mode 100644
index 000000000..3d9994ea5
--- /dev/null
+++ b/app/decorators/chouette/time_table_decorator.rb
@@ -0,0 +1,42 @@
+# TODO: Add @referential to context
+class Chouette::TimeTableDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+
+ if object.calendar
+ links << Link.new(
+ content: h.t('actions.actualize'),
+ href: h.actualize_referential_time_table_path(@referential, object),
+ method: :post
+ )
+ end
+
+ links << Link.new(
+ content: h.t('actions.combine'),
+ href: h.new_referential_time_table_time_table_combination_path(
+ @referential,
+ object
+ )
+ )
+
+ if h.policy(object).duplicate?
+ links << Link.new(
+ content: h.t('actions.duplicate'),
+ href: h.duplicate_referential_time_table_path(@referential, object)
+ )
+ end
+
+ if h.policy(object).destroy?
+ Link.new(
+ content: h.destroy_link_content,
+ href: h.referential_time_table_path(@referential, object),
+ method: :delete,
+ data: { confirm: h.t('time_tables.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb
index 629d1ff38..bd0441f43 100644
--- a/app/decorators/company_decorator.rb
+++ b/app/decorators/company_decorator.rb
@@ -1,3 +1,4 @@
+# TODO: Move this into the Chouette:: namespace
class CompanyDecorator < Draper::Decorator
decorates Chouette::Company
--
cgit v1.2.3
From ce105d1ddb7f019cf8b55e41aa69c51e651c8ac9 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 12:22:39 +0200
Subject: New decorators: Move instance variables to `context` hash
Draper allows us to pass a `context` hash when decorating objects. This
gives us a way to bring in the instance variables required by a few of
the new decorators I created just a moment ago. We can now safely get
those values inside the decorators.
Refs #3479
---
app/decorators/chouette/line_decorator.rb | 17 ++++++-----
app/decorators/chouette/route_decorator.rb | 33 +++++++++++++++++-----
.../chouette/routing_constraint_zone_decorator.rb | 14 +++++----
app/decorators/chouette/time_table_decorator.rb | 19 +++++++++----
app/decorators/company_decorator.rb | 12 ++++++--
5 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/app/decorators/chouette/line_decorator.rb b/app/decorators/chouette/line_decorator.rb
index 30c093dee..e32acb13b 100644
--- a/app/decorators/chouette/line_decorator.rb
+++ b/app/decorators/chouette/line_decorator.rb
@@ -1,31 +1,34 @@
-# TODO: figure out @line_referential
class Chouette::LineDecorator < Draper::Decorator
delegate_all
+ # Requires:
+ # context: {
+ # line_referential:
+ # }
def action_links
links = []
links << Link.new(
content: h.t('lines.actions.show_network'),
- href: [@line_referential, object.network]
+ href: [context[:line_referential], object.network]
)
links << Link.new(
content: h.t('lines.actions.show_company'),
- href: [@line_referential, object.company]
+ href: [context[:line_referential], object.company]
)
if h.policy(Chouette::Line).create? &&
- @line_referential.organisations.include?(current_organisation)
+ context[:line_referential].organisations.include?(current_organisation)
links << Link.new(
content: h.t('lines.actions.new'),
- href: h.new_line_referential_line_path(@line_referential)
+ href: h.new_line_referential_line_path(context[:line_referential])
)
end
# TODO: what if false? do we delete this?
if false && h.policy(object).update?
- # = link_to t('lines.actions.edit'), edit_line_referential_line_path(@line_referential, object), class: 'btn btn-primary'
+ # = link_to t('lines.actions.edit'), edit_line_referential_line_path(context[:line_referential], object), class: 'btn btn-primary'
end
if h.policy(object).destroy?
@@ -33,7 +36,7 @@ class Chouette::LineDecorator < Draper::Decorator
# TODO: this translation is different!
span = t('lines.actions.destroy')
content: h.destroy_link_content,
- href: h.line_referential_line_path(@line_referential, object),
+ href: h.line_referential_line_path(context[:line_referential], object),
method: :delete,
data: { confirm: h.t('lines.actions.destroy_confirm') }
)
diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/chouette/route_decorator.rb
index d59179278..f98fbfcb1 100644
--- a/app/decorators/chouette/route_decorator.rb
+++ b/app/decorators/chouette/route_decorator.rb
@@ -1,29 +1,44 @@
-# TODO: Figure out @referential, @line, @route_sp
class Chouette::RouteDecorator < Draper::Decorator
delegate_all
+ # Requires:
+ # context: {
+ # referential: ,
+ # line: ,
+ # route_sp
+ # }
def action_links
links = []
- if @route_sp.any?
+ if context[:route_sp].any?
links << Link.new(
content: h.t('journey_patterns.index.title'),
- href: [@referential, @line, object, :journey_patterns_collection]
+ href: [
+ context[:referential],
+ context[:line],
+ object,
+ :journey_patterns_collection
+ ]
)
end
if object.journey_patterns.present?
links << Link.new(
content: h.t('vehicle_journeys.actions.index'),
- href: [@referential, @line, object, :vehicle_journeys]
+ href: [
+ context[:referential],
+ context[:line],
+ object,
+ :vehicle_journeys
+ ]
)
end
links << Link.new(
content: h.t('vehicle_journey_exports.new.title'),
href: h.referential_line_route_vehicle_journey_exports_path(
- @referential,
- @line,
+ context[:referential],
+ context[:line],
object,
format: :zip
)
@@ -32,7 +47,11 @@ class Chouette::RouteDecorator < Draper::Decorator
if h.policy(object).destroy?
links << Link.new(
content: h.destroy_link_content,
- href: h.referential_line_route_path(@referential, @line, object),
+ href: h.referential_line_route_path(
+ context[:referential],
+ context[:line],
+ object
+ ),
method: :delete,
data: { confirm: h.t('routes.actions.destroy_confirm') }
)
diff --git a/app/decorators/chouette/routing_constraint_zone_decorator.rb b/app/decorators/chouette/routing_constraint_zone_decorator.rb
index bcf278dda..f95206064 100644
--- a/app/decorators/chouette/routing_constraint_zone_decorator.rb
+++ b/app/decorators/chouette/routing_constraint_zone_decorator.rb
@@ -1,7 +1,11 @@
-# TODO: Figure out @referential, @line
class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator
delegate_all
+ # Requires:
+ # context: {
+ # referential: ,
+ # line:
+ # }
def action_links
links = []
@@ -9,8 +13,8 @@ class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator
links << Link.new(
content: h.t('actions.edit'),
href: h.edit_referential_line_routing_constraint_zone_path(
- @referential,
- @line,
+ context[:referential],
+ context[:line],
object
)
)
@@ -19,8 +23,8 @@ class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator
links << Link.new(
content: h.destroy_link_content,
href: h.referential_line_routing_constraint_zone_path(
- @referential,
- @line,
+ context[:referential],
+ context[:line],
object
),
method: :delete,
diff --git a/app/decorators/chouette/time_table_decorator.rb b/app/decorators/chouette/time_table_decorator.rb
index 3d9994ea5..7f2dbf5f1 100644
--- a/app/decorators/chouette/time_table_decorator.rb
+++ b/app/decorators/chouette/time_table_decorator.rb
@@ -1,14 +1,20 @@
-# TODO: Add @referential to context
class Chouette::TimeTableDecorator < Draper::Decorator
delegate_all
+ # Requires:
+ # context: {
+ # referential: ,
+ # }
def action_links
links = []
if object.calendar
links << Link.new(
content: h.t('actions.actualize'),
- href: h.actualize_referential_time_table_path(@referential, object),
+ href: h.actualize_referential_time_table_path(
+ context[:referential],
+ object
+ ),
method: :post
)
end
@@ -16,7 +22,7 @@ class Chouette::TimeTableDecorator < Draper::Decorator
links << Link.new(
content: h.t('actions.combine'),
href: h.new_referential_time_table_time_table_combination_path(
- @referential,
+ context[:referential],
object
)
)
@@ -24,14 +30,17 @@ class Chouette::TimeTableDecorator < Draper::Decorator
if h.policy(object).duplicate?
links << Link.new(
content: h.t('actions.duplicate'),
- href: h.duplicate_referential_time_table_path(@referential, object)
+ href: h.duplicate_referential_time_table_path(
+ context[:referential],
+ object
+ )
)
end
if h.policy(object).destroy?
Link.new(
content: h.destroy_link_content,
- href: h.referential_time_table_path(@referential, object),
+ href: h.referential_time_table_path(context[:referential], object),
method: :delete,
data: { confirm: h.t('time_tables.actions.destroy_confirm') }
)
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb
index bd0441f43..3bd85319c 100644
--- a/app/decorators/company_decorator.rb
+++ b/app/decorators/company_decorator.rb
@@ -18,21 +18,27 @@ class CompanyDecorator < Draper::Decorator
if h.policy(Chouette::Company).create?
links << Link.new(
content: h.t('companies.actions.new'),
- href: h.new_line_referential_company_path(@line_referential)
+ href: h.new_line_referential_company_path(context[:line_referential])
)
end
if h.policy(object).update?
links << Link.new(
content: h.t('companies.actions.edit'),
- href: h.edit_line_referential_company_path(@line_referential, object)
+ href: h.edit_line_referential_company_path(
+ context[:line_referential],
+ object
+ )
)
end
if h.policy(object).destroy?
links << Link.new(
content: t('companies.actions.destroy'),
- href: h.line_referential_company_path(@line_referential, object),
+ href: h.line_referential_company_path(
+ context[:line_referential],
+ object
+ ),
method: :delete,
data: { confirm: t('companies.actions.destroy_confirm') }
)
--
cgit v1.2.3
From 84ebcffb06d9ba9a56cc29d1739f1f950649f82e Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 15:31:19 +0200
Subject: Routes#show: Use RouteDecorator#action_links to render header links
Instead of defining the header links in the view, get them from our
decorator so we can reuse them. Need to wrap `@route` in the decorator
in the controller and pass it the necessary context in order for it to
be able to properly build links.
Move `Chouette::RouteDecorator` to the top level app/decorators/
directory and remove it from the `Chouette` namespace. I had put it
there to make it more similar to our model directory layout, but Draper
isn't intelligent enough to look in subdirectories of `decorators` when
using the `ActiveRecord::Base#decorate` method. Otherwise I suppose I
could do `Chouette::RouteDecorator.decorate(@route)`, but that seemed
not as clean since it doesn't take advantage of the default behaviour of
Draper. Now going to have to do this for the other decorators.
Refs #3479
---
app/controllers/routes_controller.rb | 6 +++
app/decorators/chouette/route_decorator.rb | 62 -----------------------------
app/decorators/route_decorator.rb | 64 ++++++++++++++++++++++++++++++
app/views/routes/show.html.slim | 17 +++-----
4 files changed, 76 insertions(+), 73 deletions(-)
delete mode 100644 app/decorators/chouette/route_decorator.rb
create mode 100644 app/decorators/route_decorator.rb
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 73febc4b9..786bd57cc 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -42,6 +42,12 @@ class RoutesController < ChouetteController
end
show! do
+ @route = @route.decorate(context: {
+ referential: @referential,
+ line: @line,
+ route_sp: @route_sp
+ })
+
build_breadcrumb :show
end
end
diff --git a/app/decorators/chouette/route_decorator.rb b/app/decorators/chouette/route_decorator.rb
deleted file mode 100644
index f98fbfcb1..000000000
--- a/app/decorators/chouette/route_decorator.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-class Chouette::RouteDecorator < Draper::Decorator
- delegate_all
-
- # Requires:
- # context: {
- # referential: ,
- # line: ,
- # route_sp
- # }
- def action_links
- links = []
-
- if context[:route_sp].any?
- links << Link.new(
- content: h.t('journey_patterns.index.title'),
- href: [
- context[:referential],
- context[:line],
- object,
- :journey_patterns_collection
- ]
- )
- end
-
- if object.journey_patterns.present?
- links << Link.new(
- content: h.t('vehicle_journeys.actions.index'),
- href: [
- context[:referential],
- context[:line],
- object,
- :vehicle_journeys
- ]
- )
- 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
- )
- )
-
- if h.policy(object).destroy?
- links << Link.new(
- content: h.destroy_link_content,
- href: h.referential_line_route_path(
- context[:referential],
- context[:line],
- object
- ),
- method: :delete,
- data: { confirm: h.t('routes.actions.destroy_confirm') }
- )
- end
-
- links
- end
-end
diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb
new file mode 100644
index 000000000..99b174dff
--- /dev/null
+++ b/app/decorators/route_decorator.rb
@@ -0,0 +1,64 @@
+class RouteDecorator < Draper::Decorator
+ decorates Chouette::Route
+
+ delegate_all
+
+ # Requires:
+ # context: {
+ # referential: ,
+ # line: ,
+ # route_sp
+ # }
+ def action_links
+ links = []
+
+ if context[:route_sp].any?
+ links << Link.new(
+ content: h.t('journey_patterns.index.title'),
+ href: [
+ context[:referential],
+ context[:line],
+ object,
+ :journey_patterns_collection
+ ]
+ )
+ end
+
+ if object.journey_patterns.present?
+ links << Link.new(
+ content: h.t('vehicle_journeys.actions.index'),
+ href: [
+ context[:referential],
+ context[:line],
+ object,
+ :vehicle_journeys
+ ]
+ )
+ 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
+ )
+ )
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.referential_line_route_path(
+ context[:referential],
+ context[:line],
+ object
+ ),
+ method: :delete,
+ data: { confirm: h.t('routes.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index 6d2d4e90d..92a5080ae 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -8,17 +8,12 @@
/ Below is secundary actions & optional contents (filters, ...)
.row.mb-sm
.col-lg-12.text-right
- - if @route_sp.any?
- = link_to t('journey_patterns.index.title'), [@referential, @line, @route, :journey_patterns_collection], class: 'btn btn-primary'
- - if @route.journey_patterns.present?
- = link_to t('vehicle_journeys.actions.index'), [@referential, @line, @route, :vehicle_journeys], class: 'btn btn-primary'
-
- = link_to t('vehicle_journey_exports.new.title'), referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, format: :zip), class: 'btn btn-primary'
-
- - if policy(@route).destroy?
- = link_to referential_line_route_path(@referential, @line, @route), method: :delete, data: {confirm: t('routes.actions.destroy_confirm')}, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('actions.destroy')
+ - @route.action_links.each do |link|
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ = link.content
/ PageContent
.page_content
--
cgit v1.2.3
From 3a9dbe0db981536ea7c138915e423ac009235c60 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 15:39:34 +0200
Subject: Move Chouette:: decorators to root decorators/ directory
Draper doesn't seem to look for decorators in subdirectories of
decorators/, so instead of writing things like:
@line = Chouette::LineDecorator.decorate(@line)
in the controller, move the decorators to the root of decorators/ to
allow us to continue using this syntax:
@line = @line.decorate
Refs #3479
---
app/decorators/chouette/line_decorator.rb | 47 -------------------
.../chouette/routing_constraint_zone_decorator.rb | 39 ----------------
app/decorators/chouette/time_table_decorator.rb | 51 ---------------------
app/decorators/company_decorator.rb | 1 -
app/decorators/line_decorator.rb | 49 ++++++++++++++++++++
.../routing_constraint_zone_decorator.rb | 41 +++++++++++++++++
app/decorators/time_table_decorator.rb | 53 ++++++++++++++++++++++
7 files changed, 143 insertions(+), 138 deletions(-)
delete mode 100644 app/decorators/chouette/line_decorator.rb
delete mode 100644 app/decorators/chouette/routing_constraint_zone_decorator.rb
delete mode 100644 app/decorators/chouette/time_table_decorator.rb
create mode 100644 app/decorators/line_decorator.rb
create mode 100644 app/decorators/routing_constraint_zone_decorator.rb
create mode 100644 app/decorators/time_table_decorator.rb
diff --git a/app/decorators/chouette/line_decorator.rb b/app/decorators/chouette/line_decorator.rb
deleted file mode 100644
index e32acb13b..000000000
--- a/app/decorators/chouette/line_decorator.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-class Chouette::LineDecorator < Draper::Decorator
- delegate_all
-
- # Requires:
- # context: {
- # line_referential:
- # }
- def action_links
- links = []
-
- links << Link.new(
- content: h.t('lines.actions.show_network'),
- href: [context[:line_referential], object.network]
- )
-
- links << Link.new(
- content: h.t('lines.actions.show_company'),
- href: [context[:line_referential], object.company]
- )
-
- if h.policy(Chouette::Line).create? &&
- context[:line_referential].organisations.include?(current_organisation)
- links << Link.new(
- content: h.t('lines.actions.new'),
- href: h.new_line_referential_line_path(context[:line_referential])
- )
- end
-
- # TODO: what if false? do we delete this?
- if false && h.policy(object).update?
- # = link_to t('lines.actions.edit'), edit_line_referential_line_path(context[:line_referential], object), class: 'btn btn-primary'
- end
-
- if h.policy(object).destroy?
- links << Link.new(
-# TODO: this translation is different!
-span = t('lines.actions.destroy')
- content: h.destroy_link_content,
- href: h.line_referential_line_path(context[:line_referential], object),
- method: :delete,
- data: { confirm: h.t('lines.actions.destroy_confirm') }
- )
- end
-
- links
- end
-end
diff --git a/app/decorators/chouette/routing_constraint_zone_decorator.rb b/app/decorators/chouette/routing_constraint_zone_decorator.rb
deleted file mode 100644
index f95206064..000000000
--- a/app/decorators/chouette/routing_constraint_zone_decorator.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-class Chouette::RoutingConstraintZoneDecorator < Draper::Decorator
- delegate_all
-
- # Requires:
- # context: {
- # referential: ,
- # line:
- # }
- def action_links
- links = []
-
- if h.policy(object).update?
- links << Link.new(
- content: h.t('actions.edit'),
- href: h.edit_referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line],
- object
- )
- )
-
- if h.policy(object).destroy?
- links << Link.new(
- content: h.destroy_link_content,
- href: h.referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line],
- object
- ),
- method: :delete,
- data: {
- confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
- }
- )
- end
-
- links
- end
-end
diff --git a/app/decorators/chouette/time_table_decorator.rb b/app/decorators/chouette/time_table_decorator.rb
deleted file mode 100644
index 7f2dbf5f1..000000000
--- a/app/decorators/chouette/time_table_decorator.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-class Chouette::TimeTableDecorator < Draper::Decorator
- delegate_all
-
- # Requires:
- # context: {
- # referential: ,
- # }
- def action_links
- links = []
-
- if object.calendar
- links << Link.new(
- content: h.t('actions.actualize'),
- href: h.actualize_referential_time_table_path(
- context[:referential],
- object
- ),
- method: :post
- )
- end
-
- links << Link.new(
- content: h.t('actions.combine'),
- href: h.new_referential_time_table_time_table_combination_path(
- context[:referential],
- object
- )
- )
-
- if h.policy(object).duplicate?
- links << Link.new(
- content: h.t('actions.duplicate'),
- href: h.duplicate_referential_time_table_path(
- context[:referential],
- object
- )
- )
- end
-
- if h.policy(object).destroy?
- 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') }
- )
- end
-
- links
- end
-end
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb
index 3bd85319c..4adc51cc2 100644
--- a/app/decorators/company_decorator.rb
+++ b/app/decorators/company_decorator.rb
@@ -1,4 +1,3 @@
-# TODO: Move this into the Chouette:: namespace
class CompanyDecorator < Draper::Decorator
decorates Chouette::Company
diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb
new file mode 100644
index 000000000..84f6cba91
--- /dev/null
+++ b/app/decorators/line_decorator.rb
@@ -0,0 +1,49 @@
+class LineDecorator < Draper::Decorator
+ decorates Chouette::Line
+
+ delegate_all
+
+ # Requires:
+ # context: {
+ # line_referential:
+ # }
+ def action_links
+ links = []
+
+ links << Link.new(
+ content: h.t('lines.actions.show_network'),
+ href: [context[:line_referential], object.network]
+ )
+
+ links << Link.new(
+ content: h.t('lines.actions.show_company'),
+ href: [context[:line_referential], object.company]
+ )
+
+ if h.policy(Chouette::Line).create? &&
+ context[:line_referential].organisations.include?(current_organisation)
+ links << Link.new(
+ content: h.t('lines.actions.new'),
+ href: h.new_line_referential_line_path(context[:line_referential])
+ )
+ end
+
+ # TODO: what if false? do we delete this?
+ if false && h.policy(object).update?
+ # = link_to t('lines.actions.edit'), edit_line_referential_line_path(context[:line_referential], object), class: 'btn btn-primary'
+ end
+
+ if h.policy(object).destroy?
+ links << Link.new(
+# TODO: this translation is different!
+span = t('lines.actions.destroy')
+ content: h.destroy_link_content,
+ href: h.line_referential_line_path(context[:line_referential], object),
+ method: :delete,
+ data: { confirm: h.t('lines.actions.destroy_confirm') }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb
new file mode 100644
index 000000000..4b5df20c1
--- /dev/null
+++ b/app/decorators/routing_constraint_zone_decorator.rb
@@ -0,0 +1,41 @@
+class RoutingConstraintZoneDecorator < Draper::Decorator
+ decorates Chouette::RoutingConstraintZone
+
+ delegate_all
+
+ # Requires:
+ # context: {
+ # referential: ,
+ # line:
+ # }
+ def action_links
+ links = []
+
+ if h.policy(object).update?
+ links << Link.new(
+ content: h.t('actions.edit'),
+ href: h.edit_referential_line_routing_constraint_zone_path(
+ context[:referential],
+ context[:line],
+ object
+ )
+ )
+
+ if h.policy(object).destroy?
+ links << Link.new(
+ content: h.destroy_link_content,
+ href: h.referential_line_routing_constraint_zone_path(
+ context[:referential],
+ context[:line],
+ object
+ ),
+ method: :delete,
+ data: {
+ confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
+ }
+ )
+ end
+
+ links
+ end
+end
diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb
new file mode 100644
index 000000000..57661c627
--- /dev/null
+++ b/app/decorators/time_table_decorator.rb
@@ -0,0 +1,53 @@
+class TimeTableDecorator < Draper::Decorator
+ decorates Chouette::TimeTable
+
+ delegate_all
+
+ # Requires:
+ # context: {
+ # referential: ,
+ # }
+ def action_links
+ links = []
+
+ if object.calendar
+ links << Link.new(
+ content: h.t('actions.actualize'),
+ href: h.actualize_referential_time_table_path(
+ context[:referential],
+ object
+ ),
+ method: :post
+ )
+ end
+
+ links << Link.new(
+ content: h.t('actions.combine'),
+ href: h.new_referential_time_table_time_table_combination_path(
+ context[:referential],
+ object
+ )
+ )
+
+ if h.policy(object).duplicate?
+ links << Link.new(
+ content: h.t('actions.duplicate'),
+ href: h.duplicate_referential_time_table_path(
+ context[:referential],
+ object
+ )
+ )
+ end
+
+ if h.policy(object).destroy?
+ 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') }
+ )
+ end
+
+ links
+ end
+end
--
cgit v1.2.3
From 6f1fa09dd12979933bef8bb97cdc6ae4ff10a9f0 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 15:58:02 +0200
Subject: RoutingConstraintZones#show: Render header links from #action_links
Use the `RoutingConstraintZonesDecorator` to render the header links
instead of constructing them in the view. This allows us to reuse the
links.
To be honest, I haven't actually tested this for real. Don't know how to
set up an Interdiction de Traffic Local.
Refs #3479
---
app/controllers/routing_constraint_zones_controller.rb | 4 ++++
app/views/routing_constraint_zones/show.html.slim | 13 ++++++-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index 7707427b0..9d2fd712c 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -16,6 +16,10 @@ class RoutingConstraintZonesController < ChouetteController
def show
@routing_constraint_zone = collection.find(params[:id])
+ @routing_constraint_zone = @routing_constraint_zone.decorate(context: {
+ referential: @referential,
+ line: @line
+ })
end
protected
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index f0c244387..1dad4f561 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -7,13 +7,12 @@
/ Below is secundary actions & optional contents
.row
.col-lg-12.text-right.mb-sm
- - if policy(@routing_constraint_zone).update?
- = link_to t('actions.edit'), edit_referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), class: 'btn btn-primary'
-
- - if policy(@routing_constraint_zone).destroy?
- = link_to referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), method: :delete, data: {confirm: t('routing_constraint_zones.actions.destroy_confirm')}, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('actions.destroy')
+ - @routing_constraint_zone.action_links.each do |link|
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ = link.content
/ PageContent
.page_content
--
cgit v1.2.3
From 7d45b2f803d4f14f1aa0d713b0c43ed9f41a41e7 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:22:13 +0200
Subject: CompanyDecorator#action_links: Add comment about `context`
requirement
Show what keys are required to be passed as `context` to the decorator.
Missed this when I added the `context` dependency.
Refs #3479
---
app/decorators/company_decorator.rb | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb
index 4adc51cc2..5393a5c3a 100644
--- a/app/decorators/company_decorator.rb
+++ b/app/decorators/company_decorator.rb
@@ -11,6 +11,10 @@ class CompanyDecorator < Draper::Decorator
object.lines.count
end
+ # Requires:
+ # context: {
+ # line_referential:
+ # }
def action_links
links = []
--
cgit v1.2.3
From d4de52d63f400f30dabb7034e14202f5c9bd0192 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:24:15 +0200
Subject: Lines#show: Render header links from #action_links
Get the header links from the decorator so we can reuse them instead of
defining them directly in the template.
Add an option to the `destroy_link_content` Rails helper method to allow
us to specify alternate translation keys, giving us different text in
the button label. Added this because the template in question uses a
different label than the others (usually it's `actions.destroy`).
Refs #3479
---
app/controllers/lines_controller.rb | 4 ++++
app/decorators/line_decorator.rb | 4 +---
app/helpers/links_helper.rb | 4 ++--
app/views/lines/show.html.slim | 17 ++++++-----------
4 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 7eedaeb05..c3378208b 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -25,6 +25,10 @@ class LinesController < BreadcrumbController
def show
@group_of_lines = resource.group_of_lines
show! do
+ @line = @line.decorate(context: {
+ line_referential: @line_referential
+ })
+
build_breadcrumb :show
end
end
diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb
index 84f6cba91..53053ed2c 100644
--- a/app/decorators/line_decorator.rb
+++ b/app/decorators/line_decorator.rb
@@ -35,9 +35,7 @@ class LineDecorator < Draper::Decorator
if h.policy(object).destroy?
links << Link.new(
-# TODO: this translation is different!
-span = t('lines.actions.destroy')
- content: h.destroy_link_content,
+ content: h.destroy_link_content('lines.actions.destroy_confirm'),
href: h.line_referential_line_path(context[:line_referential], object),
method: :delete,
data: { confirm: h.t('lines.actions.destroy_confirm') }
diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb
index b9923db2f..683b66a52 100644
--- a/app/helpers/links_helper.rb
+++ b/app/helpers/links_helper.rb
@@ -1,5 +1,5 @@
module LinksHelper
- def destroy_link_content
- content_tag(:span, nil, class: 'fa fa-trash') + t('actions.destroy')
+ def destroy_link_content(translation_key = 'actions.destroy')
+ content_tag(:span, nil, class: 'fa fa-trash') + t(translation_key)
end
end
diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim
index dbc019e72..6f75432e1 100644
--- a/app/views/lines/show.html.slim
+++ b/app/views/lines/show.html.slim
@@ -7,17 +7,12 @@
/ Below is secundary actions & optional contents
.row
.col-lg-12.text-right.mb-sm
- = link_to t('lines.actions.show_network'), [@line_referential, @line.network], class: 'btn btn-primary'
- = link_to t('lines.actions.show_company'), [@line_referential, @line.company], class: 'btn btn-primary'
-
- - if policy(Chouette::Line).create? && @line_referential.organisations.include?(current_organisation)
- = link_to t('lines.actions.new'), new_line_referential_line_path(@line_referential), class: 'btn btn-primary'
- - if false && policy(@line).update?
- = link_to t('lines.actions.edit'), edit_line_referential_line_path(@line_referential, @line), class: 'btn btn-primary'
- - if policy(@line).destroy?
- = link_to line_referential_line_path(@line_referential, @line), method: :delete, data: {confirm: t('lines.actions.destroy_confirm')}, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('lines.actions.destroy')
+ - @line.action_links.each do |link|
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ = link.content
/ PageContent
.page_content
--
cgit v1.2.3
From 7fe8b7d100e92060a14f7c7bc32a097947dd860e Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:27:06 +0200
Subject: TimeTableDecorator#action_links: Add missing destroy link
Wasn't adding the destroy link to the `links` list, so it didn't get
added to the header buttons.
Refs #3479
---
app/decorators/time_table_decorator.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb
index 57661c627..526537310 100644
--- a/app/decorators/time_table_decorator.rb
+++ b/app/decorators/time_table_decorator.rb
@@ -40,7 +40,7 @@ class TimeTableDecorator < Draper::Decorator
end
if h.policy(object).destroy?
- Link.new(
+ links << Link.new(
content: h.destroy_link_content,
href: h.referential_time_table_path(context[:referential], object),
method: :delete,
--
cgit v1.2.3
From 4e81e22aff65221316c1528a3f2fa82272345c65 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:28:27 +0200
Subject: Calendars#show: Use #action_links to render header buttons
To abstract the links and make them reusable in other contexts, render
the buttons in the header from `CalendarDecorator#action_links`.
Refs #3479
---
app/controllers/calendars_controller.rb | 4 ++++
app/views/calendars/show.html.slim | 10 ++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 86d567882..432e528f0 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -5,6 +5,10 @@ class CalendarsController < BreadcrumbController
respond_to :html
respond_to :js, only: :index
+ def show
+ @calendar = @calendar.decorate
+ end
+
private
def calendar_params
permitted_params = [:id, :name, :short_name, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]
diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim
index 3886cefaa..26248cea8 100644
--- a/app/views/calendars/show.html.slim
+++ b/app/views/calendars/show.html.slim
@@ -8,10 +8,12 @@
/ Below is secondary actions & optional contents (filters, ...)
.row.mb-sm
.col-lg-12.text-right
- - if policy(@calendar).destroy?
- = link_to calendar_path(@calendar), method: :delete, data: { confirm: t('calendars.actions.destroy_confirm') }, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('actions.destroy')
+ - @calendar.action_links.each do |link|
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ = link.content
/ PageContent
.page_content
--
cgit v1.2.3
From 9de20c519a60443157ed277a1c68b46f00229598 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:29:32 +0200
Subject: TimeTables#show: Render header buttons from #action_links
This enables us to reuse these links in other parts of the application.
Get the links from `TimeTableDecorator#action_links`.
Refs #3479
---
app/controllers/time_tables_controller.rb | 4 ++++
app/views/time_tables/show.html.slim | 21 ++++++---------------
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index 5c4552afb..3704f2885 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -14,6 +14,10 @@ class TimeTablesController < ChouetteController
@year = params[:year] ? params[:year].to_i : Date.today.cwyear
@time_table_combination = TimeTableCombination.new
show! do
+ @time_table = @time_table.decorate(context: {
+ referential: @referential
+ })
+
build_breadcrumb :show
end
end
diff --git a/app/views/time_tables/show.html.slim b/app/views/time_tables/show.html.slim
index 2e71ebb9e..f596fd480 100644
--- a/app/views/time_tables/show.html.slim
+++ b/app/views/time_tables/show.html.slim
@@ -10,21 +10,12 @@
/ Below is secundary actions & optional contents (filters, ...)
.row.mb-sm
.col-lg-12.text-right
- / - if policy(@time_table).create? && @referential.organisation == current_organisation
- / = link_to t('time_tables.actions.new'), new_referential_time_table_path(@referential), class: 'btn btn-primary'
- - if @time_table.calendar
- = link_to t('actions.actualize'), actualize_referential_time_table_path(@referential, @time_table), method: :post, class: 'btn btn-primary'
-
- /- if policy(@time_table).create? && @referential.organisation == current_organisation
- = link_to t('actions.combine'), new_referential_time_table_time_table_combination_path(@referential, @time_table), class: 'btn btn-primary'
-
- - if policy(@time_table).duplicate?
- = link_to t('actions.duplicate'), duplicate_referential_time_table_path(@referential, @time_table), class: 'btn btn-primary'
-
- - if policy(@time_table).destroy?
- = link_to referential_time_table_path(@referential, @time_table), method: :delete, data: {confirm: t('time_tables.actions.destroy_confirm')}, class: 'btn btn-primary' do
- span.fa.fa-trash
- span = t('actions.destroy')
+ - @time_table.action_links.each do |link|
+ = link_to link.href,
+ method: link.method,
+ data: link.data,
+ class: 'btn btn-primary' do
+ = link.content
/ PageContent
.page_content
--
cgit v1.2.3
From 1f569d51d82f741811b36080df47bde94c3ad58c Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:31:20 +0200
Subject: LineDecorator: Remove unused link
This link was brought in from the "time_tables/show.html.slim" template
when I ported the links over to `LineDecorator#action_links`. The link
was wrapped in an `if false` from
5bd3973fae2c1e02c2bef31d5b12dc10b1a133c9. Presumably we no longer care
about that edit link, so since the code never executes, I'm deleting it.
Refs #3479
---
app/decorators/line_decorator.rb | 5 -----
1 file changed, 5 deletions(-)
diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb
index 53053ed2c..d4a616a97 100644
--- a/app/decorators/line_decorator.rb
+++ b/app/decorators/line_decorator.rb
@@ -28,11 +28,6 @@ class LineDecorator < Draper::Decorator
)
end
- # TODO: what if false? do we delete this?
- if false && h.policy(object).update?
- # = link_to t('lines.actions.edit'), edit_line_referential_line_path(context[:line_referential], object), class: 'btn btn-primary'
- end
-
if h.policy(object).destroy?
links << Link.new(
content: h.destroy_link_content('lines.actions.destroy_confirm'),
--
cgit v1.2.3
From f483c2db410f78287e77ac968a7229b0d5e5b835 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Mon, 19 Jun 2017 17:47:40 +0200
Subject: TableBuilder spec: Remove TODO
We're how have a separate module for the box containing links to perform
actions on selections of multiple objects in the table. I had put this
in `MultipleSelectionToolboxHelper`.
Refs #3479
---
spec/helpers/table_builder_helper_spec.rb | 6 ------
1 file changed, 6 deletions(-)
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index a61fd2343..32a6a3bfd 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -90,12 +90,6 @@ describe TableBuilderHelper, type: :helper do
|