aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb51
-rw-r--r--app/models/referential.rb4
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim2
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim2
-rw-r--r--lib/tasks/referential.rake5
5 files changed, 39 insertions, 25 deletions
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index 9d2fd712c..6fb5348f0 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -10,29 +10,39 @@ class RoutingConstraintZonesController < ChouetteController
belongs_to :line, parent_class: Chouette::Line
end
- def index
- @routing_constraint_zones = collection
- end
-
- def show
- @routing_constraint_zone = collection.find(params[:id])
- @routing_constraint_zone = @routing_constraint_zone.decorate(context: {
- referential: @referential,
- line: @line
- })
- end
-
protected
def collection
- @q = resource.routing_constraint_zones.search(params[:q])
+ @q = current_referential.routing_constraint_zones.search(params[:q])
- if sort_column && sort_direction
- @routing_constraint_zones ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction)
- else
- @routing_constraint_zones ||= @q.result(distinct: true).order(:name)
+ @routing_constraint_zones ||= begin
+ if sort_column && sort_direction
+ routing_constraint_zones = @q.result(distinct: true).order(sort_column + ' ' + sort_direction)
+ else
+ routing_constraint_zones = @q.result(distinct: true).order(:name)
+ end
+ routing_constraint_zones = routing_constraint_zones.paginate(page: params[:page], per_page: 10)
end
- @routing_constraint_zones = @routing_constraint_zones.paginate(page: params[:page], per_page: 10)
+ end
+
+ def resource
+ @routing_constraint_zone ||= begin
+ routing_constraint_zone = current_referential.routing_constraint_zones.find(params[:id])
+ routing_constraint_zone = routing_constraint_zone.decorate(context: {
+ referential: current_referential,
+ line: parent.id
+ })
+ end
+ end
+
+ def build_resource
+ @routing_constraint_zone ||= begin
+ routing_constraint_zone = current_referential.routing_constraint_zones.new
+ routing_constraint_zone = routing_constraint_zone.decorate(context: {
+ referential: current_referential,
+ line: parent.id
+ })
+ end
end
private
@@ -43,11 +53,6 @@ class RoutingConstraintZonesController < ChouetteController
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
end
- def resource
- @referential = Referential.find params[:referential_id]
- @line = @referential.lines.find params[:line_id]
- end
-
def routing_constraint_zone_params
params.require(:routing_constraint_zone).permit(
:name,
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 0ce325bd6..ed23e2e51 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -114,6 +114,10 @@ class Referential < ActiveRecord::Base
Chouette::RouteSection.all
end
+ def routing_constraint_zones
+ Chouette::RoutingConstraintZone.all
+ end
+
after_initialize :define_default_attributes
def define_default_attributes
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
index 3d4764ef7..5e5f44269 100644
--- a/app/views/routing_constraint_zones/_form.html.slim
+++ b/app/views/routing_constraint_zones/_form.html.slim
@@ -3,7 +3,7 @@
.row
.col-lg-12
= form.input :name
- = form.input :route_id, collection: @line.routes.select { |route| route.stop_points.count > 2 }, include_blank: false
+ = form.input :route_id, collection: @line.routes, include_blank: false
.separator
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
index d81a347e0..589083927 100644
--- a/app/views/routing_constraint_zones/edit.html.slim
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -1,6 +1,6 @@
/ PageHeader
= pageheader 'map-marker',
- t('.title'),
+ t('.title', routing_constraint_zone: @routing_constraint_zone.name),
'',
t('last_update', time: l(@routing_constraint_zone.updated_at, format: :short))
diff --git a/lib/tasks/referential.rake b/lib/tasks/referential.rake
index ce1ded4fc..d27354a40 100644
--- a/lib/tasks/referential.rake
+++ b/lib/tasks/referential.rake
@@ -39,6 +39,8 @@ namespace :referential do
print " ✓ Created Route ".green, route.name, "(#{route.id}), ".blue, "Line (#{line.id}) has #{line.routes.count} routes\n"
journey_pattern = Chouette::JourneyPattern.create!(route: route, name: "Journey Pattern #{Faker::Name.unique.name}")
+ print "✓ Created JourneyPattern ".green, journey_pattern.name, "(#{journey_pattern.id})".blue, "\n"
+
journey_pattern.stop_points = stop_areas.inject([]) { |stop_points, stop_area| stop_points += stop_area.stop_points }
time_tables = []
@@ -46,11 +48,14 @@ namespace :referential do
name = "Test #{Faker::Name.unique.name}"
time_table = Chouette::TimeTable.create!(comment: name, start_date: Date.parse(args[:start_date]) + j.days,
end_date: Date.parse(args[:end_date]) - j.days)
+ print "✓ Created TimeTable ".green, time_table.comment, "(#{time_table.id})".blue, "\n"
time_tables << time_table
end
25.times do |j|
vehicle_journey = Chouette::VehicleJourney.create!(journey_pattern: journey_pattern, route: route, number: Faker::Number.unique.number(4), time_tables: time_tables)
+ print "✓ Created VehicleJourney ".green, vehicle_journey.number, "(#{vehicle_journey.id})".blue, "\n"
+
time = Time.current.at_noon + j.minutes
journey_pattern.stop_points.each_with_index do |stop_point, k|
vehicle_journey.vehicle_journey_at_stops.create!(stop_point: stop_point, arrival_time: time + k.minutes, departure_time: time + k.minutes + 30.seconds)