diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index efff6efdf..c4932b1b2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -456,7 +456,9 @@ class FilesController < ApplicationController end end # 更新资源总数, 根据上传的附件数累加 - @project.update_attribute(:attachments_count, @project.attachments_count + attachments[:files].count) + unless @project.project_score.nil? + @project.project_score.update_attribute(:attach_num, @project.project_score.attach_num + attachments[:files].count) + end # end # TODO: 临时用 nyan sort_init 'created_on', 'desc' diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 708fbf6cb..f2de6085f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -203,6 +203,8 @@ class ProjectsController < ApplicationController end end + # 注意:修改该方法的时候注意同步修改forked方法 + # forked方法也会创建项目 def create unless User.current.login? redirect_to signin_url @@ -222,6 +224,11 @@ class ProjectsController < ApplicationController #unless User.current.admin? r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) + # project's score + if ProjectScore.where("project_id=?", @project.id).first.nil? + ProjectScore.create(:project_id => @project.id, :score => false) + end + # end project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) user_grades = UserGrade.create(:user_id => User.current.id, :project_id => @project.id) Rails.logger.debug "UserGrade created: #{user_grades.to_json}" diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 4d407e35e..0a9de787a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -122,6 +122,9 @@ class RepositoriesController < ApplicationController if project.save r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) + if ProjectScore.where("project_id=?", @project.id).first.nil? + ProjectScore.create(:project_id => @project.id, :score => false) + end project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id) user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id) Rails.logger.debug "UserGrade created: #{user_grades.to_json}" @@ -349,7 +352,10 @@ update # @changesets_count = @repository.latest_changesets(@path, @rev).count @changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count # 访问该页面的是会后则刷新 - if @changesets_all_count != @project.commits_count && @changesets_all_count != 0 + if @project.project_score.nil? + ProjectScore.create(:project_id => @project.id, :score => false) + end + if @changesets_all_count != @project.project_score.changeset_num && @changesets_all_count != 0 update_commits_count(@project, @changesets_all_count) end # end @@ -580,7 +586,7 @@ update private # 更新项目统计数 def update_commits_count project, count - project.update_attribute(:commits_count, count) + project.project_score.update_attribute(:changeset_num, count) end def find_repository diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 2f6c4ecc7..63f152eb2 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -683,7 +683,7 @@ class StudentWorkController < ApplicationController if !params[:name].nil? condition = "%#{params[:name].strip}%".gsub(" ","") end - @project_ids = Project.where("user_id = #{User.current.id} and name like '#{condition}'") + @project_ids = Project.visible.where("user_id = #{User.current.id} and name like '#{condition}'") @first = params[:first].to_i respond_to do |format| format.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 17f80cec8..be9c59992 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -52,7 +52,7 @@ module ApplicationHelper # 获取项目/课程总分 # 发布缺陷 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 + obj.attachments_count * 5 + score = obj.issue_num * 4 + obj.issue_journal_num + obj.changeset_num * 4 + obj.board_num * 2 + obj.board_message_num + obj.news_num + obj.attach_num * 5 end # 获取组织成员中文名字 diff --git a/app/models/course.rb b/app/models/course.rb index 4e3b4fff0..24e955d15 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,6 +1,7 @@ require 'elasticsearch/model' class Course < ActiveRecord::Base include Redmine::SafeAttributes + include ApplicationHelper STATUS_ACTIVE = 1 STATUS_CLOSED = 5 diff --git a/app/models/forge_activity.rb b/app/models/forge_activity.rb index 310d194a0..c98c5475b 100644 --- a/app/models/forge_activity.rb +++ b/app/models/forge_activity.rb @@ -20,8 +20,8 @@ class ForgeActivity < ActiveRecord::Base validates :forge_act_id,presence: true validates :forge_act_type, presence: true has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity, :add_org_activity, :add_acts_count - before_destroy :destroy_user_activity, :destroy_org_activity, :decrease_acts_count + after_save :add_user_activity, :add_org_activity + before_destroy :destroy_user_activity, :destroy_org_activity #在个人动态里面增加当前动态 def add_user_activity @@ -45,21 +45,6 @@ class ForgeActivity < ActiveRecord::Base end end - # 更新动态数 - def add_acts_count - if self.project - count = self.project.acts_count + 1 - self.project.update_attribute(:acts_count, count) - end - end - - def decrease_acts_count - if self.project - count = self.project.acts_count - 1 - self.project.update_attribute(:acts_count, count) - end - end - def add_org_activity org_activity = OrgActivity.where("org_act_type = '#{self.forge_act_type.to_s}' and org_act_id = #{self.forge_act_id}").first if org_activity diff --git a/app/models/issue.rb b/app/models/issue.rb index e898296af..e1de4cd9e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -19,6 +19,7 @@ class Issue < ActiveRecord::Base include Redmine::SafeAttributes include Redmine::Utils::DateCalculation include UserScoreHelper + include ApplicationHelper belongs_to :project,:touch=> true belongs_to :tracker belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' @@ -173,14 +174,18 @@ class Issue < ActiveRecord::Base # 创建issue的时候,issues_count加1 def add_issues_count - issue_count = self.project.issues_count + 1 - self.project.update_attribute(:issues_count, issue_count) + unless self.project.project_score.nil? + issue_count = self.project.project_score.issue_num + 1 + self.project.project_score.update_attribute(:issue_num, issue_count) + end end # 删除issue的时候,issues_count减1 def decrease_issues_count - issue_count = self.project.issues_count - 1 - self.project.update_attribute(:issues_count, issue_count) + unless self.project.project_score.nil? + issue_count = self.project.project_score.issue_num - 1 + self.project.project_score.update_attribute(:issue_num, issue_count) + end end # 更新缺陷 diff --git a/app/models/journal.rb b/app/models/journal.rb index 62f0d1d69..88b71d9ff 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -225,9 +225,9 @@ class Journal < ActiveRecord::Base # issue留言总数更新 def add_journals_count - unless self.issue.project.nil? && self.journalized_type == "Issue" + if !self.issue.project.nil? && self.journalized_type == "Issue" && self.issue.project.project_score.nil? project = self.issue.project - project.update_attribute(:journals_count, project.journals_count + 1) + project.project_score.update_attribute(:issue_journal_num, project.project_score.journals_count + 1) end end end diff --git a/app/models/message.rb b/app/models/message.rb index 2a83011f1..618fb4659 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -36,7 +36,6 @@ class Message < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy - has_many :user_acts, :class_name => 'UserActivity',:as =>:user_act ,:dependent => :destroy # end # 课程/项目 消息 @@ -129,14 +128,32 @@ class Message < ActiveRecord::Base # 发帖精辟更新发帖总数 def add_boards_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) + unless self.project.project_score.nil? + if self.project + # 讨论区 + if self.parent_id.nil? + count = self.project.project_score.board_num + 1 + self.project.project_score.update_attribute(:board_num, count) + else # 回复 + count = self.project.project_score.board_message_num + 1 + self.project.project_score.update_attribute(:board_message_num, count) + end + end + end + end + + # 删除帖子的时候更新帖子总数, 删除回复的时候总数不减少 + def decrease_boards_count + unless self.project.project_score.nil? + if self.project && self.parent_id.nil? + # 讨论区 + if self.parent_id.nil? + count = self.project.project_score.board_num - 1 + self.project.project_score.update_attribute(:board_num, count) + else # 回复 + count = self.project.project_score.board_message_num - 1 + self.project.project_score.update_attribute(:board_message_num, count) + end end end end @@ -326,20 +343,6 @@ class Message < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end - # 删除帖子的时候更新帖子总数, 删除回复的时候总数不减少 - def decrease_boards_count - if self.project && self.parent_id.nil? - # 讨论区 - 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 - # 课程成员得分(英雄榜) def act_as_student_score if self.course diff --git a/app/models/news.rb b/app/models/news.rb index 4903003e8..7c44f7e8a 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -116,9 +116,16 @@ class News < ActiveRecord::Base private def add_news_count - if self.project - count = self.project.news_count + 1 - self.project.update_attribute(:news_count, count) + if self.project && !self.project.project_score.nil? + count = self.project.project_score.news_num + 1 + self.project.project_score.update_attribute(:news_num, count) + end + end + + def decrease_news_count + if self.project && !self.project.project_score.nil? + count = self.project.project_score.news_num - 1 + self.project.project_score.update_attribute(:news_num, count) end end @@ -176,13 +183,6 @@ class News < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::NEWS end - def decrease_news_count - if self.project - count = self.project.news_count - 1 - self.project.update_attribute(:news_count, count) - end - end - def send_mail Mailer.run.news_added(self) if Setting.notified_events.include?('news_added') end diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index 75db910c3..5aa3c1dab 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -1,6 +1,7 @@ class OrgDocumentComment < ActiveRecord::Base attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked include Redmine::SafeAttributes + include ApplicationHelper belongs_to :organization belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' has_many :editor_of_documents, :dependent => :destroy diff --git a/app/models/poll.rb b/app/models/poll.rb index 41bfe8a72..b0499b572 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -1,7 +1,8 @@ class Poll < ActiveRecord::Base #attr_accessible :closed_at, :polls_group_id, :polls_name, :polls_status, :polls_type, :published_at, :user_id include Redmine::SafeAttributes - + include ApplicationHelper + belongs_to :user has_many :poll_questions, :dependent => :destroy,:order => "#{PollQuestion.table_name}.question_number" has_many :poll_users, :dependent => :destroy diff --git a/app/models/project.rb b/app/models/project.rb index f17124478..32677143d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -155,7 +155,7 @@ class Project < ActiveRecord::Base # 创建project之后默认创建一个board,之后的board去掉了board的概念 after_create :create_board_sync,:acts_as_forge_activities,:create_project_ealasticsearch_index before_destroy :delete_all_members,:delete_project_ealasticsearch_index - # after_update :update_project_ealasticsearch_index + after_update :update_project_ealasticsearch_index def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -1223,26 +1223,27 @@ class Project < ActiveRecord::Base self.__elasticsearch__.index_document end end - # def update_project_ealasticsearch_index - # if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 - # begin - # self.__elasticsearch__.update_document - # rescue => e - # self.__elasticsearch__.index_document - # end - # else #如果是更新成为私有的,那么索引就要被删除 - # begin - # self.__elasticsearch__.delete_document - # rescue => e - # - # end - # end - # end + + def update_project_ealasticsearch_index + if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 + begin + self.__elasticsearch__.update_document + rescue => e + self.__elasticsearch__.index_document + end + else #如果是更新成为私有的,那么索引就要被删除 + begin + self.__elasticsearch__.delete_document + rescue => e + + end + end + end + def delete_project_ealasticsearch_index begin self.__elasticsearch__.delete_document rescue => e - end end diff --git a/app/views/layouts/_project_info.html.erb b/app/views/layouts/_project_info.html.erb index 51758ea4c..60fc6f96d 100644 --- a/app/views/layouts/_project_info.html.erb +++ b/app/views/layouts/_project_info.html.erb @@ -1,92 +1,99 @@ -<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% teacher_num = searchTeacherAndAssistant(@course).count %> -<% student_num = studentCount(@course) %> -<% course_file_num = visable_attachemnts_incourse(@course).count%> - -
<%= @course.is_public == 0 ? "私有课程" : "公开课程" %>
-
-ID:<%= @course.id%> -
- -
- - - - - - - - - - - - - - - - - - - - -
- -
- - <%= @course.name %> - - <%# if @course.is_public == 0%> - - - <%# end %> - - <%if User.current && @course.tea_id == User.current.id && (@course.outline == 0 || BlogComment.where(:id=>@course.outline).count == 0) %> - - <% elsif User.current && @course.tea_id == User.current.id && @course.outline != 0 && BlogComment.where(:id=>@course.outline).count != 0%> - - <% elsif User.current && @course.tea_id != User.current.id && !@course.is_public? && User.current.member_of_course?(@course) && @course.outline != 0%> - - <% elsif User.current && @course.tea_id != User.current.id && @course.is_public? && @course.outline != 0%> - - <%else%> - <%end %> - -
-
-
-
-<%= l(:label_account_identity_teacher)%>(<%= course_teacher_link teacher_num %>) - -<%= l(:label_account_identity_student)%>(<%= course_student_link student_num %>) - -<%= l(:project_module_attachments)%>(<%= link_to course_file_num, course_files_path(@course), :class => 'info_foot_num c_blue',:id=>'courses_files_count_info' %>)
-
-<% if is_teacher %> -
- -
-<% end %> +<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> +<% teacher_num = searchTeacherAndAssistant(@course).count %> +<% student_num = studentCount(@course) %> +<% course_file_num = visable_attachemnts_incourse(@course).count%> + +
<%= @course.is_public == 0 ? "私有课程" : "公开课程" %> + <% if @course.id == 370 %> + 精品课程 + <% end %> +
+
+ID:<%= @course.id%> +
+ +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+ + <%= @course.name %> + + <%# if @course.is_public == 0%> + + + <%# end %> + + <%if User.current && @course.tea_id == User.current.id && (@course.outline == 0 || BlogComment.where(:id=>@course.outline).count == 0) %> + + <% elsif User.current && @course.tea_id == User.current.id && @course.outline != 0 && BlogComment.where(:id=>@course.outline).count != 0%> + + <% elsif User.current && @course.tea_id != User.current.id && !@course.is_public? && User.current.member_of_course?(@course) && @course.outline != 0%> + + <% elsif User.current && @course.tea_id != User.current.id && @course.is_public? && @course.outline != 0%> + + <%else%> + <%end %> + +
+
+
+
+<%= l(:label_account_identity_teacher)%>(<%= course_teacher_link teacher_num %>) + +<%= l(:label_account_identity_student)%>(<%= course_student_link student_num %>) + +<%= l(:project_module_attachments)%>(<%= link_to course_file_num, course_files_path(@course), :class => 'info_foot_num c_blue',:id=>'courses_files_count_info' %>)
+
+<% if is_teacher %> +
+ +
+<% end %> diff --git a/app/views/layouts/base_projects.html.erb b/app/views/layouts/base_projects.html.erb index 8ecc6fb54..58289b352 100644 --- a/app/views/layouts/base_projects.html.erb +++ b/app/views/layouts/base_projects.html.erb @@ -76,9 +76,9 @@
<% if @project.project_type == 0 %> - <% unless static_project_score(@project) == 0 %> + <% unless static_project_score(@project.project_score) == 0 %> <%= l(:label_project_score)%> : - <%= link_to(format("%.2f" ,static_project_score(@project) ).to_i, + <%= link_to(format("%.2f" ,static_project_score(@project.project_score)).to_i, {:controller => 'projects', :action => 'show_projects_score', :remote => true, @@ -95,8 +95,8 @@ <% unless @project.enabled_modules.where("name = 'files'").empty? %> <%= l(:project_module_attachments) %>( - <% @project.attachments_count %> - <%= link_to "#{@project.attachments_count}", project_files_path(@project), :class => 'info_foot_num c_blue', :id=>'project_files_count_info' %>) + <% @project.project_score.attach_num %> + <%= link_to "#{@project.project_score.attach_num }", project_files_path(@project), :class => 'info_foot_num c_blue', :id=>'project_files_count_info' %>) <% end %>
diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb index 4f2a7b662..4245be9eb 100644 --- a/app/views/organizations/_org_course_homework.html.erb +++ b/app/views/organizations/_org_course_homework.html.erb @@ -173,7 +173,7 @@ <% time=project.updated_on %> <% time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last %>

<%=(User.find project.user_id).show_name %>(组长)

-

<%=time_from_now time %>

+

<%=time_from_now time %>  <%= project.commits_count %>提交

项目名称:<%=project.name %>
创建者:<%=(User.find project.user_id).show_name %>(组长)
diff --git a/app/views/organizations/_project_create.html.erb b/app/views/organizations/_project_create.html.erb index 3b35838a7..6b45a2a13 100644 --- a/app/views/organizations/_project_create.html.erb +++ b/app/views/organizations/_project_create.html.erb @@ -23,7 +23,7 @@ 创建时间:<%= format_time(project.created_on) %>
- 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> + 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='ProjectCreateInfo' and forge_act_id =#{project.id}").first.updated_at) %>