Merge pull request #4335 from Team-D/feature/4169-tag_search_autocomplete
#4169 tag search autocomplete
This commit is contained in:
commit
a2e5f1f88e
8 changed files with 77 additions and 33 deletions
|
|
@ -41,6 +41,8 @@
|
||||||
* Deleting a post deletes it from Tumblr too [#4331](https://github.com/diaspora/diaspora/pull/4331)
|
* Deleting a post deletes it from Tumblr too [#4331](https://github.com/diaspora/diaspora/pull/4331)
|
||||||
* OpenGraph support [#4215](https://github.com/diaspora/diaspora/pull/4215)
|
* OpenGraph support [#4215](https://github.com/diaspora/diaspora/pull/4215)
|
||||||
* Added Wordpress service ability for posts. [#4321](https://github.com/diaspora/diaspora/pull/4321)
|
* Added Wordpress service ability for posts. [#4321](https://github.com/diaspora/diaspora/pull/4321)
|
||||||
|
* Implement tag search autocomplete in header search box [#4169](https://github.com/diaspora/diaspora/issues/4169)
|
||||||
|
|
||||||
|
|
||||||
# 0.1.1.0
|
# 0.1.1.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,11 @@
|
||||||
if (typeof row.search !== "undefined") {
|
if (typeof row.search !== "undefined") {
|
||||||
return Diaspora.I18n.t("search_for", row);
|
return Diaspora.I18n.t("search_for", row);
|
||||||
} else {
|
} else {
|
||||||
return "<img src='"+ row.avatar +"' class='avatar'/>" + row.name;
|
if (row.avatar) {
|
||||||
|
return "<img src='"+ row.avatar +"' class='avatar'/>" + row.name;
|
||||||
|
} else {
|
||||||
|
return row.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -62,7 +66,7 @@
|
||||||
window.location = self.searchFormAction + '?' + self.searchInputName + '=' + data['name'];
|
window.location = self.searchFormAction + '?' + self.searchInputName + '=' + data['name'];
|
||||||
} else { // The actual result
|
} else { // The actual result
|
||||||
self.options.element.val(formatted);
|
self.options.element.val(formatted);
|
||||||
window.location = data['url'];
|
window.location = data['url'] ? data['url'] : "/tags/" + searchForm.attr('name');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@
|
||||||
|
|
||||||
|
|
||||||
<div id="global_search">
|
<div id="global_search">
|
||||||
<form accept-charset="UTF-8" action="/people" class="search_form" method="get">
|
<form accept-charset="UTF-8" action="/search" class="search_form" method="get">
|
||||||
<input name="utf8" type="hidden" value="✓">
|
<input name="utf8" type="hidden" value="✓">
|
||||||
<input id="q" name="q" placeholder="{{t "header.search"}}" results="5" type="search" autocomplete="off" class="ac_input">
|
<input id="q" name="q" placeholder="{{t "header.search"}}" results="5" type="search" autocomplete="off" class="ac_input">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
class PeopleController < ApplicationController
|
class PeopleController < ApplicationController
|
||||||
before_filter :authenticate_user!, :except => [:show, :last_post]
|
before_filter :authenticate_user!, :except => [:show, :last_post]
|
||||||
before_filter :redirect_if_tag_search, :only => [:index]
|
|
||||||
|
|
||||||
respond_to :html, :except => [:tag_index]
|
respond_to :html, :except => [:tag_index]
|
||||||
respond_to :json, :only => [:index, :show]
|
respond_to :json, :only => [:index, :show]
|
||||||
|
|
@ -162,18 +161,6 @@ class PeopleController < ApplicationController
|
||||||
render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'}
|
render :partial => 'aspect_membership_dropdown', :locals => {:contact => @contact, :person => @person, :hang => 'left'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_if_tag_search
|
|
||||||
if search_query.starts_with?('#')
|
|
||||||
if search_query.length > 1
|
|
||||||
|
|
||||||
redirect_to tag_path(:name => search_query.delete('#.'))
|
|
||||||
else
|
|
||||||
flash[:error] = I18n.t('tags.show.none', :name => search_query)
|
|
||||||
redirect_to :back
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def hashes_for_people(people, aspects)
|
def hashes_for_people(people, aspects)
|
||||||
|
|
|
||||||
26
app/controllers/search_controller.rb
Normal file
26
app/controllers/search_controller.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
class SearchController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def search
|
||||||
|
if search_query.starts_with?('#')
|
||||||
|
if search_query.length > 1
|
||||||
|
respond_to do |format|
|
||||||
|
format.json {redirect_to tags_path(:q => search_query.delete("#."))}
|
||||||
|
format.html {redirect_to tag_path(:name => search_query.delete("#."))}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
flash[:error] = I18n.t('tags.show.none', :name => search_query)
|
||||||
|
redirect_to :back
|
||||||
|
end
|
||||||
|
else
|
||||||
|
redirect_to people_path(:q => search_query)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def search_query
|
||||||
|
@search_query ||= params[:q] || params[:term] || ''
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -65,6 +65,9 @@ Diaspora::Application.routes.draw do
|
||||||
put :make_profile_photo
|
put :make_profile_photo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Search
|
||||||
|
get 'search' => "search#search"
|
||||||
|
|
||||||
resources :conversations do
|
resources :conversations do
|
||||||
resources :messages, :only => [:create, :show]
|
resources :messages, :only => [:create, :show]
|
||||||
delete 'visibility' => 'conversation_visibilities#destroy'
|
delete 'visibility' => 'conversation_visibilities#destroy'
|
||||||
|
|
|
||||||
|
|
@ -64,23 +64,6 @@ describe PeopleController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'query is a tag' do
|
|
||||||
it 'goes to a tag page' do
|
|
||||||
get :index, :q => '#babies'
|
|
||||||
response.should redirect_to(tag_path('babies'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'removes dots from the query' do
|
|
||||||
get :index, :q => '#babi.es'
|
|
||||||
response.should redirect_to(tag_path('babies'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'stay on the page if you search for the empty hash' do
|
|
||||||
get :index, :q => '#'
|
|
||||||
flash[:error].should be_present
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'query is not a tag or a diaspora ID' do
|
context 'query is not a tag or a diaspora ID' do
|
||||||
it 'assigns hashes' do
|
it 'assigns hashes' do
|
||||||
get :index, :q => "Korth"
|
get :index, :q => "Korth"
|
||||||
|
|
|
||||||
39
spec/controllers/search_controller_spec.rb
Normal file
39
spec/controllers/search_controller_spec.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe SearchController do
|
||||||
|
before do
|
||||||
|
@user = alice
|
||||||
|
@aspect = @user.aspects.first
|
||||||
|
sign_in :user, @user
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'query is a person' do
|
||||||
|
@lola = FactoryGirl.create(:person, :diaspora_handle => "lola@example.org",
|
||||||
|
:profile => FactoryGirl.build(:profile, :first_name => "Lola",
|
||||||
|
:last_name => "w", :searchable => false))
|
||||||
|
it 'goes to people index page' do
|
||||||
|
get :search, :q => 'eugene'
|
||||||
|
response.should be_redirect
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe 'query is a tag' do
|
||||||
|
it 'goes to a tag page' do
|
||||||
|
get :search, :q => '#cats'
|
||||||
|
response.should redirect_to(tag_path('cats'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'removes dots from the query' do
|
||||||
|
get :search, :q => '#cat.s'
|
||||||
|
response.should redirect_to(tag_path('cats'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'stay on the page if you search for the empty hash' do
|
||||||
|
get :search, :q => '#'
|
||||||
|
flash[:error].should be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue