From 05cf2d24dc18f5ad69896b3aae86d9933fa1afe9 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 13 Jan 2016 15:29:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=A1=B9=E7=9B=AE=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=20=E8=AE=A8=E8=AE=BA=E5=8C=BA=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=E5=8A=A0=E5=85=A5=E5=BE=97=E5=88=86=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=20=E7=89=88=E6=9C=AC=E5=BA=93=E8=A1=8C=E5=8F=B7=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 6 +++++ app/models/message.rb | 22 ++++++++++++++----- app/views/layouts/base_projects.html.erb | 11 +++++----- ...113063514_add_messages_count_to_project.rb | 5 +++++ .../20160113064153_statics_boards_reply.rb | 14 ++++++++++++ db/schema.rb | 3 ++- public/stylesheets/scm.css | 1 + 7 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20160113063514_add_messages_count_to_project.rb create mode 100644 db/migrate/20160113064153_statics_boards_reply.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4fcb43172..4b7820037 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,6 +49,12 @@ module ApplicationHelper end end + # 获取项目/课程总分 + # 发布缺陷 4分 回复缺陷 1分 提交一次 4分 讨论帖子 2分 回复帖子 1分 发布新闻 1分 + def static_project_score obj + score = obj.issues_count * 4 + obj.journals_count + obj.commits_count * 4 + obj.boards_count * 2 + obj.boards_reply_count + obj.news_count + end + # 获取组织成员中文名字 def get_org_member_role_name member case member.roles[0].name diff --git a/app/models/message.rb b/app/models/message.rb index c43657aa5..a133ecdfc 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -127,9 +127,15 @@ class Message < ActiveRecord::Base # 发帖精辟更新发帖总数 def add_boards_count - if self.project && self.parent_id.nil? - count = self.project.boards_count + 1 - self.project.update_attribute(:boards_count, count) + if self.project + # 讨论区 + if self.parent_id.nil? + count = self.project.boards_count + 1 + self.project.update_attribute(:boards_count, count) + else # 回复 + count = self.project.boards_reply_count + 1 + self.project.update_attribute(:boards_reply_count, count) + end end end @@ -314,8 +320,14 @@ class Message < ActiveRecord::Base # 删除帖子的时候更新帖子总数, 删除回复的时候总数不减少 def decrease_boards_count if self.project && self.parent_id.nil? - count = self.project.boards_count - 1 - self.project.update_attribute(:boards_count, count) + # 讨论区 + if self.parent_id.nil? + count = self.project.boards_count - 1 + self.project.update_attribute(:boards_count, count) + else # 回复 + count = self.project.boards_reply_count - 1 + self.project.update_attribute(:boards_reply_count, count) + end end end diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 8bee1b7e2..8ecc6fb54 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -76,12 +76,13 @@
<% if @project.project_type == 0 %> - <% unless project_scores(@project) == 0 %> + <% unless static_project_score(@project) == 0 %> <%= l(:label_project_score)%> : - <%= link_to(format("%.2f" ,project_scores(@project) ).to_i, {:controller => 'projects', - :action => 'show_projects_score', - :remote => true, - :id => @project.id}, :class => "c_orange f14" ) %> + <%= link_to(format("%.2f" ,static_project_score(@project) ).to_i, + {:controller => 'projects', + :action => 'show_projects_score', + :remote => true, + :id => @project.id}, :class => "c_orange f14" ) %> <% end %> <% end %>
diff --git a/db/migrate/20160113063514_add_messages_count_to_project.rb b/db/migrate/20160113063514_add_messages_count_to_project.rb new file mode 100644 index 000000000..218ac3cc4 --- /dev/null +++ b/db/migrate/20160113063514_add_messages_count_to_project.rb @@ -0,0 +1,5 @@ +class AddMessagesCountToProject < ActiveRecord::Migration + def change + add_column :projects, :boards_reply_count, :integer, :default => false + end +end diff --git a/db/migrate/20160113064153_statics_boards_reply.rb b/db/migrate/20160113064153_statics_boards_reply.rb new file mode 100644 index 000000000..baf427b10 --- /dev/null +++ b/db/migrate/20160113064153_statics_boards_reply.rb @@ -0,0 +1,14 @@ +class StaticsBoardsReply < ActiveRecord::Migration + def up + Project.all.each do |project| + puts project.id + unless project.boards.first.nil? + messages_count = Message.where("board_id =? and parent_id is not ?", project.boards.first.id, nil).count + project.update_attribute(:boards_reply_count, messages_count) + end + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index fc3762bd1..5079e6655 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160108024752) do +ActiveRecord::Schema.define(:version => 20160113064153) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1417,6 +1417,7 @@ ActiveRecord::Schema.define(:version => 20160108024752) do t.integer "news_count", :default => 0 t.integer "acts_count", :default => 0 t.integer "journals_count", :default => 0 + t.integer "boards_reply_count", :default => 0 end add_index "projects", ["lft"], :name => "index_projects_on_lft" diff --git a/public/stylesheets/scm.css b/public/stylesheets/scm.css index 054b0bf99..b8b624154 100644 --- a/public/stylesheets/scm.css +++ b/public/stylesheets/scm.css @@ -52,6 +52,7 @@ table.filecontent th.line-num { -ms-user-select: none; -webkit-user-select: none; font-weight:normal; + white-space: nowrap; } table.filecontent th.line-num a { text-decoration: none;