diff options
| author | Bruno Perles | 2015-12-16 10:02:29 +0100 |
|---|---|---|
| committer | Bruno Perles | 2015-12-16 10:02:29 +0100 |
| commit | 013f4fa8fe9bb08f3ed1d15f905ca2a8437d6aa7 (patch) | |
| tree | 426b9c17167c10547da2222517cbd4433ae554fe /app/controllers | |
| parent | 2590606c5912a85b8cb1aaa40c57dab67d75e7f7 (diff) | |
| download | chouette-core-013f4fa8fe9bb08f3ed1d15f905ca2a8437d6aa7.tar.bz2 | |
Add route_sections for traces
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/route_sections_controller.rb | 70 | ||||
| -rw-r--r-- | app/controllers/route_sections_selectors_controller.rb | 42 | ||||
| -rw-r--r-- | app/controllers/routes_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/stop_areas_controller.rb | 2 |
4 files changed, 114 insertions, 2 deletions
diff --git a/app/controllers/route_sections_controller.rb b/app/controllers/route_sections_controller.rb new file mode 100644 index 000000000..64cb8c65c --- /dev/null +++ b/app/controllers/route_sections_controller.rb @@ -0,0 +1,70 @@ +class RouteSectionsController < ChouetteController + + defaults :resource_class => Chouette::RouteSection + + respond_to :html + respond_to :kml, :only => :show + + belongs_to :referential + + before_action :save_return_to_path, only: [:edit, :create_to_edit] + before_action ->(controller) { build_breadcrumb controller.action_name } + + helper_method :search + + def index + index! + end + + def new + @stop_areas = referential.stop_areas.with_geometry.order :name + new! + end + + def show + @map = RouteSectionMap.new(resource).with_helpers(self) + show! + end + + def edit + @map = RouteSectionMap.new(resource, true).with_helpers(self) + edit! + end + + def update + update! { session.delete(:return_to) } + end + + def create + create! { session.delete(:return_to) } + end + + def create_to_edit + route_section = Chouette::RouteSection.create(route_section_params) + redirect_to edit_referential_route_section_path(referential, route_section) + end + + protected + + def save_return_to_path + session[:return_to] = params[:return_to] if params[:return_to] + end + + def collection + # if q = params[:q] + # @route_sections ||= Chouette::RouteSection.joins(:departure, :arrival).where(departure: {name: "#{q}"}).or.where(arrival: {name: "#{q}"}) + # end + @route_sections ||= search.collection.includes(:departure, :arrival).paginate page: params[:page] + end + + def search + @search ||= RouteSectionSearch.new(params[:route_section_search]) + end + + private + + def route_section_params + params.require(:route_section).permit(:departure_id, :arrival_id, :editable_geometry, :no_processing) + end + +end diff --git a/app/controllers/route_sections_selectors_controller.rb b/app/controllers/route_sections_selectors_controller.rb new file mode 100644 index 000000000..05a399ae8 --- /dev/null +++ b/app/controllers/route_sections_selectors_controller.rb @@ -0,0 +1,42 @@ +class RouteSectionsSelectorsController < ChouetteController + + # singleton option makes association_chain crazy + #defaults singleton: true + + respond_to :html, only: [ :edit, :update ] + respond_to :js, only: :section + + belongs_to :referential do + belongs_to :line, :parent_class => Chouette::Line do + belongs_to :route, :parent_class => Chouette::Route do + belongs_to :journey_pattern, parent_class: Chouette::JourneyPattern + end + end + end + + def edit + @map = RouteSectionSelectorMap.new(resource).with_helpers(self) + end + + def selection + parent + + @route_section = referential.route_sections.find params[:route_section_id].to_i + render partial: 'selection', format: 'js' + end + + private + + def resource + @route_sections_selector ||= RouteSectionsSelector.new parent + end + + def build_resource + @route_sections_selector ||= RouteSectionsSelector.new parent, *resource_params + end + + def route_section_selector_params + params.require(:route_section_selector).permit() + end + +end diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 6dfaf3dd0..59c129867 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -75,7 +75,7 @@ class RoutesController < ChouetteController end private - + def route_params params.require(:route).permit( :direction_code, :wayback_code, :line_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :opposite_route_id, :published_name, :number, :direction, :wayback, { stop_points_attributes: [ :id, :_destroy, :position, :stop_area_id, :for_boarding, :for_alighting ] } ) end diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 9321ac9ae..dbbadb80c 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -137,6 +137,6 @@ class StopAreasController < ChouetteController 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 end |
