Permalink
Browse files

Merge with server

  • Loading branch information...
2 parents 2888347 + bda13dd commit baced99af4781f28ec3c83e97e21d3138867ea68 @nowa nowa committed Apr 20, 2011
Showing with 2,598 additions and 735 deletions.
  1. +2 −1 Gemfile
  2. +16 −3 app/controllers/application_controller.rb
  3. +20 −2 app/controllers/asks_controller.rb
  4. +1 −3 app/controllers/cpanel/answers_controller.rb
  5. +1 −3 app/controllers/cpanel/asks_controller.rb
  6. +1 −3 app/controllers/cpanel/comments_controller.rb
  7. +1 −3 app/controllers/cpanel/topics_controller.rb
  8. +1 −3 app/controllers/cpanel/users_controller.rb
  9. +54 −14 app/controllers/search_controller.rb
  10. +1 −0 app/controllers/users_controller.rb
  11. +6 −0 app/mailers/user_mailer.rb
  12. +9 −5 app/models/ask.rb
  13. +6 −3 app/models/base_model.rb
  14. +72 −12 app/models/search.rb
  15. +29 −4 app/models/topic.rb
  16. +12 −1 app/models/user.rb
  17. 0 app/views/asks/{_answer.html.erb → _answer.erb}
  18. +36 −0 app/views/asks/_ask.mobile.erb
  19. 0 app/views/asks/{_base.html.erb → _base.erb}
  20. 0 app/views/asks/{_form.html.erb → _form.erb}
  21. +17 −0 app/views/asks/_sidebar.mobile.erb
  22. +1 −1 app/views/asks/index.html.erb
  23. +22 −0 app/views/asks/index.mobile.erb
  24. 0 app/views/asks/{new.html.erb → new.erb}
  25. +52 −0 app/views/asks/share.html.erb
  26. +6 −0 app/views/asks/share.js.erb
  27. +32 −15 app/views/asks/show.html.erb
  28. +202 −0 app/views/asks/show.mobile.erb
  29. +1 −1 app/views/cpanel/answers/_form.html.erb
  30. +28 −17 app/views/cpanel/answers/index.html.erb
  31. +26 −17 app/views/cpanel/asks/index.html.erb
  32. +1 −1 app/views/cpanel/comments/_form.html.erb
  33. +24 −18 app/views/cpanel/comments/index.html.erb
  34. +24 −19 app/views/cpanel/topics/index.html.erb
  35. +1 −1 app/views/cpanel/users/_form.html.erb
  36. +26 −17 app/views/cpanel/users/index.html.erb
  37. +22 −0 app/views/devise/invitations/edit.mobile.erb
  38. +25 −0 app/views/devise/invitations/new.mobile.erb
  39. 0 app/views/devise/menu/{_login_items.html.erb → _login_items.erb}
  40. 0 app/views/devise/menu/{_registration_items.html.erb → _registration_items.erb}
  41. +26 −0 app/views/devise/passwords/edit.mobile.erb
  42. +17 −0 app/views/devise/passwords/new.mobile.erb
  43. +4 −0 app/views/devise/sessions/create.mobile.erb
  44. +29 −0 app/views/devise/sessions/new.mobile.erb
  45. +4 −0 app/views/errors/404.mobile.erb
  46. +40 −0 app/views/home/about.mobile.erb
  47. +23 −0 app/views/home/index.mobile.erb
  48. +50 −0 app/views/home/newbie.mobile.erb
  49. +25 −0 app/views/home/recommended.mobile.erb
  50. +26 −9 app/views/layouts/application.html.erb
  51. +132 −0 app/views/layouts/application.mobile.erb
  52. +230 −0 app/views/logs/_log.mobile.erb
  53. +81 −0 app/views/logs/_notifies.js.erb
  54. +81 −0 app/views/logs/_notifies.mobile.erb
  55. +27 −0 app/views/logs/index.mobile.erb
  56. +45 −0 app/views/registrations/new.mobile.erb
  57. 0 app/views/shared/{_error_messages.html.erb → _error_messages.erb}
  58. 0 app/views/shared/{_omniauth_links.html.erb → _omniauth_links.erb}
  59. +80 −0 app/views/topics/show.mobile.erb
  60. +1 −0 app/views/user_mailer/simple.html.erb
  61. 0 app/views/users/{_answered_ask.html.erb → _answered_ask.erb}
  62. 0 app/views/users/{_follower.html.erb → _follower.erb}
  63. +71 −0 app/views/users/_head.mobile.erb
  64. +33 −0 app/views/users/_sidebar.mobile.erb
  65. 0 app/views/users/{_topic.html.erb → _topic.erb}
  66. +13 −0 app/views/users/answered.mobile.erb
  67. +13 −0 app/views/users/asked.mobile.erb
  68. +13 −0 app/views/users/followers.mobile.erb
  69. +13 −0 app/views/users/following_topics.mobile.erb
  70. +60 −0 app/views/users/show.mobile.erb
  71. +1 −1 comet/faye.js
  72. +3 −0 config/routes.rb
  73. +1 −0 config/sphinx.yml.default
  74. +2 −0 db/dict/build.sh
  75. +1 −1 lib/zomet.rb
  76. BIN public/images/add_ask.gif
  77. BIN public/images/email.gif
  78. BIN public/images/loading.gif
  79. BIN public/images/loading1.gif
  80. BIN public/images/url.gif
  81. +20 −0 public/javascripts/application.js
  82. +108 −109 public/javascripts/asks.js
  83. +2 −2 public/javascripts/facebox.js
  84. +87 −46 public/javascripts/jquery.autocomplete.js
  85. +124 −0 public/stylesheets/application.css
  86. +120 −0 public/stylesheets/asks.css
  87. +1 −2 public/stylesheets/facebox.css
  88. +30 −397 public/stylesheets/front.css
  89. +7 −1 public/stylesheets/jquery.autocomplete.css
  90. +74 −0 public/stylesheets/mobile.css
  91. +102 −0 public/stylesheets/users.css
View
@@ -7,6 +7,7 @@ gem "bson", "1.2.4"
gem "bson_ext", "1.2.4"
gem 'mongo-rails-instrumentation'
gem "mongoid-eager-loading"
+# gem "mongoid-sphinx-huacnlee", :path => "/Users/jason/work/mongoid-sphinx", :require => "mongoid_sphinx"
gem "mongoid-sphinx-huacnlee", :require => "mongoid_sphinx"
gem "mongoid_rails_migrations"
@@ -68,4 +69,4 @@ gem "resque"
gem "resque_mailer"
# Comet
-gem "juggernaut"
+gem "juggernaut"
@@ -2,7 +2,20 @@
class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
- before_filter :load_notice
+ before_filter :init, :load_notice
+ has_mobile_fu
+
+ def init
+ if params[:force_format] == "mobile"
+ cookies[:mobile] = true
+ elsif params[:force_format] == "desktop"
+ cookies[:mobile] = nil
+ end
+
+ if !cookies[:mobile].blank? and request.format.to_sym == :html
+ force_mobile_format
+ end
+ end
def load_notice
@notice = Notice.last
@@ -14,8 +27,8 @@ def load_notice
end
# 暂时不使用mobile-fu的功能,仅仅使用其is_mobile_device?方法
- include ActionController::MobileFu::InstanceMethods
- helper_method :is_mobile_device?
+ #include ActionController::MobileFu::InstanceMethods
+ #helper_method :is_mobile_device?
# Comet Server
use_zomet
@@ -6,8 +6,7 @@ class AsksController < ApplicationController
def index
@per_page = 20
- @asks = Ask.normal.recent.includes(:user,:topics)
- .paginate(:page => params[:page], :per_page => @per_page)
+ @asks = Ask.normal.recent.includes(:user).paginate(:page => params[:page], :per_page => @per_page)
set_seo_meta("所有问题")
end
@@ -73,6 +72,25 @@ def redirect
end
end
+ def share
+ @ask = Ask.find(params[:id])
+ if request.get?
+ if current_user
+ render "share", :layout => false
+ else
+ render_404
+ end
+ else
+ case params[:type]
+ when "email"
+ UserMailer.simple(params[:to], params[:subject], params[:body].gsub("\n","<br />")).deliver
+ @success = true
+ @msg = "已经将问题连接发送到了 #{params[:to]}"
+ end
+ end
+
+ end
+
def answer
@answer = Answer.new(params[:answer])
@answer.ask_id = params[:id]
@@ -2,9 +2,7 @@
class Cpanel::AnswersController < CpanelController
def index
- @answers = initialize_grid(Answer,
- :order => 'id',
- :order_direction => 'desc')
+ @answers = Answer.includes([:user]).desc("created_at").paginate(:page => params[:page], :per_page => 20)
respond_to do |format|
format.html # index.html.erb
@@ -2,9 +2,7 @@
class Cpanel::AsksController < CpanelController
def index
- @asks = initialize_grid(Ask,
- :order => 'id',
- :order_direction => 'desc')
+ @asks = Ask.includes([:user]).desc("created_at").paginate(:page => params[:page], :per_page => 40)
respond_to do |format|
format.html # index.html.erb
@@ -2,9 +2,7 @@
class Cpanel::CommentsController < CpanelController
def index
- @comments = initialize_grid(Comment,
- :order => 'id',
- :order_direction => 'desc')
+ @comments = Comment.desc("created_at").paginate(:page => params[:page], :per_page => 40)
respond_to do |format|
format.html # index.html.erb
@@ -2,9 +2,7 @@
class Cpanel::TopicsController < CpanelController
def index
- @topics = initialize_grid(Topic,
- :order => 'id',
- :order_direction => 'desc')
+ @topics = Topic.desc("created_at").paginate(:page => params[:page], :per_page => 40)
respond_to do |format|
format.html # index.html.erb
@@ -2,9 +2,7 @@
class Cpanel::UsersController < CpanelController
def index
- @users = initialize_grid(User,
- :order => 'id',
- :order_direction => 'desc')
+ @users = User.desc("created_at").paginate(:page => params[:page], :per_page => 40)
respond_to do |format|
format.html # index.html.erb
@@ -2,52 +2,92 @@
class SearchController < ApplicationController
def index
- if params[:format] == "json"
- result = Search.query(params["w"].to_s.strip,:limit => 10)
- render :json => result.to_json
- else
- @asks = Ask.search_title(params["w"].to_s.strip,:limit => 20)
- set_seo_meta("关于“#{params[:w]}”的搜索结果")
- render "/asks/index"
+ @asks = Ask.search_title(params["w"].to_s.strip,:limit => 20)
+ set_seo_meta("关于“#{params[:w]}”的搜索结果")
+ render "/asks/index"
+ end
+
+ def all
+ result = Search.query(params[:q].strip,:limit => 10)
+ lines = []
+ result.each do |item|
+ case item['type']
+ when "Ask"
+ lines << complete_line_ask(item)
+ when "User"
+ lines << complete_line_user(item)
+ when "Topic"
+ lines << complete_line_topic(item)
+ end
end
+ render :text => lines.join("\n")
end
def topics
- result = Search.query(params[:q],:type => "Topic",:limit => 10)
+ result = Search.complete(params[:q].strip,:type => "Topic",:limit => 10)
if params[:format] == "json"
- render :json => result.to_json
+ lines = []
+ result.each do |item|
+ lines << complete_line_topic(item)
+ end
+ render :text => lines.join("\n")
else
lines = []
result.each do |item|
- lines << item['title']
+ lines << complete_line_topic(item)
end
render :text => lines.join("\n")
end
end
def asks
- result = Search.query(params[:q],:type => "Ask",:limit => 10)
+ result = Search.query(params[:q].strip,:type => "Ask",:limit => 10)
if params[:format] == "json"
render :json => result.to_json
else
lines = []
result.each do |item|
- lines << "#{item['title']}#!##{item['id']}"
+ lines << complete_line_ask(item)
end
render :text => lines.join("\n")
end
end
def users
- result = Search.query(params[:q],:type => "User",:limit => 10)
+ result = Search.complete(params[:q],:type => "User",:limit => 10)
if params[:format] == "json"
render :json => result.to_json
else
lines = []
result.each do |item|
- lines << "#{item['title']}#!##{item['id']}#!##{item['tagline']}#!##{item['avatar_small']}#!##{item['slug']}"
+ lines << complete_line_user(item)
end
render :text => lines.join("\n")
end
end
+
+ private
+ def complete_line_ask(item,hash = true)
+ if hash
+ "#{item['title']}#!##{item['id']}#!##{item['topics'].join(',')}#!#Ask"
+ else
+ "#{item.title.gsub("\n",'')}#!##{item.id}#!##{item.topics.join(',')}#!#Ask"
+ end
+ end
+
+ def complete_line_topic(item,hash = true)
+ if hash
+ "#{item['title']}#!##{item['followers_count']}#!##{item['cover_small']}#!#Topic"
+ else
+ "#{item.name}#!##{item.followers_count}#!##{item.cover_small}#!#Topic"
+ end
+ end
+
+ def complete_line_user(item,hash = true)
+ if hash
+ "#{item['title']}#!##{item['id']}#!##{item['tagline']}#!##{item['avatar_small']}#!##{item['slug']}#!#User"
+ else
+ "#{item.name}#!##{item.id}#!##{item.tagline}#!##{item.avatar_small}#!##{item.slug}#!#User"
+ end
+ end
end
@@ -110,6 +110,7 @@ def auth_callback
auth = request.env["omniauth.auth"]
redirect_to root_path if auth.blank?
provider_name = auth['provider'].gsub(/^t/,"").titleize
+ Rails.logger.debug { auth }
if current_user
Authorization.create_from_hash(auth, current_user)
@@ -61,5 +61,11 @@ def ask_user(ask_id)
mail(:to => @user.email, :subject => @title, :from => Setting.email_sender)
end
+ def simple(to, subject, content)
+ @title = subject
+ @content = content
+ mail(:to => to, :subject => @title, :from => Setting.email_sender)
+ end
+
end
View
@@ -51,16 +51,16 @@ class Ask
# 正常可显示的问题, 前台调用都带上这个过滤
scope :normal, where(:spams_count.lt => Setting.ask_spam_max)
scope :last_actived, desc(:answered_at)
- scope :recent, desc("$natural")
+ scope :recent, desc("created_at")
# 除开一些 id,如用到 mute 的问题,传入用户的 muted_ask_ids
scope :exclude_ids, lambda { |id_array| not_in("_id" => (id_array ||= [])) }
scope :only_ids, lambda { |id_array| any_in("_id" => (id_array ||= [])) }
# 问我的问题
scope :asked_to, lambda { |to_user_id| where(:to_user_id => to_user_id) }
# FullText indexes
- search_index(:fields => [:title,:body, :topics],
- :attributes => [],
+ search_index(:fields => [:title,:topics],
+ :attributes => [:title,:topics],
:options => {} )
redis_search_index(:title_field => :title,:ext_fields => [:topics])
@@ -180,9 +180,13 @@ def self.mmseg_text(text)
result = Ask.search(text,:max_matches => 1)
words = []
result.raw_result[:words].each do |w|
- next if w[0] == "ask"
- words << ((w[0] == "rubi" and text.downcase.index("ruby")) ? "ruby" : w[0])
+ t = w[0].dup.force_encoding("utf-8")
+ next if t == "ask"
+ words << ((t == "rubi" and text.downcase.index("ruby")) ? "ruby" : t )
end
+ # 修正顺序
+ words = words.sort { |x,y| (text.index(x) || -1) <=> (text.index(y) || -1) }
+ Rails.logger.debug { "mmseg:#{words}" }
words
end
View
@@ -15,7 +15,6 @@ def spam?(attr)
return false
end
end
-
end
module ClassMethods
@@ -49,12 +48,16 @@ def remove_search_index
def update_search_index
index_fields_changed = false
#{ext_fields}.each do |f|
+ next if f.to_s == "id"
if instance_eval(f.to_s + "_changed?")
index_fields_changed = true
end
end
- if(self.#{title_field}_changed?)
- index_fields_changed = true
+ begin
+ if(self.#{title_field}_changed?)
+ index_fields_changed = true
+ end
+ rescue
end
if index_fields_changed
Rails.logger.debug { "-- update_search_index --" }
Oops, something went wrong.

0 comments on commit baced99

Please sign in to comment.