Permalink
Browse files

Merge branch 'master' into sphinx_search

  • Loading branch information...
2 parents e759da3 + cf88f82 commit c9f1ed80f154907fef59d79d581b7621b927a7e9 @huacnlee committed Apr 15, 2011
Showing with 468 additions and 75,940 deletions.
  1. +2 −0 .gitignore
  2. +10 −0 app/controllers/application_controller.rb
  3. +75 −0 app/controllers/cpanel/notices_controller.rb
  4. +15 −3 app/controllers/users_controller.rb
  5. +9 −6 app/helpers/application_helper.rb
  6. +2 −0 app/helpers/cpanel/notices_helper.rb
  7. +1 −1 app/mailers/user_mailer.rb
  8. +2 −0 app/models/ask.rb
  9. +8 −0 app/models/notice.rb
  10. +1 −1 app/views/asks/show.html.erb
  11. +15 −0 app/views/cpanel/notices/_base.html.erb
  12. +14 −0 app/views/cpanel/notices/_form.html.erb
  13. +6 −0 app/views/cpanel/notices/edit.html.erb
  14. +23 −0 app/views/cpanel/notices/index.html.erb
  15. +5 −0 app/views/cpanel/notices/new.html.erb
  16. +18 −0 app/views/cpanel/notices/show.html.erb
  17. +14 −2 app/views/layouts/application.html.erb
  18. +1 −0 app/views/layouts/cpanel.html.erb
  19. +3 −1 app/views/logs/_log.html.erb
  20. +2 −2 app/views/logs/index.html.erb
  21. +2 −2 app/views/topics/show.html.erb
  22. +1 −1 app/views/user_mailer/ask_user.html.erb
  23. +3 −3 app/views/users/_follower.html.erb
  24. +2 −0 app/views/users/_head.html.erb
  25. +2 −24 app/views/users/_sidebar.html.erb
  26. +3 −3 app/views/users/_topic.html.erb
  27. +2 −0 config/routes.rb
  28. +0 −75,880 db/dict/thesaurus.txt
  29. +7 −1 public/404.html
  30. +8 −2 public/500.html
  31. +1 −0 public/google0813ea2e8992f7bb.html
  32. +7 −1 public/javascripts/application.js
  33. +1 −0 public/javascripts/asks.js
  34. +97 −0 public/javascripts/jquery.cookie.js
  35. +8 −4 public/javascripts/topics.js
  36. +21 −0 public/javascripts/users.js
  37. +16 −1 public/stylesheets/application.css
  38. +8 −2 public/stylesheets/front.css
  39. +49 −0 test/functional/cpanel/notices_controller_test.rb
  40. +4 −0 test/unit/helpers/cpanel/notices_helper_test.rb
View
@@ -7,9 +7,11 @@ tmp/
config/*.yml
public/javascripts/cached_*
public/stylesheets/cached_*
+public/google*.html
public/about.html
db/sphinx
db/dict/*.lib
+db/dict/thesaurus.txt
#以bundle install --path vendor/bundle方式安装,不影响开发者现有gems环境
vendor/bundle
@@ -2,6 +2,16 @@
class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
+ before_filter :load_notice
+
+ def load_notice
+ @notice = Notice.last
+ if !@notice.blank? and !@notice.end_at.blank?
+ if @notice.end_at < Time.now
+ @notice = nil
+ end
+ end
+ end
# 暂时不使用mobile-fu的功能,仅仅使用其is_mobile_device?方法
include ActionController::MobileFu::InstanceMethods
@@ -0,0 +1,75 @@
+# coding: UTF-8
+class Cpanel::NoticesController < CpanelController
+
+ def index
+ @notices = initialize_grid(Notice,
+ :order => 'id',
+ :order_direction => 'desc')
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json
+ end
+ end
+
+ def show
+ @notice = Notice.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json
+ end
+ end
+
+ def new
+ @notice = Notice.new
+ @notice.end_at = Time.now + 1.days
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json
+ end
+ end
+
+ def edit
+ @notice = Notice.find(params[:id])
+ end
+
+ def create
+ @notice = Notice.new(params[:notice])
+
+ respond_to do |format|
+ if @notice.save
+ format.html { redirect_to(cpanel_notices_path, :notice => 'Notice 创建成功。') }
+ format.json
+ else
+ format.html { render :action => "new" }
+ format.json
+ end
+ end
+ end
+
+ def update
+ @notice = Notice.find(params[:id])
+
+ respond_to do |format|
+ if @notice.update_attributes(params[:notice])
+ format.html { redirect_to(cpanel_notices_path, :notice => 'Notice 更新成功。') }
+ format.json
+ else
+ format.html { render :action => "edit" }
+ format.json
+ end
+ end
+ end
+
+ def destroy
+ @notice = Notice.find(params[:id])
+ @notice.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(cpanel_notices_path,:notice => "删除成功。") }
+ format.json
+ end
+ end
+end
@@ -20,6 +20,18 @@ def answered
render "/users/answered_asks.js"
end
end
+
+ def asked_to
+ @per_page = 10
+ @asks = Ask.normal.recent.asked_to(@user.id)
+ .paginate(:page => params[:page], :per_page => @per_page)
+ set_seo_meta("#{@user.name}的问题")
+ if params[:format] == "js"
+ render "/asks/index.js"
+ else
+ render "asked"
+ end
+ end
def show
@per_page = 10
@@ -42,7 +54,7 @@ def asked
end
def following_topics
- @per_page = 10
+ @per_page = 20
@topics = @user.followed_topics.desc("$natural")
.paginate(:page => params[:page], :per_page => @per_page)
@@ -53,7 +65,7 @@ def following_topics
end
def followers
- @per_page = 10
+ @per_page = 20
@followers = @user.followers.desc("$natural")
.paginate(:page => params[:page], :per_page => @per_page)
@@ -64,7 +76,7 @@ def followers
end
def following
- @per_page = 10
+ @per_page = 20
@followers = @user.following.desc("$natural")
.paginate(:page => params[:page], :per_page => @per_page)
@@ -11,8 +11,11 @@ def use_yahei_font?(ua)
return use
end
- def ask_notification_tag(ask_id, log, a, show_ask = true)
+ def ask_notification_tag(ask_id, notify, show_ask = true)
return if ask_id.nil?
+
+ log = notify.log
+ a = notify.action
tag = ""
ask = Ask.find(ask_id)
return "" if ask.nil? or log.user.nil?
@@ -22,29 +25,29 @@ def ask_notification_tag(ask_id, log, a, show_ask = true)
case a
when "AGREE_ANSWER", "NEW_ANSWER_COMMENT"
tag += user_tag + " #{a == "AGREE_ANSWER" ? "赞成" : "评论"}了你在"
- ask_tag = "<a href=\"#{ask_path(ask)}#{a == "AGREE_ANSWER" ? "#answer_" + log.target_id.to_s : "?eawc=yes&awid=" + log.title.to_s + "#answer_" + log.title.to_s}\">#{show_ask ? ask.title : "该问题中的回答。"}</a>" + (show_ask ? " 中的回答。" : "")
+ ask_tag = "<a onclick=\"mark_notifies_as_read(this, '#{notify.id}');\" href=\"#{ask_path(ask)}#{a == "AGREE_ANSWER" ? "#answer_" + log.target_id.to_s : "?eawc=yes&awid=" + log.title.to_s + "#answer_" + log.title.to_s}\">#{show_ask ? ask.title : "该问题中的回答。"}</a>" + (show_ask ? " 中的回答。" : "")
tag += (show_ask ? "问题 " : "") + ask_tag
when "NEW_ANSWER", "NEW_ASK_COMMENT"
tag += user_tag + " #{a == "NEW_ANSWER" ? "回答" : "评论"}"
- ask_tag = "<a href=\"#{ask_path(ask)}#{a == "NEW_ASK_COMMENT" ? "?easc=yes&asid=" + log.target_parent_id.to_s : ""}#answer_#{log.target_id.to_s}\">#{show_ask ? ask.title : "该问题。"}</a>"
+ ask_tag = "<a onclick=\"mark_notifies_as_read(this, '#{notify.id}');\" href=\"#{ask_path(ask)}#{a == "NEW_ASK_COMMENT" ? "?easc=yes&asid=" + log.target_parent_id.to_s : ""}#answer_#{log.target_id.to_s}\">#{show_ask ? ask.title : "该问题。"}</a>"
tag += (show_ask ? "问题 " : "") + ask_tag
when "THANK_ANSWER"
tag += user_tag + "感谢了你"
if show_ask
- ask_tag = "在 <a href=\"#{ask_path(ask)}?nr=1#answer_#{log.target_id.to_s}\">#{ask.title}</a> 的回答。"
+ ask_tag = "在 <a onclick=\"mark_notifies_as_read(this, '#{notify.id}');\" href=\"#{ask_path(ask)}?nr=1#answer_#{log.target_id.to_s}\">#{ask.title}</a> 的回答。"
else
ask_tag = "的回答。"
end
tag += ask_tag
when "INVITE_TO_ANSWER"
tag += user_tag + "邀请你回答 "
if show_ask
- tag += "<a href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
+ tag += "<a onclick=\"mark_notifies_as_read(this, '#{notify.id}');\" href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
end
when "ASK_USER"
tag += user_tag + "向你询问 "
if show_ask
- tag += "<a href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
+ tag += "<a onclick=\"mark_notifies_as_read(this, '#{notify.id}');\" href=\"#{ask_path(ask)}?nr=1\">#{ask.title}</a>"
end
end
return tag
@@ -0,0 +1,2 @@
+module Cpanel::NoticesHelper
+end
@@ -57,7 +57,7 @@ def invite_to_answer(ask_id, user_id, invitor_ids)
def ask_user(ask_id)
@ask = Ask.find(ask_id)
@user = @ask.to_user
- @title = "#{@ask.user.name}对向你询问#{@ask.title}"
+ @title = "#{@ask.user.name}向你询问#{@ask.title}"
mail(:to => @user.email, :subject => @title, :from => Setting.email_sender)
end
View
@@ -55,6 +55,8 @@ class Ask
# 除开一些 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,:topics],
View
@@ -0,0 +1,8 @@
+class Notice
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :body
+ field :end_at, :type => DateTime
+
+end
@@ -71,7 +71,7 @@
<% end %>
• <a href="#new_answer" onclick="return $('#new_answer .qeditor_preview').focus();">添加答案</a>
• <a href="#" onclick="return Asks.report(this);">举报</a>
- • <a class="spam<%= ' spamed' if spamed?(@ask) %>" onclick="return Asks.spamAsk(this,'<%= @ask.id %>');" title="问题被<%= Setting.ask_spam_max %>个网友不感兴趣后,问题将会隐藏。" href="#">不感兴趣</a>
+ • <a class="spam<%= ' spamed' if spamed?(@ask) %>" onclick="return Asks.spamAsk(this,'<%= @ask.id %>');" title="问题被<%= Setting.ask_spam_max %>个网友认为是烂问题以后,问题将会隐藏。" href="#">烂问题</a>
<% if !@ask.spams_count.blank? %>(<span id="spams_count"><%= @ask.spams_count %></span>人认为)<% end %>
• <span class="date"><%= l @ask.created_at.getlocal, :format => :short %></span>
</div>
@@ -0,0 +1,15 @@
+<%= content_for :base_sitemap do %>
+<a href="<%= cpanel_notices_path %>">cpanel_notices</a> »
+<% end %>
+<%= content_for :styles do %>
+<% end %>
+
+<%= spaceless do %>
+<div class="tools">
+ <a href="<%= cpanel_notices_path %>" class="button small left<%= ' checked' if params[:action] == "index" %>">查看所有</a>
+ <% if ["edit","update"].index(params[:action]) %>
+ <a href="#" class="button small checked">编辑</a>
+ <% end %>
+ <a href="<%= new_cpanel_notice_path %>" class="button small right<%= ' checked' if ["new","create"].index(params[:action]) %>">新建</a>
+</div>
+<% end %>
@@ -0,0 +1,14 @@
+<div id="cpanel_notice" class="form">
+<%= simple_form_for(@notice,
+ :url => (@notice.created_at.blank? ? cpanel_notices_path : cpanel_notice_path(@notice.id)) ) do |f| %>
+
+ <div class="inputs">
+ <%= f.input :body, :as => :text %>
+ <%= f.input :end_at, :as => :string %>
+ </div>
+ <div class="actions">
+ <button type="submit">提交</button>
+ 或者 <%= link_to '返回', cpanel_notices_path %>
+ </div>
+<% end %>
+</div>
@@ -0,0 +1,6 @@
+<%= content_for :sitemap do %>
+<span class="current">修改</span>
+<% end %>
+<%= render 'base' %>
+<%= render 'form' %>
+
@@ -0,0 +1,23 @@
+<%= content_for :sitemap do %>
+<span class="current">列表</span>
+<% end %>
+<%= render 'base' %>
+
+<div id="cpanel_notices">
+ <%= grid(@notices, :show_filters => :always) do |g|
+ g.column :column_name => '', :attribute_name => '_id'
+ g.column :column_name => 'body', :attribute_name => 'body' do |c|
+ c.body if !c.body.blank?
+ end
+ g.column :column_name => 'end_at', :attribute_name => 'end_at' do |c|
+ c.end_at if !c.end_at.blank?
+ end
+ g.column :column_name => '创建时间', :attribute_name => 'created_at', :td_html_attrs => { :style => "width:120px;" }
+ g.column :td_html_attrs => { :style => "width:50px; text-align:right;" } do |c|
+ raw "#{link_to '修改', edit_cpanel_notice_path(c.id)}
+ #{link_to image_tag("wice_grid/delete.png", :style => "margin-bottom:-4px"), cpanel_notice_path(c.id), :method => :delete, :confirm => '确定要删除吗?'}"
+ end
+ end %>
+</div>
+
+
@@ -0,0 +1,5 @@
+<%= content_for :sitemap do %>
+<span class="current">新建</span>
+<% end %>
+<%= render 'base' %>
+<%= render 'form' %>
@@ -0,0 +1,18 @@
+<%= content_for :sitemap do %>
+<span class="current">查看</span>
+<% end %>
+<%= render 'base' %>
+<div class="tools">
+ <%= link_to '修改', edit_cpanel_notice_path(@notice) %> |
+ <%= link_to '返回', cpanel_notices_path %>
+</div>
+<div id="cpanel_notice">
+ <p>
+ <b>Body:</b>
+ <%= @notice.body %>
+ </p>
+ <p>
+ <b>End at:</b>
+ <%= @notice.end_at %>
+ </p>
+ </div>
@@ -16,7 +16,7 @@
<meta name="description" content="<%= @meta_description %>" />
<link rel="shortcut icon" href="/favicon.ico?v=003" />
<%= csrf_meta_tag %>
- <%= javascript_include_tag "jquery.min","rails","facebox","jquery.jdialog","jquery.qeditor","jquery.autocomplete","jcaches","application","asks", :cache => "cached_application" %>
+ <%= javascript_include_tag "jquery.min","rails","facebox","jquery.jdialog","jquery.qeditor","jquery.autocomplete", "jquery.cookie" ,"jcaches","application","asks","topics","users", :cache => "cached_application" %>
<%= yield :scripts %>
<script type="text/javascript">
<% if current_user %>
@@ -57,6 +57,17 @@
<div id="main">
<div class="container">
<div class="left_wrapper">
+ <% if !@notice.blank? %>
+ <% if cookies[:hide_notice] != @notice.id.to_s %>
+ <div id="sys_notice">
+ <%= raw @notice.body %>
+ <div class="info">
+ <span class="date"><%= l @notice.updated_at.getlocal, :format => :long %></span>
+ <a href="#" class="gray_button small" onclick="return App.hideNotice('<%= @notice.id %>');">我知道了</a>
+ </div>
+ </div>
+ <% end %>
+ <% end %>
<% if !notice.blank? %>
<div class="notice_message"><%= notice %></div>
<script type="text/javascript">
@@ -81,6 +92,7 @@
<div class="left_wrapper">
<div class="links">
<a href="/about">关于者也</a> •
+ <a href="/asks/4d95f33bfd503c3bf2000011">每天进步一点</a> •
<a href="http://blog.zheye.org" target="_blank">博客</a> •
<a href="/register">如何注册</a> •
<a href="http://twitter.com/zheyecn" target="_blank">Twitter</a> •
@@ -108,7 +120,7 @@
<div class="logo"></div>
<div class="text">加载中…</div>
</div>
- <div style="width:0px;height;0px;overflow:hidden;">
+ <div style="width:0px;height:0px;overflow:hidden;">
<%= image_tag("loading.gif") %>
<div id="report_page">
<h2>举报内容</h2>
@@ -16,6 +16,7 @@
控制台 <a href="<%= root_path %>" class="out">回前台</a>
</td>
<td id="nav">
+ <a href="<%= cpanel_notices_path %>">公告</a> |
<a href="<%= cpanel_users_path %>">用户</a> |
<a href="<%= cpanel_asks_path %>">问题</a> |
<a href="<%= cpanel_answers_path %>">回答</a> |
@@ -76,7 +76,9 @@ when "UserLog"
item = User.first(:conditions => { :id => log.target_id})
elsif ["AGREE"].include?(action)
answer = Answer.first(:conditions => {:id => log.target_id})
- item = answer.ask
+ if !answer.blank?
+ item = answer.ask
+ end
elsif ["THANK_ANSWER"].include?(action)
item = Answer.first(:conditions => {:id => log.target_id})
end
Oops, something went wrong.

0 comments on commit c9f1ed8

Please sign in to comment.