saved searches: paginate index page + add search form.

This commit is contained in:
evazion
2019-09-02 20:41:10 -05:00
parent 6ef79fe6ab
commit 4abffc7faa
3 changed files with 25 additions and 10 deletions

View File

@@ -3,11 +3,7 @@ class SavedSearchesController < ApplicationController
respond_to :html, :xml, :json, :js respond_to :html, :xml, :json, :js
def index def index
@saved_searches = saved_searches.order("id") @saved_searches = saved_searches.search(search_params).paginate(params[:page], limit: params[:limit])
if params[:label]
@saved_searches = saved_searches.labeled(params[:label])
end
respond_with(@saved_searches) do |format| respond_with(@saved_searches) do |format|
format.xml do format.xml do

View File

@@ -93,6 +93,17 @@ class SavedSearch < ApplicationRecord
concerning :Search do concerning :Search do
class_methods 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) def populate(query)
CurrentUser.as_system do CurrentUser.as_system do
redis_key = "search:#{query}" redis_key = "search:#{query}"

View File

@@ -7,19 +7,25 @@
<% end %> <% end %>
</h1> </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> <thead>
<tr> <tr>
<th data-sort="string" width="60%">Query</th> <th data-sort="string">Query</th>
<th data-sort="string" width="20%">Labels</th> <th data-sort="string">Labels</th>
<th width="20%" class="links"></th> <th class="links"></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @saved_searches.each do |ss| %> <% @saved_searches.each do |ss| %>
<tr id="saved-search-<%= ss.id %>"> <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> <td>
<% ss.labels.each do |label| %> <% ss.labels.each do |label| %>
<%= link_to label, posts_path(:tags => "search:#{label}") %> <%= link_to label, posts_path(:tags => "search:#{label}") %>
@@ -33,6 +39,8 @@
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%= numbered_paginator(@saved_searches) %>
</div> </div>
</div> </div>