aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorAlban Peignier2016-05-15 10:25:11 +0200
committerAlban Peignier2016-05-15 10:25:11 +0200
commit297727032a0c1fddfbb9d8864deda1ec24ea36f6 (patch)
tree62868de1770546b748b5fec3c59e806cbe5c8f21 /app/controllers
parentaffbacfcd955230f66badb261dcc462cca9cd0b9 (diff)
downloadchouette-core-297727032a0c1fddfbb9d8864deda1ec24ea36f6.tar.bz2
Associate StopAreaReferential to Referential. Create ReferentialStopAreas to manage lines in Referential. Refs #822
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/referential_stop_areas_controller.rb137
1 files changed, 137 insertions, 0 deletions
diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb
new file mode 100644
index 000000000..06305bb1f
--- /dev/null
+++ b/app/controllers/referential_stop_areas_controller.rb
@@ -0,0 +1,137 @@
+# -*- coding: utf-8 -*-
+class ReferentialStopAreasController < ChouetteController
+ defaults :resource_class => Chouette::StopArea, :collection_name => 'stop_areas', :instance_name => 'stop_area'
+
+ belongs_to :referential do
+ belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true
+ belongs_to :network, :parent_class => Chouette::Network, :optional => true, :polymorphic => true
+ belongs_to :connection_link, :parent_class => Chouette::ConnectionLink, :optional => true, :polymorphic => true
+ end
+
+ respond_to :html, :kml, :xml, :json
+ respond_to :js, :only => :index
+
+ def select_parent
+ @stop_area = stop_area
+ @parent = stop_area.parent
+ build_breadcrumb :edit
+ end
+
+ def add_children
+ @stop_area = stop_area
+ @children = stop_area.children
+ build_breadcrumb :edit
+ end
+
+ def add_routing_lines
+ @stop_area = stop_area
+ @lines = stop_area.routing_lines
+ build_breadcrumb :edit
+ end
+
+ def add_routing_stops
+ @stop_area = stop_area
+ build_breadcrumb :edit
+ end
+
+ def access_links
+ @stop_area = stop_area
+ @generic_access_links = stop_area.generic_access_link_matrix
+ @detail_access_links = stop_area.detail_access_link_matrix
+ build_breadcrumb :edit
+ end
+
+ def index
+ request.format.kml? ? @per_page = nil : @per_page = 12
+ @zip_codes = referential.stop_areas.collect(&:zip_code).compact.uniq
+ index! do |format|
+ format.html {
+ if collection.out_of_bounds?
+ redirect_to params.merge(:page => 1)
+ end
+ build_breadcrumb :index
+ }
+ end
+ end
+
+ def new
+ @map = StopAreaMap.new( Chouette::StopArea.new).with_helpers(self)
+ @map.editable = true
+ new! do
+ build_breadcrumb :show
+ end
+ end
+
+ def create
+ @map = StopAreaMap.new(Chouette::StopArea.new).with_helpers(self)
+ @map.editable = true
+
+ create!
+ end
+
+ def show
+ map.editable = false
+ @access_points = @stop_area.access_points
+ show! do |format|
+ unless stop_area.position or params[:default] or params[:routing]
+ format.kml {
+ render :nothing => true, :status => :not_found
+ }
+
+ end
+ build_breadcrumb :show
+ end
+ end
+
+ def edit
+ edit! do
+ stop_area.position ||= stop_area.default_position
+ map.editable = true
+ build_breadcrumb :edit
+ end
+ end
+
+ def update
+ stop_area.position ||= stop_area.default_position
+ map.editable = true
+
+ update!
+ end
+
+ def default_geometry
+ count = referential.stop_areas.without_geometry.default_geometry!
+ flash[:notice] = I18n.translate("stop_areas.default_geometry_success", :count => count)
+ redirect_to stop_area_referential_stop_areas_path(@stop_area_referential)
+ end
+
+ def zip_codes
+ respond_to do |format|
+ format.json { render :json => referential.stop_areas.collect(&:zip_code).compact.uniq.to_json }
+ end
+ end
+
+ protected
+
+ alias_method :stop_area, :resource
+
+ def map
+ @map = StopAreaMap.new(stop_area).with_helpers(self)
+ end
+
+ def collection
+ @q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q])
+ @stop_areas ||=
+ begin
+ stop_areas = @q.result(:distinct => true).order(:name)
+ stop_areas = stop_areas.paginate(:page => params[:page], :per_page => @per_page) if @per_page.present?
+ stop_areas
+ end
+ end
+
+ private
+
+ def stop_area_params
+ params.require(:stop_area).permit( :routing_stop_ids, :routing_line_ids, :children_ids, :stop_area_type, :parent_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :coordinates, :url, :time_zone )
+ end
+
+end