Skip to content

Commit

Permalink
Merge pull request #833 from user12986714/patch-37
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtOfCode- committed Jan 27, 2021
2 parents f79e918 + 1ae4bd0 commit a5bf169
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
32 changes: 19 additions & 13 deletions app/controllers/search_controller.rb
Expand Up @@ -64,9 +64,6 @@ def index
end

@results = @results.where(search_string.join(params[:or_search].present? ? ' OR ' : ' AND '), **search_params)
.paginate(page: params[:page], per_page: per_page)
.order(Arel.sql('`posts`.`created_at` DESC'))

@results = @results.includes(:reasons).includes(:feedbacks) if params[:option].nil?

if params[:has_no_feedback] == '1'
Expand Down Expand Up @@ -127,17 +124,26 @@ def index
@counts_by_feedback = %i[is_tp is_fp is_naa].each_with_index.map do |symbol, i|
[symbol, @counts_by_accuracy_group.select { |k, _v| k[i] }.values.sum]
end.to_h
@total_count = @counts_by_accuracy_group.values.sum

@results = case params[:feedback_filter]
when 'tp'
@results.where(is_tp: true)
.paginate(page: params[:page], per_page: per_page,
total_entries: @counts_by_feedback[:is_tp])
when 'fp'
@results.where(is_fp: true)
.paginate(page: params[:page], per_page: per_page,
total_entries: @counts_by_feedback[:is_fp])
when 'naa'
@results.where(is_naa: true)
.paginate(page: params[:page], per_page: per_page,
total_entries: @counts_by_feedback[:is_naa])
else
@results.paginate(page: params[:page], per_page: per_page,
total_entries: @total_count)
end.order(Arel.sql('`posts`.`created_at` DESC'))

case params[:feedback_filter]
when 'tp'
@results = @results.where(is_tp: true)
when 'fp'
@results = @results.where(is_fp: true)
when 'naa'
@results = @results.where(is_naa: true)
end

@sites = Site.where(id: @results.map(&:site_id)).to_a unless params[:option] == 'graphs'
render :search
end
format.json do
Expand Down
4 changes: 2 additions & 2 deletions app/views/posts/_post.html.erb
Expand Up @@ -38,8 +38,8 @@
<% end %>
<% if post.comments.any? && !hide_feedbacks %>
<span class="comment-hint text-muted" title="<%= pluralize(post.comments.count, 'comment') %>">
<span class="glyphicon glyphicon-comment"></span> &times;<%= post.comments.count %>
<span class="comment-hint text-muted" title="<%= pluralize(post.comments.size, 'comment') %>">
<span class="glyphicon glyphicon-comment"></span> &times;<%= post.comments.size %>
</span>
<% end %>

Expand Down
6 changes: 2 additions & 4 deletions app/views/search/search.html.erb
Expand Up @@ -98,7 +98,7 @@
<% if @results.present? %>
<ul class="nav nav-tabs">
<li role="presentation" class="<%= "active" if params[:option].nil? and (params[:feedback_filter].nil? or params[:feedback_filter] == 'all') %>">
<%= link_to "Results (#{@counts_by_accuracy_group.values.sum})", search_path(request.query_parameters.merge!({option: nil, feedback_filter: nil})) %>
<%= link_to "Results (#{@total_count})", search_path(request.query_parameters.merge!({option: nil, feedback_filter: nil})) %>
</li>
<li class="<%= 'active' if params[:feedback_filter] == 'tp' %>">
<%= link_to "True positives (#{@counts_by_feedback[:is_tp]})", search_path(request.query_parameters.to_h.merge!({option: nil, feedback_filter: "tp"})) %>
Expand All @@ -116,9 +116,7 @@

<% if params[:option].nil? %>
<table class="table">
<% @results.each do |post| %>
<%= render "posts/post", post: post %>
<% end %>
<%= render @results, collection: :post %>
</table>
<div class="text-center">
<%= will_paginate @results, renderer: BootstrapPagination::Rails %>
Expand Down

0 comments on commit a5bf169

Please sign in to comment.