diff options
| author | Teddy Wing | 2017-06-09 16:12:45 +0200 |
|---|---|---|
| committer | Teddy Wing | 2017-06-09 16:12:45 +0200 |
| commit | 0b9e41d57fdba19bf3d9a61029e2fd688fbf61f2 (patch) | |
| tree | 459500ebcb620415bb74e36c9684e10714be647e | |
| parent | 8674d00185602c76b5231282ac87ea746ab1a2f2 (diff) | |
| download | chouette-core-0b9e41d57fdba19bf3d9a61029e2fd688fbf61f2.tar.bz2 | |
TableBuilderHelper: Extract polymorphic URL block to method
Get rid of the duplication in these two sections by extracting the code
to a method. Still not a huge fan of how it's set up, but this at least
gives us an incremental improvement.
Refs #3479
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 83c7a0689..586842d46 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -75,24 +75,8 @@ module TableBuilderHelper end # if so this column's contents get transformed into a link to the object if attribute == 'name' || attribute == 'comment' - lnk = [] - - unless item.is_a?(Calendar) || item.is_a?(Referential) - if current_referential - lnk << current_referential - lnk << item.line if item.respond_to? :line - lnk << item.route.line if item.is_a?(Chouette::RoutingConstraintZone) - lnk << item if item.respond_to? :line_referential - lnk << item.stop_area if item.respond_to? :stop_area - lnk << item if item.respond_to? :stop_points || item.is_a?(Chouette::TimeTable) - elsif item.respond_to? :referential - lnk << item.referential - end - else - lnk << item - end - - bcont << content_tag(:td, link_to(value, lnk), title: 'Voir') + polymorph_url = polymorphic_url_parts(item) + bcont << content_tag(:td, link_to(value, polymorph_url), title: 'Voir') else bcont << content_tag(:td, value) end @@ -119,20 +103,7 @@ module TableBuilderHelper polymorph_url << action end - unless item.is_a?(Calendar) || item.is_a?(Referential) - if current_referential - polymorph_url << current_referential - polymorph_url << item.line if item.respond_to? :line - polymorph_url << item.route.line if item.is_a?(Chouette::RoutingConstraintZone) - polymorph_url << item if item.respond_to? :line_referential - polymorph_url << item.stop_area if item.respond_to? :stop_area - polymorph_url << item if item.respond_to? :stop_points || item.is_a?(Chouette::TimeTable) - elsif item.respond_to? :referential - polymorph_url << item.referential - end - else - polymorph_url << item - end + polymorph_url += polymorphic_url_parts(item) if action == :delete if policy(item).present? @@ -215,4 +186,25 @@ module TableBuilderHelper ) end end + + def polymorphic_url_parts(item) + polymorph_url = [] + + unless item.is_a?(Calendar) || item.is_a?(Referential) + if current_referential + polymorph_url << current_referential + polymorph_url << item.line if item.respond_to? :line + polymorph_url << item.route.line if item.is_a?(Chouette::RoutingConstraintZone) + polymorph_url << item if item.respond_to? :line_referential + polymorph_url << item.stop_area if item.respond_to? :stop_area + polymorph_url << item if item.respond_to? :stop_points || item.is_a?(Chouette::TimeTable) + elsif item.respond_to? :referential + polymorph_url << item.referential + end + else + polymorph_url << item + end + + polymorph_url + end end |
