Skip to content
Extraits de code Groupes Projets
Valider 23aff2af rédigé par Steven Fuchs's avatar Steven Fuchs
Parcourir les fichiers

run second search ajaxily when no results are found from remote pod.

parent 9b08f3f6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -35,6 +35,7 @@ class PeopleController < ApplicationController
if diaspora_id?(search_query)
@people = Person.where(:diaspora_handle => search_query.downcase)
Webfinger.in_background(search_query) if @people.empty?
@background_query = search_query
end
@people = @people.paginate(:page => params[:page], :per_page => 15)
@hashes = hashes_for_people(@people, @aspects)
......@@ -42,6 +43,22 @@ class PeopleController < ApplicationController
end
end
def refresh_search
@aspect = :search
@people = Person.where(:diaspora_handle => search_query.downcase)
@people = @people.paginate(:page => params[:page], :per_page => 15)
@hashes = hashes_for_people(@people, @aspects)
@answer_html = ""
self.formats = self.formats + [:html]
@hashes.each do |hash|
@answer_html += render_to_string :partial => 'people/person', :locals => hash
end
render :json => { :search_count => @people.count, :search_html => @answer_html }.to_json
end
def tag_index
profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id')
@people = Person.where(:id => profiles.map{|p| p.person_id}).paginate(:page => params[:page], :per_page => 15)
......
......@@ -18,12 +18,16 @@
.span-15.append-1
#people_stream.stream
- if @hashes.empty?
%p
%p#not_found{:class => @background_query.nil? ? "" : "hidden" }
=t('.no_one_found')
%p#searching{:class => @background_query.nil? ? "hidden" : "" }
=t('.searching')
- if ! @background_query.nil?
:javascript
$(document).ready(function() { setTimeout("runDelayedSearch('#{@background_query}')", 10000); });
- else
- for hash in @hashes
= render :partial => 'people/person', :locals => hash
= render :partial => 'people/person.html', :locals => hash
= will_paginate @people
......
......@@ -536,6 +536,7 @@ en:
no_results: "Hey! You need to search for something."
couldnt_find_them_send_invite: "Couldn't find them? Send an invite!"
no_one_found: "...and no one was found."
searching: "searching, please be patient..."
looking_for: "Looking for posts tagged %{tag_link}?"
webfinger:
fail: "Sorry, we couldn't find %{handle}."
......
......@@ -124,6 +124,7 @@ Diaspora::Application.routes.draw do
get 'community_spotlight' => "contacts#spotlight", :as => 'community_spotlight'
get 'people/refresh_search' => "people#refresh_search"
resources :people, :except => [:edit, :update] do
resources :status_messages
resources :photos
......
......@@ -6,3 +6,21 @@ Diaspora.Pages.ContactsIndex = function() {
$('.conversation_button').twipsy({position: 'below'});
});
};
function runDelayedSearch( searchTerm ) {
$.ajax({
dataType: 'json',
url: '/people/refresh_search',
data: { q: searchTerm },
success: handleSearchRefresh
});
}
function handleSearchRefresh(data) {
if ( data.search_count > 0 ) {
$("#people_stream.stream").html( data.search_html );
} else {
$("p#not_found").removeClass( 'hidden' );
$("p#searching").addClass( 'hidden' );
}
}
\ No newline at end of file
......@@ -351,6 +351,35 @@ describe PeopleController do
end
end
describe '#refresh_search ' do
before(:each)do
@eugene = Factory(:person,
:profile => Factory.build(:profile, :first_name => "Eugene", :last_name => "w"))
@korth = Factory(:person,
:profile => Factory.build(:profile, :first_name => "Evan", :last_name => "Korth"))
end
describe 'via json' do
it 'returns a zero count when a search fails' do
get :refresh_search, :q => "weweweKorth", :format => 'json'
response.body.should == {:search_count=>0, :search_html=>""}.to_json
end
it 'returns with a zero count unless a fully composed name is sent' do
get :refresh_search, :q => "Korth"
response.body.should == {:search_count=>0, :search_html=>""}.to_json
end
it 'returns with a found name' do
get :refresh_search, :q => @korth.diaspora_handle
puts JSON.parse( response.body ).inspect
JSON.parse( response.body )["search_count"].should == 1
end
end
end
describe '#contacts' do
it 'assigns the contacts of a person' do
contact = alice.contact_for(bob.person)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter