From 90a35fa24a5d62beaef5cdde3f7161ed76e2133a Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 28 Jul 2014 15:06:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E3=80=81=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E9=A6=96=E9=A1=B5=EF=BC=8C=E8=B4=B4=E5=90=A7=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=90=8D=E5=AD=97=E8=BF=87=E9=95=BF=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E8=AF=BE=E7=A8=8B=E3=80=81=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=BC=96=E8=BE=91=E8=B4=B4=E5=AD=90=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 10 +++++++++- app/views/layouts/base_tags.html.erb | 5 +++++ app/views/welcome/contest.html.erb | 4 ++-- app/views/welcome/course.html.erb | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index e974936eb..438dd0aaf 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -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 diff --git a/app/views/layouts/base_tags.html.erb b/app/views/layouts/base_tags.html.erb index d7f53a641..6a5b490d1 100644 --- a/app/views/layouts/base_tags.html.erb +++ b/app/views/layouts/base_tags.html.erb @@ -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%> diff --git a/app/views/welcome/contest.html.erb b/app/views/welcome/contest.html.erb index 10da9f331..27afed749 100644 --- a/app/views/welcome/contest.html.erb +++ b/app/views/welcome/contest.html.erb @@ -275,10 +275,10 @@ <%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %> - <%=l(:label_question_sponsor)%>: <%= link_to_user(topic.author) %> + <%=l(:label_question_sponsor)%>: <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %> - <%=l(:label_final_reply)%>: <%=link_to_user topic.last_reply.try(:author) %> + <%=l(:label_final_reply)%>: <% 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 %> <%=l(:label_reply)%>(<%= link_to topic.try(:replies_count), topic.event_url %>) diff --git a/app/views/welcome/course.html.erb b/app/views/welcome/course.html.erb index dae00f50e..5c2b82e2a 100644 --- a/app/views/welcome/course.html.erb +++ b/app/views/welcome/course.html.erb @@ -243,10 +243,10 @@ <%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %> - 楼主: <%= link_to_user(topic.author) %> + 楼主: <%= link_to topic.author.login.truncate(10, omission: '...'),user_path(topic.author),title: topic.author.login %> - 最后回复:<%= 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 %> 回复(<%= link_to topic.try(:replies_count), topic.event_url %>) From 225e3c396a3f9c2becb431e3554be0816de28dde Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 29 Jul 2014 10:06:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=BE=97=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=88=86=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/user_score_helper.rb | 96 +++++++++++++++++++++++++++++++- app/models/journal.rb | 10 +--- app/models/journal_detail.rb | 11 +++- app/models/memo.rb | 8 ++- app/models/message.rb | 13 ++--- 5 files changed, 118 insertions(+), 20 deletions(-) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 720919369..700a162ef 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -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 diff --git a/app/models/journal.rb b/app/models/journal.rb index 8d03f2325..4e5780997 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -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 diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb index 4100a5b1c..2839077fe 100644 --- a/app/models/journal_detail.rb +++ b/app/models/journal_detail.rb @@ -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 diff --git a/app/models/memo.rb b/app/models/memo.rb index 6370065ba..3629db8a2 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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 diff --git a/app/models/message.rb b/app/models/message.rb index 2c183dc59..78071466d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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