aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-07-11 19:33:30 +0200
committerTeddy Wing2017-07-12 11:11:14 +0200
commita021c872a51271ac43a253cffdd55761200bbee6 (patch)
treed87df79ec8c51b1f5b5741ebed89107cae6c23e5
parent9fed0c184323de9e5e0bcfe83465cb4e2b153590 (diff)
downloadchouette-core-a021c872a51271ac43a253cffdd55761200bbee6.tar.bz2
Routes#show: Use new table builder helper
Update the table builder helper for the table of `Chouette::StopPoints` on this page. Created a new `StopPointDecorator` which unfortunately has the same code as `StopAreaDecorator`, the only difference being that instead of using `object`, it uses `object.stop_area`. Need to work out how to eliminate that code duplication. Refs #3479
-rw-r--r--app/controllers/routes_controller.rb5
-rw-r--r--app/decorators/stop_point_decorator.rb44
-rw-r--r--app/views/routes/show.html.slim50
3 files changed, 87 insertions, 12 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 4781d0d16..7ba2c1a58 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -47,6 +47,11 @@ class RoutesController < ChouetteController
line: @line
})
+ @route_sp = ModelDecorator.decorate(
+ @route_sp,
+ with: StopPointDecorator
+ )
+
build_breadcrumb :show
end
end
diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb
new file mode 100644
index 000000000..a7229226f
--- /dev/null
+++ b/app/decorators/stop_point_decorator.rb
@@ -0,0 +1,44 @@
+class StopPointDecorator < Draper::Decorator
+ 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
+ end
+end
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index eee19d85a..f2f8f1a9d 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -33,18 +33,44 @@
.row
.col-lg-12
- if @route_sp.any?
- = table_builder @route_sp,
- { 'ID Reflex' => Proc.new {|s| s.try(:stop_area).try(:user_objectid)},
- :name => Proc.new {|s| s.try(:stop_area).try(:name)},
- :deleted_at => Proc.new{|s| s.try(:stop_area).deleted_at ? t('false') : t('true')},
- :zip_code => Proc.new {|s| s.try(:stop_area).try(:zip_code)},
- :city_name => Proc.new {|s| s.try(:stop_area).try(:city_name)},
- :for_boarding => Proc.new {|s| t("stop_points.stop_point.for_boarding.#{s.for_boarding}")},
- :for_alighting => Proc.new {|s| t("stop_points.stop_point.for_alighting.#{s.for_alighting}")},
- :position => 'position' },
- [:show],
- [],
- 'table'
+ = table_builder_2 @route_sp,
+ [ \
+ TableBuilderHelper::Column.new( \
+ name: 'ID Reflex', \
+ attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) }, \
+ sortable: false \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :name, \
+ attribute: Proc.new {|s| s.try(:stop_area).try(:name)} \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :deleted_at, \
+ attribute: Proc.new { |s| s.try(:stop_area).deleted_at ? t('false') : t('true') } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :zip_code, \
+ attribute: Proc.new { |s| s.try(:stop_area).try(:zip_code) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :city_name, \
+ attribute: Proc.new { |s| s.try(:stop_area).try(:city_name) } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :for_boarding, \
+ attribute: Proc.new { |s| t("stop_points.stop_point.for_boarding.#{s.for_boarding}") } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :for_alighting, \
+ attribute: Proc.new { |s| t("stop_points.stop_point.for_alighting.#{s.for_alighting}") } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :position, \
+ attribute: 'position' \
+ ), \
+ ],
+ links: [:show],
+ cls: 'table'
- else
= replacement_msg t('stop_areas.search_no_results')