aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-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
4 files changed, 34 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))