diff options
| author | Teddy Wing | 2017-06-19 12:06:23 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-19 15:11:33 +0200 |
| commit | ad21d8990a99d24b72b45ccc1d261ddc93179bfd (patch) | |
| tree | 5430f7241c590dace670a588c0e307f0567b5072 | |
| parent | a417f0a2f2813fbec7e3c925334433f6a724405d (diff) | |
| download | chouette-core-ad21d8990a99d24b72b45ccc1d261ddc93179bfd.tar.bz2 | |
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
| -rw-r--r-- | app/decorators/calendar_decorator.rb | 18 | ||||
| -rw-r--r-- | app/decorators/chouette/line_decorator.rb | 44 | ||||
| -rw-r--r-- | app/decorators/chouette/route_decorator.rb | 43 | ||||
| -rw-r--r-- | app/decorators/chouette/routing_constraint_zone_decorator.rb | 35 | ||||
| -rw-r--r-- | app/decorators/chouette/time_table_decorator.rb | 42 | ||||
| -rw-r--r-- | app/decorators/company_decorator.rb | 1 |
6 files changed, 183 insertions, 0 deletions
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 |
