aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRhenium <rhenium@rhe.jp>2013-08-20 19:39:46 +0900
committerRhenium <rhenium@rhe.jp>2013-08-20 19:40:04 +0900
commit63501b243d377f1f71dcc4640b6b9b6c3ede9bc0 (patch)
tree3cbd14e0a4ac9fcbfbefe1de5c98be0be86b182a
parentc03273db00ab84ec33f0c8a6721b47c517dac9a6 (diff)
downloadaclog-63501b243d377f1f71dcc4640b6b9b6c3ede9bc0.tar.gz
fix search
-rw-r--r--app/assets/javascripts/html-autoload.js2
-rw-r--r--app/controllers/search_controller.rb9
-rw-r--r--app/controllers/tweets_controller.rb20
-rw-r--r--app/helpers/tweets_helper.rb24
-rw-r--r--app/views/tweets/_tweet.html.haml4
-rw-r--r--app/views/tweets/_tweet.json.jbuilder2
-rw-r--r--app/views/tweets/search.html.haml (renamed from app/views/search/search.html.haml)0
-rw-r--r--config/routes.rb3
8 files changed, 29 insertions, 35 deletions
diff --git a/app/assets/javascripts/html-autoload.js b/app/assets/javascripts/html-autoload.js
index 8c31223..d96b80b 100644
--- a/app/assets/javascripts/html-autoload.js
+++ b/app/assets/javascripts/html-autoload.js
@@ -42,7 +42,7 @@
}
});
- function insertContent(json) {
+ function insertContent(json, status) {
var nextPage = $(json.html);
page = page + 1;
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
deleted file mode 100644
index 31efbc0..0000000
--- a/app/controllers/search_controller.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class SearchController < ApplicationController
- include Aclog::Twitter
-
- def search
- @caption = "search"
- @tweets = Tweet.parse_query(params[:query].to_s || "").reacted.order_by_id.list(params, force_page: true)
- @tweets = @tweets.recent(7) unless @tweets.to_sql.include?("`tweets`.`id`")
- end
-end
diff --git a/app/controllers/tweets_controller.rb b/app/controllers/tweets_controller.rb
index dc89879..6f91f4e 100644
--- a/app/controllers/tweets_controller.rb
+++ b/app/controllers/tweets_controller.rb
@@ -86,6 +86,12 @@ class TweetsController < ApplicationController
@tweets = Tweet.reacted.order_by_id.list(params)
end
+ def search
+ @caption = "Search"
+ @tweets = Tweet.parse_query(params[:query].to_s || "").reacted.order_by_id.list(params, force_page: true)
+ @tweets = @tweets.recent(7) unless @tweets.to_sql.include?("`tweets`.`id`")
+ end
+
private
def user_required
@user = _require_user(params[:user_id], params[:screen_name])
@@ -100,12 +106,16 @@ class TweetsController < ApplicationController
end
def render(*args)
- if lookup_context.exists?(params[:action], params[:controller])
- super(*args)
- elsif request.xhr?
- html = render_to_string(partial: "tweets/tweet", collection: @tweets.includes(:user), as: :tweet, formats: [:html])
- n = url_for(params[:page] ? params.merge(page: params[:page].to_i + 1) : params.merge(max_id: @tweets.last.id - 1))
+ if request.xhr?
+ html = render_to_string(partial: "tweets/tweet", collection: @tweets.includes(:user), as: :tweet, formats: :html)
+ n = @tweets.length > 0 ?
+ url_for(params[:page] ?
+ params.merge(page: params[:page].to_i + 1) :
+ params.merge(max_id: @tweets.last.id - 1)) :
+ nil
super json: {html: html, next: n}
+ elsif lookup_context.exists?(params[:action], params[:controller])
+ super(*args)
else
super("_tweets")
end
diff --git a/app/helpers/tweets_helper.rb b/app/helpers/tweets_helper.rb
index cfd4771..476ae55 100644
--- a/app/helpers/tweets_helper.rb
+++ b/app/helpers/tweets_helper.rb
@@ -1,26 +1,18 @@
module TweetsHelper
- def user_limit
- if request.format == :json
- if params[:limit]
- params[:limit].to_i
- else
+ def html_favoriters_limit
+ if params[:action] == "show"
+ if params[:full] == "true"
nil
- end
- else
- if params[:action] == "show"
- if params[:full] == "true"
- nil
- else
- Settings.tweets.users.count_lot
- end
else
- Settings.tweets.users.count_default
+ Settings.tweets.users.count_lot
end
+ else
+ Settings.tweets.users.count_default
end
end
- def user_truncated?(tweet)
- tr = user_limit || Float::INFINITY
+ def html_favoriters_truncated?(tweet)
+ tr = html_favoriters_limit || Float::INFINITY
tr < tweet.favorites_count || tr < tweet.retweets_count
end
end
diff --git a/app/views/tweets/_tweet.html.haml b/app/views/tweets/_tweet.html.haml
index d0ffc00..19604ef 100644
--- a/app/views/tweets/_tweet.html.haml
+++ b/app/views/tweets/_tweet.html.haml
@@ -25,7 +25,7 @@
= link_to image_tag("bird_gray_16.png", alt: "Twitter"), twitter_status_url(tweet), target: "_blank"
%span.created_at
= link_to format_time(tweet.tweeted_at), tweet_path(tweet.id)
- - if params[:action] == "show" && user_truncated?(tweet)
+ - if params[:action] == "show" && html_favoriters_truncated?(tweet)
%span.full
= link_to "full", params.merge(full: true)
%span.source
@@ -39,7 +39,7 @@
%span.type= title
%dd
%ul.inline
- - users.limit(user_limit).each do |m|
+ - users.limit(html_favoriters_limit).each do |m|
%li
- if !m.protected? || session[:user_id] == m.id || session[:user_id] == tweet.user.id
= link_to user_path(m.screen_name) do
diff --git a/app/views/tweets/_tweet.json.jbuilder b/app/views/tweets/_tweet.json.jbuilder
index 71ca10c..993b824 100644
--- a/app/views/tweets/_tweet.json.jbuilder
+++ b/app/views/tweets/_tweet.json.jbuilder
@@ -2,6 +2,8 @@ json.(tweet, :id, :favorites_count, :retweets_count)
json.user_id tweet.user_id
+user_limit = Integer(params[:limit]) rescue nil
+
json.favoriters tweet.favorites.limit(user_limit).pluck(:user_id)
json.retweeters tweet.retweets.limit(user_limit).pluck(:user_id)
diff --git a/app/views/search/search.html.haml b/app/views/tweets/search.html.haml
index c3d51b5..c3d51b5 100644
--- a/app/views/search/search.html.haml
+++ b/app/views/tweets/search.html.haml
diff --git a/config/routes.rb b/config/routes.rb
index 0b44a62..6075703 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -9,8 +9,6 @@ Aclog::Application.routes.draw do
# HTML only pages
scope format: "html" do
- get "/search" => "search#search", as: "search"
-
# Internals / SessionsController
get "/i/import/:id" => "i#import", as: "import"
get "/i/callback" => "sessions#callback"
@@ -54,6 +52,7 @@ Aclog::Application.routes.draw do
get "/best", action: "all_best", as: "best"
get "/recent", action: "all_recent", as: "recent"
get "/timeline", action: "all_timeline", as: "timeline"
+ get "/search", action: "search", as: "search"
end
# TweetController / Tweets