aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorjpl2017-06-05 17:56:39 +0200
committerjpl2017-06-05 17:56:48 +0200
commit6e6a2158f88e0a4e8973cb8e098e92b444aecf77 (patch)
tree1200de4eeaa68ff7c1e7d1f949a9afa4c805dc00 /app/controllers
parentf422c130f9bda3c425cc3e1b9604345ca3586fe1 (diff)
downloadchouette-core-6e6a2158f88e0a4e8973cb8e098e92b444aecf77.tar.bz2
Refs #3486: updating ITL#index layout
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb46
1 files changed, 43 insertions, 3 deletions
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index f2f74e801..b5072f401 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -1,6 +1,7 @@
class RoutingConstraintZonesController < ChouetteController
- defaults resource_class: Chouette::RoutingConstraintZone
+ include PolicyChecker
+ defaults resource_class: Chouette::RoutingConstraintZone
respond_to :html, :xml, :json
before_action :remove_empty_stop_point, only: [:create, :update]
@@ -9,11 +10,50 @@ class RoutingConstraintZonesController < ChouetteController
belongs_to :line, parent_class: Chouette::Line
end
- include PolicyChecker
+ def index
+ @routing_constraint_zones = collection
+ end
+
+ def show
+ @routing_constraint_zone = collection.find(params[:id])
+ end
+
+ protected
+
+ def collection
+ @q = resource.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)
+ end
+ @routing_constraint_zones = @routing_constraint_zones.paginate(page: params[:page], per_page: 10)
+ end
private
+ def sort_column
+ (Chouette::RoutingConstraintZone.column_names).include?(params[:sort]) ? params[:sort] : 'name'
+ end
+ def sort_direction
+ %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, { stop_point_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