Start background search with gon
This commit is contained in:
parent
b8c76a3317
commit
459ebffa6e
3 changed files with 17 additions and 16 deletions
|
|
@ -30,4 +30,10 @@ var List = {
|
||||||
setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000);
|
setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
if (gon.preloads.background_query) {
|
||||||
|
List.startSearchDelay(gon.preloads.background_query);
|
||||||
|
}
|
||||||
|
});
|
||||||
// @license-end
|
// @license-end
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,10 @@ class PeopleController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
format.any(:html, :mobile) do
|
format.any(:html, :mobile) do
|
||||||
#only do it if it is an email address
|
# only do it if it is a diaspora*-ID
|
||||||
if diaspora_id?(search_query)
|
if diaspora_id?(search_query)
|
||||||
@people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
|
@people = Person.where(diaspora_handle: search_query.downcase, closed_account: false)
|
||||||
if @people.empty?
|
background_search(search_query) if @people.empty?
|
||||||
Workers::FetchWebfinger.perform_async(search_query)
|
|
||||||
@background_query = search_query.downcase
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@people = @people.paginate(:page => params[:page], :per_page => 15)
|
@people = @people.paginate(:page => params[:page], :per_page => 15)
|
||||||
@hashes = hashes_for_people(@people, @aspects)
|
@hashes = hashes_for_people(@people, @aspects)
|
||||||
|
|
@ -167,6 +164,12 @@ class PeopleController < ApplicationController
|
||||||
raise Diaspora::AccountClosed if @person.closed_account?
|
raise Diaspora::AccountClosed if @person.closed_account?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def background_search(search_query)
|
||||||
|
Workers::FetchWebfinger.perform_async(search_query)
|
||||||
|
@background_query = search_query.downcase
|
||||||
|
gon.preloads[:background_query] = @background_query
|
||||||
|
end
|
||||||
|
|
||||||
def hashes_for_people(people, aspects)
|
def hashes_for_people(people, aspects)
|
||||||
people.map {|person|
|
people.map {|person|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,20 +16,12 @@
|
||||||
.col-md-8
|
.col-md-8
|
||||||
#people_stream.stream
|
#people_stream.stream
|
||||||
- if @hashes.empty?
|
- if @hashes.empty?
|
||||||
- if @background_query.present?
|
|
||||||
|
|
||||||
/ TODO this is gross, and should be extracted!
|
|
||||||
:javascript
|
|
||||||
$(document).ready( function() {
|
|
||||||
List.startSearchDelay('#{@background_query}')
|
|
||||||
} );
|
|
||||||
|
|
||||||
%p
|
%p
|
||||||
|
- if @background_query.present?
|
||||||
= t(".searching")
|
= t(".searching")
|
||||||
.loader
|
.loader
|
||||||
.spinner
|
.spinner
|
||||||
- else
|
- else
|
||||||
%p
|
|
||||||
= t('.no_one_found')
|
= t('.no_one_found')
|
||||||
- else
|
- else
|
||||||
- for hash in @hashes
|
- for hash in @hashes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue