almost done
This commit is contained in:
parent
bbe5f56292
commit
a5bb26a3c4
6 changed files with 72 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
autocompleteInput.autoSuggest(data, {
|
||||
selectedItemProp: "name",
|
||||
searchObjProps: "name",
|
||||
asHtmlID: "contact_ids",
|
||||
asHtmlID: "tag_ids",
|
||||
keyDelay: 0,
|
||||
startText: '',
|
||||
emptyText: '#{t('.no_results')}',
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue