/wiki_pages: sort autocomplete by post count.
* Add search[order]=post_count param to /wiki_pages. * Make autocomplete do a prefix match ordered by post count, so that it works the same way that tag autocomplete does elsewhere.
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
$.ajax({
|
||||
url: "/wiki_pages.json",
|
||||
data: {
|
||||
"search[title]": "*" + req.term + "*",
|
||||
"search[title]": req.term + "*",
|
||||
"search[hide_deleted]": "Yes",
|
||||
"search[order]": "post_count",
|
||||
"limit": 10
|
||||
},
|
||||
method: "get",
|
||||
|
||||
@@ -15,7 +15,7 @@ class WikiPagesController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@wiki_pages = WikiPage.search(params[:search]).order("updated_at desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
@wiki_pages = WikiPage.search(params[:search]).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||
respond_with(@wiki_pages) do |format|
|
||||
format.html do
|
||||
if params[:page].nil? || params[:page].to_i == 1
|
||||
|
||||
@@ -79,10 +79,15 @@ class WikiPage < ActiveRecord::Base
|
||||
end
|
||||
|
||||
params[:order] ||= params.delete(:sort)
|
||||
if params[:order] == "time" || params[:order] == "Date"
|
||||
case params[:order]
|
||||
when "time"
|
||||
q = q.order("updated_at desc")
|
||||
elsif params[:order] == "title" || params[:order] == "Name"
|
||||
when "title"
|
||||
q = q.order("title")
|
||||
when "post_count"
|
||||
q = q.joins(:tag).order("tags.post_count desc")
|
||||
else
|
||||
q = q.order("updated_at desc")
|
||||
end
|
||||
|
||||
q
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<div class="input">
|
||||
<label for="search_order">Order</label>
|
||||
<%= select "search", "order", ["Name", "Date"] %>
|
||||
<%= select "search", "order", [%w[Name title], %w[Date time], %w[Posts post_count]] %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
|
||||
Reference in New Issue
Block a user