aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTeddy Wing2017-06-19 12:22:39 +0200
committerTeddy Wing2017-06-19 15:11:34 +0200
commitce105d1ddb7f019cf8b55e41aa69c51e651c8ac9 (patch)
tree744344c806a40e4d95e76aa87af0e3e10a00aeb9 /app
parentad21d8990a99d24b72b45ccc1d261ddc93179bfd (diff)
downloadchouette-core-ce105d1ddb7f019cf8b55e41aa69c51e651c8ac9.tar.bz2
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
Diffstat (limited to 'app')
-rw-r--r--app/decorators/chouette/line_decorator.rb17
-rw-r--r--app/decorators/chouette/route_decorator.rb33
-rw-r--r--app/decorators/chouette/routing_constraint_zone_decorator.rb14
-rw-r--r--app/decorators/chouette/time_table_decorator.rb19
-rw-r--r--app/decorators/company_decorator.rb12
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') }
)