blob: 03d6cf176cd7f41fbec9113081b0bbb0444493ba (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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]
  helper_method :search
  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)
    if route_section.id
      redirect_to edit_referential_route_section_path(referential, route_section)
    else
      flash[:alert] = I18n.t('route_sections.unable_to_contact_server')
      redirect_to :back
    end
  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
 |