saved searches: paginate index page + add search form.
This commit is contained in:
@@ -3,11 +3,7 @@ class SavedSearchesController < ApplicationController
|
||||
respond_to :html, :xml, :json, :js
|
||||
|
||||
def index
|
||||
@saved_searches = saved_searches.order("id")
|
||||
|
||||
if params[:label]
|
||||
@saved_searches = saved_searches.labeled(params[:label])
|
||||
end
|
||||
@saved_searches = saved_searches.search(search_params).paginate(params[:page], limit: params[:limit])
|
||||
|
||||
respond_with(@saved_searches) do |format|
|
||||
format.xml do
|
||||
|
||||
@@ -93,6 +93,17 @@ class SavedSearch < ApplicationRecord
|
||||
|
||||
concerning :Search do
|
||||
class_methods do
|
||||
def search(params)
|
||||
q = super
|
||||
q = q.search_attributes(params, :query)
|
||||
|
||||
if params[:label]
|
||||
q = q.labeled(params[:label])
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def populate(query)
|
||||
CurrentUser.as_system do
|
||||
redis_key = "search:#{query}"
|
||||
|
||||
@@ -7,19 +7,25 @@
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<table class="striped" width="100%">
|
||||
<%= simple_form_for(:search, url: saved_searches_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||
<%= f.input :query_ilike, label: "Query", input_html: { value: params[:search][:query_ilike] } %>
|
||||
<%= f.input :label, label: "Label", input_html: { value: params[:search][:label] } %>
|
||||
<%= f.submit "Search" %>
|
||||
<% end %>
|
||||
|
||||
<table class="striped autofit" width="100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="string" width="60%">Query</th>
|
||||
<th data-sort="string" width="20%">Labels</th>
|
||||
<th width="20%" class="links"></th>
|
||||
<th data-sort="string">Query</th>
|
||||
<th data-sort="string">Labels</th>
|
||||
<th class="links"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @saved_searches.each do |ss| %>
|
||||
<tr id="saved-search-<%= ss.id %>">
|
||||
<td><%= link_to ss.query, posts_path(:tags => ss.query) %></td>
|
||||
<td class="col-expand"><%= link_to ss.query, posts_path(tags: ss.query) %></td>
|
||||
<td>
|
||||
<% ss.labels.each do |label| %>
|
||||
<%= link_to label, posts_path(:tags => "search:#{label}") %>
|
||||
@@ -33,6 +39,8 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= numbered_paginator(@saved_searches) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user