diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/referential_lines_controller.rb | 18 | ||||
| -rw-r--r-- | app/helpers/pagination_helper.rb | 4 | ||||
| -rw-r--r-- | app/views/referential_lines/show.html.slim | 9 |
3 files changed, 17 insertions, 14 deletions
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index 4842cebc1..5d36e7da7 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -23,18 +23,22 @@ class ReferentialLinesController < ChouetteController end def show - @map = LineMap.new(resource).with_helpers(self) + @routes = resource.routes - @q = @line.routes.ransack(params[:q]) + case sort_route_column + when "stop_points", "journey_patterns" + left_join = %Q{LEFT JOIN "#{sort_route_column}" ON "#{sort_route_column}"."route_id" = "routes"."id"} - if sort_route_column && sort_route_direction - @routes ||= @q.result(distinct: true).order(sort_route_column + ' ' + sort_route_direction) + @routes = @routes.joins(left_join).group(:id).order("count(#{sort_route_column}.route_id) #{sort_route_direction}") else - @routes ||= @q.result(distinct: true).order(:name) + @routes = @routes.order("#{sort_route_column} #{sort_route_direction}") end + + @q = @routes.ransack(params[:q]) + @routes = @q.result + @routes = @routes.paginate(page: params[:page], per_page: 10) - @group_of_lines = @line.group_of_lines show! do build_breadcrumb :show end @@ -106,7 +110,7 @@ class ReferentialLinesController < ChouetteController end def sort_route_column - @line.routes.column_names.include?(params[:sort]) ? params[:sort] : 'name' + (@line.routes.column_names + %w{stop_points journey_patterns}).include?(params[:sort]) ? params[:sort] : 'name' end def sort_route_direction %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb index 350d796ea..02eec39dc 100644 --- a/app/helpers/pagination_helper.rb +++ b/app/helpers/pagination_helper.rb @@ -20,8 +20,8 @@ module PaginationHelper end def new_pagination collection, cls = nil - k = collection.first.class - pinfos = page_entries_info collection, model: k, html: false + # k = collection.first.class unless collection.empty? + pinfos = page_entries_info collection, html: false if collection.total_pages > 1 links = content_tag :div, '', class: 'page_links' do diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index 2566550ba..cd15cb0e0 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -46,21 +46,20 @@ .row .col-lg-12 - if params[:q].present? or @routes.any? - .row.mb-sm - .col-lg-12.text-right - = new_pagination @routes + / .row.mb-sm + / .col-lg-12.text-right + / = new_pagination @routes .row .col-lg-12 = search_form_for @q, url: referential_line_path(@referential, @line), class: 'form form-filter' do |f| .input-group.search_bar = f.search_field :name_cont, class: 'form-control', placeholder: "Indiquez un nom d'itinéraire..." - + span.input-group-btn button.btn.btn-default type='submit' span.fa.fa-search - - if @routes.any? .row .col-lg-12 |
