mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
adds filters and breaks pagination
This commit is contained in:
parent
ff58856c99
commit
be19256457
2 changed files with 39 additions and 5 deletions
|
@ -1,12 +1,35 @@
|
|||
class SearchController < ApplicationController
|
||||
def index
|
||||
@show_search_result = params[:q].present?
|
||||
@paper_type = params[:paper_type]
|
||||
@originator = params[:originator]
|
||||
|
||||
@show_search_result = @show_filters = params[:q].present?
|
||||
papers_found = if @show_search_result
|
||||
Paper.search(params[:q]).records
|
||||
else
|
||||
Paper
|
||||
Paper.all
|
||||
end
|
||||
|
||||
if @show_filters
|
||||
|
||||
@paper_types_found = papers_found.map(&:paper_type).uniq
|
||||
@originators_found = papers_found.map(&:originator).uniq
|
||||
|
||||
if @paper_type.present?
|
||||
papers_found = papers_found.where(paper_type: @paper_type)
|
||||
end
|
||||
|
||||
if @originator.present?
|
||||
papers_found = papers_found.where(originator: @originator)
|
||||
end
|
||||
end
|
||||
|
||||
@papers_count = papers_found.page(params[:page]).total_count
|
||||
@papers = papers_found.page(params[:page])
|
||||
# Fixme Pagination
|
||||
#order(published_at: :desc).
|
||||
# page(params[:page])
|
||||
|
||||
|
||||
end
|
||||
@papers_count = @show_search_result ? papers_found.results.total : papers_found.count
|
||||
@papers = papers_found.order(published_at: :desc).page(params[:page])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue