diff options
| author | Teddy Wing | 2017-07-11 19:41:29 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-07-12 11:11:14 +0200 |
| commit | ebd714e18ae8e954b5862b5ab70ea47a22674795 (patch) | |
| tree | 28980d3e8e1d7aed741f7da7b5f834054ecfab68 | |
| parent | a021c872a51271ac43a253cffdd55761200bbee6 (diff) | |
| download | chouette-core-ebd714e18ae8e954b5862b5ab70ea47a22674795.tar.bz2 | |
StopPointDecorator#action_links: Remove code duplication
Remove the duplication between this method and
`StopAreaDecorator#action_links`. For now used inheritance, but this
will not be a good idea if the two need separate decorator
functionality. In that case, `#action_links` should probably be split
out into a separate module for both of them to use.
Refs #3479
| -rw-r--r-- | app/decorators/stop_area_decorator.rb | 17 | ||||
| -rw-r--r-- | app/decorators/stop_point_decorator.rb | 39 |
2 files changed, 11 insertions, 45 deletions
diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 1f3b3d16c..4e777292d 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -3,34 +3,35 @@ class StopAreaDecorator < Draper::Decorator delegate_all - def action_links + def action_links(stop_area = nil) links = [] + stop_area ||= object if h.policy(Chouette::StopArea).new? links << Link.new( content: h.t('stop_areas.actions.new'), href: h.new_stop_area_referential_stop_area_path( - object.stop_area_referential + stop_area.stop_area_referential ) ) end - if h.policy(object).update? + if h.policy(stop_area).update? links << Link.new( content: h.t('stop_areas.actions.edit'), href: h.edit_stop_area_referential_stop_area_path( - object.stop_area_referential, - object + stop_area.stop_area_referential, + stop_area ) ) end - if h.policy(object).destroy? + if h.policy(stop_area).destroy? links << Link.new( content: h.destroy_link_content('stop_areas.actions.destroy'), href: h.stop_area_referential_stop_area_path( - object.stop_area_referential, - object + stop_area.stop_area_referential, + stop_area ), method: :delete, data: { confirm: t('stop_areas.actions.destroy_confirm') } diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb index a7229226f..196d6d490 100644 --- a/app/decorators/stop_point_decorator.rb +++ b/app/decorators/stop_point_decorator.rb @@ -1,44 +1,9 @@ -class StopPointDecorator < Draper::Decorator +class StopPointDecorator < StopAreaDecorator decorates Chouette::StopPoint delegate_all def action_links - links = [] - - stop_area = object.stop_area - - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential - ) - ) - end - - if h.policy(stop_area).update? - links << Link.new( - content: h.t('stop_areas.actions.edit'), - href: h.edit_stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ) - ) - end - - if h.policy(stop_area).destroy? - links << Link.new( - content: h.destroy_link_content('stop_areas.actions.destroy'), - href: h.stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ), - method: :delete, - data: { confirm: t('stop_areas.actions.destroy_confirm') } - ) - end - - links + super(object.stop_area) end end |
