Skip to content

Commit 407d14b

Browse files
committed
add quick_search
1 parent af32cc1 commit 407d14b

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

app/controllers/dashboard_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class DashboardController < ApplicationController
22

33
has_widgets do |root|
44
root << widget(:twitter, :title => "Twitter")
5-
root << widget(:trashbin, :title => "Trash Bin")
5+
root << widget(:trashbin, :title => "Trash tweets here!")
6+
root << widget(:quick_search, :title => "Quick search")
67
end
78

89
def index

app/views/dashboard/index.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
= render_widget 'twitter'
66
.column
77
= render_widget 'trashbin'
8-
-#.column
9-
-#= render_widget 'autocomplete'
8+
.column
9+
= render_widget 'quick_search'
1010

1111
:javascript
1212
$(function() {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:javascript
2+
$().ready(function() {
3+
var input = $("##{widget_id}-field");
4+
input.autocomplete(
5+
{source: input.attr('data-load-event-url')}
6+
);
7+
});
8+
9+
What are you lookin' for?
10+
= text_field_tag "#{widget_id}-field", "", 'data-load-event-url' => url_for_event(:typing)

app/widgets/quick_search_widget.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class QuickSearchWidget < Apotomo::Widget
2+
3+
responds_to_event :typing, :with => :search
4+
after_initialize :setup!
5+
6+
def display
7+
render :layout => 'portlet'
8+
end
9+
10+
def search(evt)
11+
items = Tweet.find(:all, :conditions => "text LIKE '%#{evt[:term]}%'").
12+
collect do |t|
13+
{:label => t.text}
14+
end
15+
16+
render :text => items.to_json
17+
end
18+
19+
private
20+
def setup!(*)
21+
@title = options[:title]
22+
end
23+
24+
end

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
# You can have the root of your site routed with "root"
5252
# just remember to delete public/index.html.
53-
# root :to => 'welcome#index'
53+
root :to => 'dashboard#index'
5454

5555
# See how all your routes lay out with "rake routes"
5656

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'test_helper'
2+
3+
class QuickSearchWidgetTest < Apotomo::TestCase
4+
has_widgets do |root|
5+
root << widget(:quick_search, 'me')
6+
end
7+
8+
test "display" do
9+
render_widget 'me'
10+
assert_select "h1"
11+
end
12+
end

0 commit comments

Comments
 (0)