diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 8df259e1d..576f05f7f 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -8,6 +8,30 @@ class TagsController < ApplicationController skip_before_filter :which_action_and_user skip_before_filter :set_grammatical_gender + respond_to :html, :only => [:show] + respond_to :json, :only => [:index] + + def index + pp params + if params[:q].length > 1 + @tags = ActsAsTaggableOn::Tag.named_like(params[:q]) + @hash = @tags.inject([]) do |memo, obj| + memo << { :name => obj.name, + :value => ("#"+obj.name)} + end + + respond_to do |format| + format.json{ + json = { :items => @hash}.to_json + render(:json => json, :status => 201) + } + end + else + pp "not!" + render :nothing => true + end + end + def show if current_user @posts = StatusMessage.joins(:aspects).where(:pending => false diff --git a/app/views/conversations/new.haml b/app/views/conversations/new.haml index bd1e9d59d..7f392d9a0 100644 --- a/app/views/conversations/new.haml +++ b/app/views/conversations/new.haml @@ -10,7 +10,7 @@ autocompleteInput.autoSuggest(data, { selectedItemProp: "name", searchObjProps: "name", - asHtmlID: "contact_ids", + asHtmlID: "tag_ids", keyDelay: 0, startText: '', emptyText: '#{t('.no_results')}', diff --git a/app/views/profiles/_edit_public.html.haml b/app/views/profiles/_edit_public.html.haml index 30820f0fa..f1b8e4811 100644 --- a/app/views/profiles/_edit_public.html.haml +++ b/app/views/profiles/_edit_public.html.haml @@ -2,6 +2,25 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +- content_for :head do + = include_javascripts :profile + +:javascript + $(document).ready(function () { + var autocompleteInput = $("#profile_tag_string"); + + autocompleteInput.autoSuggest("#{tags_path}", { + selectedItemProp: "name", + searchObjProps: "name", + asHtmlID: "tag_ids", + keyDelay: 0, + startText: '', + emptyText: '#{t('.no_results')}', + }); + + autocompleteInput.focus(); + }); + %h3 = t('profiles.edit.your_public_profile') diff --git a/config/assets.yml b/config/assets.yml index 0425d1d04..ed858a34a 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -62,6 +62,8 @@ javascripts: inbox: - public/javascripts/vendor/jquery.autoSuggest.js - public/javascripts/inbox.js + profile: + - public/javascripts/vendor/jquery.autoSuggest.js stylesheets: default: diff --git a/config/routes.rb b/config/routes.rb index f8d68a5e6..fb86493e8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ Diaspora::Application.routes.draw do resources :comments, :only => [:create, :destroy] get 'tags/:name' => 'tags#show', :as => 'tag' + resources :tags, :only => [:index] resource :like, :only => [:create] diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 207497862..0fcc167fa 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -7,11 +7,34 @@ require 'spec_helper' describe TagsController do render_views - describe '#show' do + before do + @user = alice + end + + describe '#index (search)' do before do - @user = alice + sign_in :user, @user + bob.profile.tag_string = "#cats #diaspora #rad" + bob.profile.build_tags + bob.profile.save! end + it 'responds with json' do + get :index, :q => "ra", :format => 'json' + #parse json + response.body.should include("#diaspora") + response.body.should include("#rad") + end + + it 'requires at least two characters' do + get :index, :q => "c", :format => 'json' + response.body.should_not include("#cats") + end + end + + describe '#show' do + + context 'signed in' do before do sign_in :user, @user