Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change to searching for cities

  • Loading branch information...
commit 8bb8c996011388bcd5c228950c755404a5148981 1 parent 74a962a
@alevy alevy authored
View
21 app.rb
@@ -34,7 +34,7 @@ def client
def friends
@friends ||= settings.cache.fetch("#{session[:at]}:friends") do
friends = client.fql_query("SELECT uid, name, current_location FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me())")
- settings.cache.set("#{session[:at]}:friends", friends, 60)
+ settings.cache.set("#{session[:at]}:friends", friends, 600)
friends
end
end
@@ -53,7 +53,7 @@ def friends
@user = settings.cache.fetch("#{session[:at]}:me") do
user = Mogli::User.find("me", @client)
- settings.cache.set("#{session[:at]}:me", user, 60)
+ settings.cache.set("#{session[:at]}:me", user, 600)
user
end
@@ -66,16 +66,25 @@ def friends
content_type :json
query = params[:term].downcase
+ cities = friends.map do |friend|
+ friend["current_location"] and friend["current_location"]["city"]
+ end
+ cities.uniq!
+
+ result = cities.select do |city|
+ city and city.downcase.index(query)
+ end
+ result.to_json
+end
+
+get "/friends_in" do
result = friends.select do |friend|
if friend["current_location"]
- friend["name"].downcase.index(query)
+ friend["current_location"]["city"] == params[:city]
else
nil
end
end
- result = result.map do |friend|
- {:label => friend["name"], :value => friend["current_location"]["name"] }
- end
result.to_json
end
View
18 public/javascript/application.js
@@ -1,12 +1,16 @@
$(function() {
$("#friend_name").autocomplete({
source: "/search",
- select: function( event, ui ) {
- if (ui.item) {
- window.location.href = "mailto:" + ui.item.value;
- }
+ minLength: 2,
+ select: function(event, ui) {
+ $.getJSON("/friends_in?city=" + ui.item.label, function(data) {
+ $("#friends_list").html("");
+ $.each(data, function(i, friend) {
+ $("#friends_list").append("<li>" + friend.name + "</li>");
+ });
+ });
+ $("#friend_name").val("");
+ return false;
}
- }).data("autocomplete")._renderItem = function(ul, item) {
- return $("<li></li>").append("<a>" + item.label + " (" + item.value + ")</a>").appendTo(ul);
- };
+ })
});
View
9 public/stylesheets/base.css
@@ -77,6 +77,15 @@ input[type="search"] {
border: 1px solid #999;
}
+ul#friends_list {
+ padding: 10px;
+}
+
+ul#friends_list li {
+ font-size: 16px;
+ margin: 5px;
+}
+
/* ------------------------------------------ */
/* =clearfix
View
6 views/index.erb
@@ -36,8 +36,12 @@
</div>
</header>
<section id="search">
- <h2>Search for a friend's e-mail by name:</h2>
+ <h2>Search for a city:</h2>
<input type="search" id="friend_name"/>
</section>
+ <section>
+ <ul id="friends_list">
+ </ul>
+ </section>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.