diff options
| author | jpl | 2017-04-10 15:40:36 +0200 | 
|---|---|---|
| committer | jpl | 2017-04-10 15:40:46 +0200 | 
| commit | 19127ebb18ee3f068ff686bf21bad7472f493186 (patch) | |
| tree | 4fa625f5fa5bd806d70efaa46ed4a0066c1d972b /app/controllers/time_tables_controller.rb | |
| parent | 14ba8e73fea3a1fb26d1d714d1291e710f95f984 (diff) | |
| download | chouette-core-19127ebb18ee3f068ff686bf21bad7472f493186.tar.bz2 | |
Refs #2909: Fix tests, updating table builder
Diffstat (limited to 'app/controllers/time_tables_controller.rb')
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 17 | 
1 files changed, 15 insertions, 2 deletions
| diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 5dc84ddf1..c5aa7280a 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -99,13 +99,20 @@ class TimeTablesController < ChouetteController      ransack_params.delete("tag_search") if ransack_params.present?      selected_time_tables = tag_search ? select_time_tables.tagged_with(tag_search, :wild => true, :any => true) : select_time_tables +      @q = selected_time_tables.search(ransack_params) -    @time_tables ||= @q.result(:distinct => true).order(:comment).paginate(:page => params[:page]) + +    if sort_column && sort_direction +      @time_tables ||= @q.result(:distinct => true).order("#{sort_column} #{sort_direction}") +    else +      @time_tables ||= @q.result(:distinct => true).order(:comment) +    end +    @time_tables = @time_tables.paginate(page: params[:page], per_page: 10)    end    def select_time_tables      if params[:route_id] -      referential.time_tables.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})") +      referential.time_tables.joins(vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})")     else        referential.time_tables     end @@ -120,6 +127,12 @@ class TimeTablesController < ChouetteController    end    private +  def sort_column +    referential.time_tables.column_names.include?(params[:sort]) ? params[:sort] : 'comment' +  end +  def sort_direction +    %w[asc desc].include?(params[:direction]) ?  params[:direction] : 'asc' +  end    def time_table_params      params.require(:time_table).permit( | 
