FEATURE: on mobile take users to full page search

UX: improve styling on full page search page
FEATURE: allow search context in full page search
FEATURE: visited color link for full page search
FIX: broken search help on fulls page search page
FEATURE: allow preload store to return a null
FEATURE: "mobileAction" for the header buttons
This commit is contained in:
Sam
2015-09-08 11:03:51 +10:00
parent e37dd5a393
commit e13ed24122
15 changed files with 203 additions and 43 deletions

View File

@@ -9,7 +9,20 @@ class SearchController < ApplicationController
end
def show
search = Search.new(params[:q], type_filter: 'topic', guardian: guardian, include_blurbs: true, blurb_length: 300)
search_args = {
type_filter: 'topic',
guardian: guardian,
include_blurbs: true,
blurb_length: 300
}
context, type = lookup_search_context
if context
search_args[:search_context] = context
search_args[:type_filter] = type if type
end
search = Search.new(params[:q], search_args)
result = search.execute
serializer = serialize_data(result, GroupedSearchResultSerializer, result: result)
@@ -34,7 +47,29 @@ class SearchController < ApplicationController
search_args[:include_blurbs] = params[:include_blurbs] == "true" if params[:include_blurbs].present?
search_args[:search_for_id] = true if params[:search_for_id].present?
context,type = lookup_search_context
if context
search_args[:search_context] = context
search_args[:type_filter] = type if type
end
search = Search.new(params[:term], search_args.symbolize_keys)
result = search.execute
render_serialized(result, GroupedSearchResultSerializer, result: result)
end
protected
def lookup_search_context
return if params[:skip_context] == "true"
search_context = params[:search_context]
unless search_context
if (context = params[:context]) && (id = params[:context_id])
search_context = {type: context, id: id}
end
end
if search_context.present?
raise Discourse::InvalidParameters.new(:search_context) unless SearchController.valid_context_types.include?(search_context[:type])
@@ -43,23 +78,21 @@ class SearchController < ApplicationController
# A user is found by username
context_obj = nil
if ['user','private_messages'].include? search_context[:type]
context_obj = User.find_by(username_lower: params[:search_context][:id].downcase)
context_obj = User.find_by(username_lower: search_context[:id].downcase)
else
klass = search_context[:type].classify.constantize
context_obj = klass.find_by(id: params[:search_context][:id])
context_obj = klass.find_by(id: search_context[:id])
end
type_filter = nil
if search_context[:type] == 'private_messages'
search_args[:type_filter] = 'private_messages'
type_filter = 'private_messages'
end
guardian.ensure_can_see!(context_obj)
search_args[:search_context] = context_obj
end
search = Search.new(params[:term], search_args.symbolize_keys)
result = search.execute
render_serialized(result, GroupedSearchResultSerializer, result: result)
[context_obj, type_filter]
end
end
end