diff --git a/Changelog.md b/Changelog.md
index 9e7e4cb9e..8c7cc3d52 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -33,6 +33,8 @@
* 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)
* 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
diff --git a/app/assets/javascripts/widgets/search.js b/app/assets/javascripts/widgets/search.js
index 675b6f8b8..ebe1009fe 100644
--- a/app/assets/javascripts/widgets/search.js
+++ b/app/assets/javascripts/widgets/search.js
@@ -31,7 +31,11 @@
if (typeof row.search !== "undefined") {
return Diaspora.I18n.t("search_for", row);
} else {
- return "
" + row.name;
+ if (row.avatar) {
+ return "
" + row.name;
+ } else {
+ return row.name;
+ }
}
};
@@ -62,7 +66,7 @@
window.location = self.searchFormAction + '?' + self.searchInputName + '=' + data['name'];
} else { // The actual result
self.options.element.val(formatted);
- window.location = data['url'];
+ window.location = data['url'] ? data['url'] : "/tags/" + searchForm.attr('name');
}
};
};
diff --git a/app/assets/templates/header_tpl.jst.hbs b/app/assets/templates/header_tpl.jst.hbs
index 9733982ed..948617e69 100644
--- a/app/assets/templates/header_tpl.jst.hbs
+++ b/app/assets/templates/header_tpl.jst.hbs
@@ -103,7 +103,7 @@
-
diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb
index d11742ec3..85d06471e 100644
--- a/app/controllers/people_controller.rb
+++ b/app/controllers/people_controller.rb
@@ -4,7 +4,6 @@
class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :last_post]
- before_filter :redirect_if_tag_search, :only => [:index]
respond_to :html, :except => [:tag_index]
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'}
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
def hashes_for_people(people, aspects)
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
new file mode 100644
index 000000000..cb6802267
--- /dev/null
+++ b/app/controllers/search_controller.rb
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 558fd070d..e29ca6b9b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -64,6 +64,9 @@ Diaspora::Application.routes.draw do
resources :photos, :except => [:index] do
put :make_profile_photo
end
+
+ #Search
+ get 'search' => "search#search"
resources :conversations do
resources :messages, :only => [:create, :show]
diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb
index c38ed5148..75980194a 100644
--- a/spec/controllers/people_controller_spec.rb
+++ b/spec/controllers/people_controller_spec.rb
@@ -64,23 +64,6 @@ describe PeopleController do
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
it 'assigns hashes' do
get :index, :q => "Korth"
diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb
new file mode 100644
index 000000000..e048c376d
--- /dev/null
+++ b/spec/controllers/search_controller_spec.rb
@@ -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