diff options
| author | Alban Peignier | 2016-05-15 09:22:06 +0200 | 
|---|---|---|
| committer | Alban Peignier | 2016-05-15 09:22:06 +0200 | 
| commit | affbacfcd955230f66badb261dcc462cca9cd0b9 (patch) | |
| tree | 5410864baa11d3e5b24671cfb8f9258aaa833e62 /app/controllers/referential_lines_controller.rb | |
| parent | f5a3f0061fed4f8f51ebc0d556539a483626f76e (diff) | |
| download | chouette-core-affbacfcd955230f66badb261dcc462cca9cd0b9.tar.bz2 | |
Associate LineReferential to Referential. Create ReferentialLines to manage lines in Referential. Refs #826
Diffstat (limited to 'app/controllers/referential_lines_controller.rb')
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 89 | 
1 files changed, 89 insertions, 0 deletions
| diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb new file mode 100644 index 000000000..7112cf452 --- /dev/null +++ b/app/controllers/referential_lines_controller.rb @@ -0,0 +1,89 @@ +class ReferentialLinesController < ChouetteController + +  defaults :resource_class => Chouette::Line, :collection_name => 'lines', :instance_name => 'line' +  respond_to :html +  respond_to :xml +  respond_to :json +  respond_to :kml, :only => :show +  respond_to :js, :only => :index + +  belongs_to :referential + +  def index +    index! do |format| +      format.html { +        if collection.out_of_bounds? +          redirect_to params.merge(:page => 1) +        end +        build_breadcrumb :index +      } +    end +  end + +  def show +    @map = LineMap.new(resource).with_helpers(self) +    @routes = @line.routes +    @group_of_lines = @line.group_of_lines +    show! do +      build_breadcrumb :show +    end +  end + +  # overwrite inherited resources to use delete instead of destroy +  # foreign keys will propagate deletion) +  def destroy_resource(object) +    object.delete +  end + +  def delete_all +    objects = +      get_collection_ivar || set_collection_ivar(end_of_association_chain.where(:id => params[:ids])) +    objects.each { |object| object.delete } +    respond_with(objects, :location => smart_collection_url) +  end + +  def name_filter +    respond_to do |format| +      format.json { render :json => filtered_lines_maps} +    end +  end + +  protected + +  def filtered_lines_maps +    filtered_lines.collect do |line| +      { :id => line.id, :name => (line.published_name ? line.published_name : line.name) } +    end +  end + +  def filtered_lines +    referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e }  } +  end + +  def collection +    if params[:q] && params[:q]["network_id_eq"] == "-1" +      params[:q]["network_id_eq"] = "" +      params[:q]["network_id_blank"] = "1" +    end + +    if params[:q] && params[:q]["company_id_eq"] == "-1" +      params[:q]["company_id_eq"] = "" +      params[:q]["company_id_blank"] = "1" +    end + +    if params[:q] && params[:q]["group_of_lines_id_eq"] == "-1" +      params[:q]["group_of_lines_id_eq"] = "" +      params[:q]["group_of_lines_id_blank"] = "1" +    end + +    @q = referential.lines.search(params[:q]) +    @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) +  end + +  private + +  def line_params +    params.require(:line).permit( :transport_mode, :network_id, :company_id, :objectid, :object_version, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name, :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs, :flexible_service, :group_of_lines, :group_of_line_ids, :group_of_line_tokens, :url, :color, :text_color, :stable_id, { footnotes_attributes: [ :code, :label, :_destroy, :id ] } ) +  end + +end | 
