Merge remote-tracking branch 'origin/szzh' into szzh

This commit is contained in:
sw 2014-07-29 11:16:14 +08:00
commit e7503237f1
9 changed files with 136 additions and 25 deletions

View File

@ -18,7 +18,7 @@
class MessagesController < ApplicationController
menu_item :boards
default_search_scope :messages
before_filter :find_board, :only => [:new, :preview]
before_filter :find_board, :only => [:new, :preview,:edit]
before_filter :find_attachments, :only => [:preview]
before_filter :find_message, :except => [:new, :preview]
before_filter :authorize, :except => [:preview, :edit, :destroy, :new]
@ -107,7 +107,15 @@ class MessagesController < ApplicationController
flash[:notice] = l(:notice_successful_update)
@message.reload
redirect_to board_message_path(@message.board, @message.root, :r => (@message.parent_id && @message.id))
elsif request.get?
respond_to do |format|
format.html {
layout_file = @project ? 'base_projects' : 'base_courses'
render :layout => layout_file
}
end
end
end
# Delete a messages

View File

@ -408,19 +408,33 @@ module UserScoreHelper
update_score(option_number)
end
#发帖数
def memo_num(user,project=nil)
Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count
end
#更新对缺陷留言数
def update_messges_for_issue(user,type)
option_number = get_option_number(user,type)
option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}'").all.count
option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count
update_score(option_number)
end
def messges_for_issue_num(user,project=nil)
Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count
end
#更新更改缺陷状态状态次数
def update_issues_status(user,type)
option_number = get_option_number(user,type)
option_number.issues_status = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
update_score(option_number)
end
def issues_status_num(user,project=nil)
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
end
#更新对留言的回复数量
def update_replay_for_message(user,type)
option_number = get_option_number(user,type)
@ -428,6 +442,10 @@ module UserScoreHelper
update_score(option_number)
end
def replay_for_message_num(user,project=nil)
JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count
end
#更新对帖子的回复数量
def update_replay_for_memo(user,type)
option_number = get_option_number(user,type)
@ -435,6 +453,10 @@ module UserScoreHelper
update_score(option_number)
end
def replay_for_memo_num(user,project=nil)
Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count + Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count
end
#更新被关注的人数
def update_follow(user,type)
option_number = get_option_number(user,type)
@ -442,6 +464,10 @@ module UserScoreHelper
update_score(option_number)
end
def follow_num(user,project=nil)
Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count
end
#更新帖子踩各项数量
def update_tread(user,type)
option_number = get_option_number(user,type)
@ -472,6 +498,31 @@ module UserScoreHelper
update_score(option_number)
end
def tread_num(user,project=nil)
result0 = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count
pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all
result = []
result1 = []
result2 = []
pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil?
next
end
target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project
if level == 1 && target_user.id = user.id
result << pt
elsif level == 2 && target_user.id = user.id
result1 << pt
elsif level == 3 && target_user.id = user.id
result2 << pt
end
end
[:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count]
end
#更新帖子顶数量
def update_praise(user,type)
option_number = get_option_number(user,type)
@ -501,6 +552,30 @@ module UserScoreHelper
update_score(option_number)
end
def praise_num(user,project=nil)
pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all
result = []
result1 = []
result2 = []
pts.each do |pt|
obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id)
if obj.nil?
next
end
target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project
if level == 1 && target_user.id = user.id
result << pt
elsif level == 2 && target_user.id = user.id
result1 << pt
elsif level == 3 && target_user.id = user.id
result2 << pt
end
end
[:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count]
end
#更新提交代码次数
def update_changeset(user,type)
option_number = get_option_number(user,type)
@ -508,6 +583,10 @@ module UserScoreHelper
update_score(option_number)
end
def changeset_num(user,project=nil)
Changeset.includes(:user).where("user_id = '#{user.id}'").all.count
end
#更新文档提交次数
def update_document(user,type)
option_number = get_option_number(user,type)
@ -515,6 +594,10 @@ module UserScoreHelper
update_score(option_number)
end
def document(user,project=nil?)
Document.includes(:user).where("user_id = '#{user.id}'").all.count
end
#更新附件提交数量
def update_attachment(user,type)
option_number = get_option_number(user,type)
@ -522,6 +605,10 @@ module UserScoreHelper
update_score(option_number)
end
def attachment_num(user,project=nil)
Attachment.includes(:author).where("author_id = '#{user.id}'").all.count
end
#更新缺陷完成度次数
def update_issue_done_ratio(user,type)
option_number = get_option_number(user,type)
@ -529,10 +616,17 @@ module UserScoreHelper
update_score(option_number)
end
def issue_done_ratio_num(user,project)
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count
end
#更新发布缺陷次数
def update_post_issue(user,type)
option_number = get_option_number(user,type)
option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number)
end
def post_issue_num(user,project=nil)
Issue.includes(:author).where("author_id = '#{user.id}'").all.count
end
end

View File

@ -48,7 +48,7 @@ class Journal < ActiveRecord::Base
# fq
after_create :act_as_activity,:be_user_score
# end
after_destroy :down_user_score
#before_save :be_user_score
#before_destroy :down_user_score
@ -158,19 +158,13 @@ class Journal < ActiveRecord::Base
# 更新用户分数 -by zjc
def be_user_score
#新建了缺陷留言且留言不为空,不为空白
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(User.current,1)
end
end
# 减少用户分数 -by zjc
def down_user_score
#删除有效缺陷留言
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分减分
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
end
update_messges_for_issue(User.current,1)
end
end

View File

@ -20,6 +20,7 @@ class JournalDetail < ActiveRecord::Base
belongs_to :journal
before_save :normalize_values
after_create :be_user_score
after_destroy :down_user_score
private
def normalize_values
@ -42,12 +43,18 @@ class JournalDetail < ActiveRecord::Base
def be_user_score
#更新缺陷完成度
if self.prop_key = 'done_ratio'
if self.prop_key == 'done_ratio'
update_issue_done_ratio(User.current,1)
#更新缺陷状态
elsif self.prop_key = 'status_id'
elsif self.prop_key == 'status_id'
update_issues_status(User.current , 1)
end
end
#更新用户分数
def down_user_score
update_issue_done_ratio(User.current,1)
update_issues_status(User.current , 1)
end
end

View File

@ -44,7 +44,7 @@ class Memo < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters!,:be_user_score
# after_update :update_memos_forum
after_destroy :reset_counters!
after_destroy :reset_counters!,:down_user_score
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
@ -157,4 +157,10 @@ class Memo < ActiveRecord::Base
end
end
#被删除时更新用户分数
def down_user_score
update_memo_number(User.current,1)
update_replay_for_memo(User.current,1)
end
end

View File

@ -59,7 +59,7 @@ class Message < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters!
after_update :update_messages_board
after_destroy :reset_counters!
after_destroy :reset_counters!,:down_user_score
# fq
after_create :act_as_activity,:be_user_score
@ -158,14 +158,11 @@ class Message < ActiveRecord::Base
update_replay_for_memo(User.current,1)
end
end
#减少用户分数
def down_user_score
#删除发帖
if self.parent_id.nil?
UserScore.joint(:delete_message, User.current,nil, { message_id: self.id })
#删除留言
else
UserScore.joint(:reply_deleting, User.current,self.parent.author, { message_id: self.id })
end
#更新发帖和回帖数量
update_memo_number(User.current,1)
update_replay_for_memo(User.current,1)
end
end

View File

@ -1,3 +1,8 @@
<% @nav_dispaly_home_path_label = 1
@nav_dispaly_main_course_label = 1
@nav_dispaly_main_project_label = 1
@nav_dispaly_main_contest_label = 1 %>
<% @nav_dispaly_forum_label = 1%>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -275,10 +275,10 @@
<%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %>
</span>
<span class="memo_author">
<%=l(:label_question_sponsor)%>:&nbsp;<%= link_to_user(topic.author) %>
<%=l(:label_question_sponsor)%>:&nbsp;<%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %>
</span>
<span class="memo_last_person">
<%=l(:label_final_reply)%>:&nbsp;<%=link_to_user topic.last_reply.try(:author) %>
<%=l(:label_final_reply)%>:&nbsp;<% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %><%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%><% end %>
</span>
<span class="memo_reply">
<%=l(:label_reply)%>(<%= link_to topic.try(:replies_count), topic.event_url %>)

View File

@ -243,10 +243,10 @@
<%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %>
</span>
<span class="memo_author">
楼主: <%= link_to_user(topic.author) %>
楼主: <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %>
</span>
<span class="memo_last_person">
最后回复:<%= link_to_user topic.last_reply.try(:author) %>
最后回复:<% unless (topic.last_reply.nil? || topic.last_reply.author.nil?) %><%=link_to topic.last_reply.author.login.truncate(10, omission: '...'),user_path(topic.last_reply.author),title: topic.last_reply.author.login%><% end %>
</span>
<span class="memo_reply">
回复(<%= link_to topic.try(:replies_count), topic.event_url %>)