aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorVlatka Pavisic2017-04-11 15:35:01 +0200
committerVlatka Pavisic2017-04-11 15:35:01 +0200
commitaa481c087b162bc775b4418e205f91c5b6bead19 (patch)
tree914ba9b39e0338317bcc2bfd839f745647beda1a /app
parent8adf909694b52959483818bf839d6e180015eb99 (diff)
downloadchouette-core-aa481c087b162bc775b4418e205f91c5b6bead19.tar.bz2
Refs #3047: Associate RoutingConstraintZone with StopPoints
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee18
-rw-r--r--app/controllers/route_stop_points_controller.rb18
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb7
-rw-r--r--app/helpers/newapplication_helper.rb10
-rw-r--r--app/models/chouette/routing_constraint_zone.rb11
-rw-r--r--app/models/chouette/stop_point.rb6
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim8
-rw-r--r--app/views/routing_constraint_zones/show.html.slim7
8 files changed, 65 insertions, 20 deletions
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
new file mode 100644
index 000000000..57f94e654
--- /dev/null
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -0,0 +1,18 @@
+fill_stop_points_options = ->
+ stop_point_select = $('#routing_constraint_zone_stop_point_ids')
+ stop_point_select.empty()
+ route_id = $('#routing_constraint_zone_route_id').val()
+ $.ajax
+ url: "/referentials/5/lines/162/routes/#{route_id}/stop_points"
+ dataType: 'json'
+ success: (data, textStatus, jqXHR) ->
+ for stop_point in data
+ stop_point_select.append "<option value='#{stop_point.id}'>#{stop_point.name}</option>"
+ error: (jqXHR, textStatus, errorThrown) ->
+ console.log textStatus
+ console.log errorThrown
+
+$ ->
+ if document.location.pathname.endsWith('new')
+ fill_stop_points_options()
+ $('#routing_constraint_zone_route_id').change(fill_stop_points_options)
diff --git a/app/controllers/route_stop_points_controller.rb b/app/controllers/route_stop_points_controller.rb
new file mode 100644
index 000000000..e12acb33b
--- /dev/null
+++ b/app/controllers/route_stop_points_controller.rb
@@ -0,0 +1,18 @@
+class RouteStopPointsController < ChouetteController
+ defaults resource_class: Chouette::StopPoint
+ actions :index
+ respond_to :json, only: :index
+
+ belongs_to :referential do
+ belongs_to :line, :parent_class => Chouette::Line do
+ belongs_to :route, :parent_class => Chouette::Route
+ end
+ end
+
+ def index
+ respond_to do |format|
+ format.json { render json: referential.lines.find(params[:line_id]).routes.find(params[:route_id]).stop_points.map { |sp| { id: sp.id, name: sp.name } } }
+ end
+ end
+end
+
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index bc3dcdfd4..f2f74e801 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -3,6 +3,8 @@ class RoutingConstraintZonesController < ChouetteController
respond_to :html, :xml, :json
+ before_action :remove_empty_stop_point, only: [:create, :update]
+
belongs_to :referential do
belongs_to :line, parent_class: Chouette::Line
end
@@ -11,7 +13,10 @@ class RoutingConstraintZonesController < ChouetteController
private
def routing_constraint_zone_params
- params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :route_id, :objectid, :object_version, :creator_id)
+ params.require(:routing_constraint_zone).permit(:name, { stop_point_ids: [] }, :line_id, :route_id, :objectid, :object_version, :creator_id)
end
+ def remove_empty_stop_point
+ params.require(:routing_constraint_zone)[:stop_point_ids].delete('')
+ end
end
diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb
index c4b8ee7ab..f5b898731 100644
--- a/app/helpers/newapplication_helper.rb
+++ b/app/helpers/newapplication_helper.rb
@@ -51,12 +51,11 @@ module NewapplicationHelper
if attribute == 'name'
lnk = []
- unless item.class.to_s == 'Calendar' or item.class.to_s == 'Referential'
+ unless item.class == Calendar or item.class == Referential
if current_referential
lnk << current_referential
lnk << item.line if item.respond_to? :line
- lnk << item.route.line if item.class.to_s == 'Chouette::RoutingConstraintZone'
- lnk << item if item.class.to_s == 'Chouette::RoutingConstraintZone'
+ lnk << item.route.line if item.class == 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
@@ -103,12 +102,11 @@ module NewapplicationHelper
polymorph_url << action
end
- unless item.class.to_s == 'Calendar' or item.class.to_s == 'Referential'
+ unless item.class == Calendar or item.class == Referential
if current_referential
polymorph_url << current_referential
polymorph_url << item.line if item.respond_to? :line
- polymorph_url << item.route.line if item.class.to_s == 'Chouette::RoutingConstraintZone'
- polymorph_url << item if item.class.to_s == 'Chouette::RoutingConstraintZone'
+ polymorph_url << item.route.line if item.class == 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
diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb
index 2c8583ec1..d548ce048 100644
--- a/app/models/chouette/routing_constraint_zone.rb
+++ b/app/models/chouette/routing_constraint_zone.rb
@@ -1,9 +1,12 @@
class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord
belongs_to :route
- has_array_of :stop_areas, class_name: 'Chouette::StopArea'
+ has_array_of :stop_points, class_name: 'Chouette::StopPoint'
- validates_presence_of :name, :stop_area_ids, :route_id
- validates :stop_areas, length: { minimum: 2 }
+ validates_presence_of :name, :stop_point_ids, :route_id
+ validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') }
+ validate :stop_points_belong_to_route
- self.primary_key = 'id'
+ def stop_points_belong_to_route
+ errors.add(:stop_points, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp }
+ end
end
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index b77189fc1..96b79c9e7 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -2,7 +2,7 @@ module Chouette
class StopPoint < TridentActiveRecord
include ForBoardingEnumerations
include ForAlightingEnumerations
-
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
self.primary_key = "id"
@@ -18,6 +18,8 @@ module Chouette
scope :default_order, order("position")
+ delegate :name, to: :stop_area
+
before_destroy :remove_dependent_journey_pattern_stop_points
def remove_dependent_journey_pattern_stop_points
route.journey_patterns.each do |jp|
@@ -25,7 +27,7 @@ module Chouette
jp.stop_point_ids = jp.stop_point_ids - [id]
end
end
- end
+ end
def stop_area_id_validation
if stop_area_id.nil?
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
index f72dd1471..e07b21fec 100644
--- a/app/views/routing_constraint_zones/_form.html.slim
+++ b/app/views/routing_constraint_zones/_form.html.slim
@@ -4,13 +4,15 @@
= f.input :name
.row
.col-lg-6.col-sm-12
- = f.input :route_id, collection: @line.routes
+ = f.input :route_id, collection: @line.routes, include_blank: false
.row
.col-lg-6.col-sm-12
- / Temporarily limit the collection to 10 items... otherwise it kills RoR
- = f.input :stop_area_ids, as: :select, collection: Chouette::StopArea.limit(10), selected: @routing_constraint_zone.stop_area_ids, label: Chouette::StopArea.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection de arrêts', 'multiple': 'multiple', style: 'width: 100%' }
+ - stop_points_collection = @routing_constraint_zone.persisted? ? @routing_constraint_zone.route.stop_points : []
+ = f.input :stop_point_ids, id: 'stop_point_ids', as: :select, collection: stop_points_collection, selected: @routing_constraint_zone.stop_point_ids, label: Chouette::StopPoint.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection des arrêts sur séquence d\'arrêts', 'multiple': 'multiple', style: 'width: 100%' }
.row
.col-lg-12.text-right
= link_to 'Annuler', :back, class: 'btn btn-link'
= f.button :submit, class: 'btn btn-danger'
+
+
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index 7b7b63623..351784ecc 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -9,10 +9,9 @@ p
= link_to @routing_constraint_zone.route.name, referential_line_route_path(@referential, @line, @routing_constraint_zone.route)
p
- label => "#{Chouette::StopArea.model_name.human.pluralize.capitalize} : "
+ label => "#{Chouette::StopPoint.model_name.human.pluralize.capitalize} : "
br
- - @routing_constraint_zone.stop_areas.each do |stop_area|
- = link_to stop_area.name, referential_stop_area_path(@referential, stop_area)
+ - @routing_constraint_zone.stop_points.each do |stop_point|
+ = link_to stop_point.name, referential_stop_area_path(@referential, stop_point.stop_area)
br
-