Merge branch 'search-repeatedly' of https://github.com/stwf/diaspora into stwf-search-repeatedly
This commit is contained in:
commit
2a30e60fe0
10 changed files with 140 additions and 5 deletions
|
|
@ -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.downcase
|
||||
end
|
||||
@people = @people.paginate(:page => params[:page], :per_page => 15)
|
||||
@hashes = hashes_for_people(@people, @aspects)
|
||||
|
|
@ -42,6 +43,20 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def refresh_search
|
||||
@aspect = :search
|
||||
@people = Person.where(:diaspora_handle => search_query.downcase)
|
||||
@answer_html = ""
|
||||
unless @people.empty?
|
||||
@hashes = hashes_for_people(@people, @aspects)
|
||||
|
||||
self.formats = self.formats + [:html]
|
||||
@answer_html = render_to_string :partial => 'people/person', :locals => @hashes.first
|
||||
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,9 +18,14 @@
|
|||
.span-15.append-1
|
||||
#people_stream.stream
|
||||
- if @hashes.empty?
|
||||
%p
|
||||
=t('.no_one_found')
|
||||
|
||||
- if @background_query.present?
|
||||
%p
|
||||
=t('.searching')
|
||||
:javascript
|
||||
$(document).ready(function() { List.startSearchDelay('#{@background_query}') } );
|
||||
- else
|
||||
%p
|
||||
=t('.no_one_found')
|
||||
- else
|
||||
- for hash in @hashes
|
||||
= render :partial => 'people/person', :locals => hash
|
||||
|
|
|
|||
|
|
@ -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}."
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ en:
|
|||
my_stream: "Stream"
|
||||
|
||||
videos:
|
||||
watch: "Watch this video on <%= provider %>"
|
||||
unknown: "Unknown video type"
|
||||
watch: "Watch this video on <%= provider %>"
|
||||
unknown: "Unknown video type"
|
||||
search_for: "Search for <%= name %>"
|
||||
publisher:
|
||||
at_least_one_aspect: "You must publish to at least one aspect"
|
||||
|
|
@ -73,6 +73,8 @@ en:
|
|||
looking_good: "OMG, you look awesome!"
|
||||
tags:
|
||||
wasnt_that_interesting: "OK, I suppose #<%= tagName %> wasn't all that interesting..."
|
||||
people:
|
||||
not_found: "and no one was found..."
|
||||
|
||||
stream:
|
||||
hide: "Hide"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -32,7 +32,26 @@ var List = {
|
|||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
runDelayedSearch: function( searchTerm ) {
|
||||
$.ajax({
|
||||
dataType: 'json',
|
||||
url: '/people/refresh_search',
|
||||
data: { q: searchTerm },
|
||||
success: List.handleSearchRefresh
|
||||
});
|
||||
},
|
||||
handleSearchRefresh: function( data ) {
|
||||
if ( data.search_count > 0 ) {
|
||||
$("#people_stream.stream").html( data.search_html );
|
||||
} else {
|
||||
$("#people_stream.stream").html( "<p>" + Diaspora.I18n.t("people.not_found") + "</p>" );
|
||||
}
|
||||
},
|
||||
startSearchDelay: function ( theSearch ) {
|
||||
setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@ Diaspora.Pages.ContactsIndex = function() {
|
|||
self.infiniteScroll = self.instantiate("InfiniteScroll");
|
||||
$('.conversation_button').twipsy({position: 'below'});
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
|||
22
spec/controllers/jasmine_fixtures/people_spec.rb
Normal file
22
spec/controllers/jasmine_fixtures/people_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe PeopleController do
|
||||
describe '#index' do
|
||||
before do
|
||||
sign_in :user, bob
|
||||
end
|
||||
|
||||
it "generates a jasmine fixture with no query", :fixture => true do
|
||||
get :index
|
||||
save_fixture(html_for("body"), "empty_people_search")
|
||||
end
|
||||
it "generates a jasmine fixture trying an external search", :fixture => true do
|
||||
get :index, :q => "sample@diaspor.us"
|
||||
save_fixture(html_for("body"), "pending_external_people_search")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -52,6 +52,11 @@ describe PeopleController do
|
|||
get :index, :q => "Eugene@Example.ORG"
|
||||
assigns[:people][0].id.should == @unsearchable_eugene.id
|
||||
end
|
||||
|
||||
it 'sets the background query task' do
|
||||
get :index, :q => "Eugene@Example.ORG"
|
||||
assigns[:background_query].should == "eugene@example.org"
|
||||
end
|
||||
end
|
||||
|
||||
context 'query is a tag' do
|
||||
|
|
@ -77,6 +82,11 @@ describe PeopleController do
|
|||
assigns[:hashes].should_not be_nil
|
||||
end
|
||||
|
||||
it 'does not set the background query task' do
|
||||
get :index, :q => "Korth"
|
||||
assigns[:background_query].should_not be_present
|
||||
end
|
||||
|
||||
it "assigns people" do
|
||||
eugene2 = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
|
|
@ -351,6 +361,34 @@ 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
|
||||
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)
|
||||
|
|
|
|||
31
spec/javascripts/search-spec.js
Normal file
31
spec/javascripts/search-spec.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
describe("List", function() {
|
||||
|
||||
describe("runDelayedSearch", function() {
|
||||
beforeEach( function(){
|
||||
});
|
||||
|
||||
it('gets called on initialize', function(){
|
||||
spyOn( List, 'startSearchDelay');
|
||||
spec.loadFixture('pending_external_people_search');
|
||||
expect(List.startSearchDelay).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("runDelayedSearch", function() {
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('empty_people_search');
|
||||
List.initialize();
|
||||
});
|
||||
|
||||
it('inserts contact html', function(){
|
||||
List.handleSearchRefresh( { count:1,search_html: '<div class='testing_insert_div'>hello</div>' } );
|
||||
expect($(".testing_insert_div").text().toEqual( "hello" ));
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue