diff --git a/app/assets/javascripts/subfield_subdomain_dirs.js.coffee b/app/assets/javascripts/subfield_subdomain_dirs.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/subfield_subdomain_dirs.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/subfield_subdomain_dirs.css.scss b/app/assets/stylesheets/subfield_subdomain_dirs.css.scss new file mode 100644 index 000000000..6843d92f8 --- /dev/null +++ b/app/assets/stylesheets/subfield_subdomain_dirs.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the subfield_subdomain_dirs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 9e7309646..25e731754 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -53,6 +53,7 @@ class AtController < ApplicationController end def find_project(id) + return [] if id<0 at_persons = Project.find(id).users at_persons.delete_if { |u| u.id == User.current.id } end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 70a0b76b8..c4932b1b2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -17,8 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class FilesController < ApplicationController - - layout 'base_projects' #by young + layout 'base_projects' #by young menu_item :files before_filter :auth_login1, :only => [:index] @@ -173,6 +172,7 @@ class FilesController < ApplicationController # #render 'stores' # redirect_to search_course_files_url end + @page = params[:page] || 1 end def find_course_attache keywords,course,sort = "" @@ -381,6 +381,7 @@ class FilesController < ApplicationController @organization = Organization.find(@containers.first.organization_id) show_attachments @containers @tag_list = attachment_tag_list @all_attachments + @page = params[:page] || 1 render :layout => 'base_org' # @subfield = params[:org_subfield_id] end @@ -454,6 +455,11 @@ class FilesController < ApplicationController end end end + # 更新资源总数, 根据上传的附件数累加 + 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' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -482,9 +488,6 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end - # 更新课程英雄榜得分 - update_contributor_score(@course, attachments[:files].first) - # end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type @@ -506,8 +509,9 @@ class FilesController < ApplicationController end end end - - + # 更新课程英雄榜得分 + update_contributor_score(@course, attachments[:files].first) + # end # TODO: 临时用 nyan sort_init 'created_on', 'desc' sort_update 'created_on' => "#{Attachment.table_name}.created_on", @@ -828,5 +832,5 @@ class FilesController < ApplicationController def upload_files_menu - end +end end diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 7685b77a8..f250b46de 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -20,7 +20,12 @@ class OrgDocumentCommentsController < ApplicationController flash.keep[:notice] = l(:notice_successful_create) EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at) if params[:field_id] - redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) + @org_subfield = OrgSubfield.find(params[:field_id]) + if @org_subfield.subfield_subdomain_dir.nil? + redirect_to organization_path(@organization, :org_subfield_id => params[:field_id]) + else + redirect_to show_org_subfield_organization_path(:id => @organization.id, :sub_dir_name => @org_subfield.subfield_subdomain_dir.name) + end else redirect_to organization_org_document_comments_path(@organization) end diff --git a/app/controllers/org_subfields_controller.rb b/app/controllers/org_subfields_controller.rb index 66a236b5b..5850629f0 100644 --- a/app/controllers/org_subfields_controller.rb +++ b/app/controllers/org_subfields_controller.rb @@ -1,22 +1,90 @@ class OrgSubfieldsController < ApplicationController + helper :attachments + layout 'base_org' def create - @subfield = OrgSubfield.create(:name => params[:name]) - @organization = Organization.find(params[:organization_id]) - @organization.org_subfields << @subfield - @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + if OrgSubfield.where("organization_id=#{params[:organization_id]} and name=?",params[:name]).count == 0 + @res = true + @subfield = OrgSubfield.create(:name => params[:name]) + @organization = Organization.find(params[:organization_id]) + @organization.org_subfields << @subfield + if !params[:sub_dir].blank? + sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ + "and org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir]}'" + if SubfieldSubdomainDir.find_by_sql(sql).count == 0 + SubfieldSubdomainDir.create(:org_subfield_id => @subfield.id, :name => params[:sub_dir]) + end + end + @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) + else + @res = false + end end def show - @org_subfield = OrgSubfield.find(params[:id]) - @organization = @org_subfield.organization.id - @messages = [] - @messages << @org_subfield.org_document_comments - @messages << @org_subfield.messages - @messages.sort{|a, b| b.updated_at <=> a.updated_at} - respond_to do |format| - format.html{render :layout => 'base_org'} + @flag = params[:flag] || false + sort = "" + @sort = "" + @order = "" + @is_remote = false + @organization = Organization.find(params[:id]) + @org_subfield = OrgSubfield.find_by_sql("select distinct org_subfields.* from org_subfields,"+ + "subfield_subdomain_dirs where org_subfields.id = subfield_subdomain_dirs.org_subfield_id and "+ + " org_subfields.organization_id=#{@organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'").first + if @org_subfield.field_type == 'Post' + @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 + @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10) + #redirect_to organization_path(@organization, :org_subfield_id => @org_subfield.id) + else + if params[:sort] + params[:sort].split(",").each do |sort_type| + order_by = sort_type.split(":") + case order_by[0] + when "filename" + attribute = "filename" + when "size" + attribute = "filesize" + when "attach_type" + attribute = "attachtype" + when "content_type" + attribute = "created_on" + when "field_file_dense" + attribute = "is_public" + when "downloads" + attribute = "downloads" + when "created_on" + attribute = "created_on" + when "quotes" + attribute = "quotes" + else + attribute = "created_on" + end + @sort = order_by[0] + @order = order_by[1] + if order_by.count == 1 && attribute + sort += "#{Attachment.table_name}.#{attribute} asc " + if sort_type != params[:sort].split(",").last + sort += "," + end + elsif order_by.count == 2 && order_by[1] + sort += "#{Attachment.table_name}.#{attribute} #{order_by[1]} " + if sort_type != params[:sort].split(",").last + sort += "," + end + end + end + else + sort = "#{Attachment.table_name}.created_on desc" + end + @container_type = 2 + @containers = [ OrgSubfield.includes(:attachments).reorder(sort).find(@org_subfield.id)] + @organization = Organization.find(@containers.first.organization_id) + show_attachments @containers + @tag_list = attachment_tag_list @all_attachments end + @page = params[:page] || 1 + #render :layout => 'base_org' end + def destroy @subfield = OrgSubfield.find(params[:id]) @organization = Organization.find(@subfield.organization_id) @@ -29,4 +97,43 @@ class OrgSubfieldsController < ApplicationController @subfield.update_attributes(:name => params[:name]) end + def update_sub_dir + @org_subfield = OrgSubfield.find(params[:id]) + sql = "select subfield_subdomain_dirs.* from subfield_subdomain_dirs, org_subfields where subfield_subdomain_dirs.org_subfield_id = org_subfields.id "+ + "and org_subfields.organization_id=#{@org_subfield.organization.id} and subfield_subdomain_dirs.name='#{params[:sub_dir_name]}'" + if SubfieldSubdomainDir.find_by_sql(sql).count == 0 + if @org_subfield.subfield_subdomain_dir + @sub_dir = @org_subfield.subfield_subdomain_dir + @sub_dir.update_attribute(:name, params[:sub_dir_name]) + else + @sub_dir = SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name]) + end + @exist = false + else + @exist = true + end + end + + def show_attachments obj + @attachments = [] + obj.each do |container| + @attachments += container.attachments + end + @all_attachments = User.current.admin? ? @attachments : visable_attachemnts(@attachments) + @limit = 10 + @feedback_count = @all_attachments.count + @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] + @offset ||= @feedback_pages.offset + #@curse_attachments_all = @all_attachments[@offset, @limit] + @obj_attachments = paginateHelper @all_attachments,10 + end + + #获取指定资源列表的TAG的集合以及每个TAG的数量,降序排序 + def attachment_tag_list attachments + tag_list = Hash.new + attachments.each do |attachment| + attachment.tag_list.map{|tag| tag_list.has_key?(tag) ? tag_list[tag] = tag_list[tag] + 1 : tag_list[tag] = 1} + end + tag_list.sort {|a,b| b[1]<=>a[1]} + end end diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 9f80503d8..25ee3dc48 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -114,7 +114,7 @@ class OrganizationsController < ApplicationController @organization = Organization.find(params[:id]) @organization.name = params[:organization][:name] @organization.description = params[:organization][:description] - @organization.domain = params[:organization][:domain] + # @organization.domain = params[:organization][:domain] @organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0 #@organization.name = params[:organization][:name] @organization.save diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 31c70e92a..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}" @@ -512,6 +519,14 @@ class ProjectsController < ApplicationController def edit end + def set_public_or_private + @project = Project.find(params[:id]) + if @project.is_public? + @project.update_attribute(:is_public, 0) + else + @project.update_attribute(:is_public, 1) + end + end # by young # include CoursesHelper def member diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1674055ac..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}" @@ -344,20 +347,18 @@ update #Modified by young # (show_error_not_found; return) unless @entries g = Gitlab.client - - # count = 0 - # (0..100).each do |page| - # if g.commits(@project.gpid,:page => page).count == 0 - # break - # else - # count = count + g.commits(@project.gpid,:page => page).count - # end - # end - @changesets = g.commits(@project.gpid, :ref_name => @rev) # @changesets = @repository.latest_changesets(@path, @rev) # @changesets_count = @repository.latest_changesets(@path, @rev).count - @changesets_all_count = @project.gpid.nil? ? 0 : g.commits_total_count(@project.gpid).count + @changesets_all_count = @project.gpid.nil? ? 0 : g.project(@project.gpid).commit_count + # 访问该页面的是会后则刷新 + 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 @changesets_latest_coimmit = @changesets[0] @properties = @repository.properties(@path, @rev) @repositories = @project.repositories @@ -583,6 +584,10 @@ update end private + # 更新项目统计数 + def update_commits_count project, count + project.project_score.update_attribute(:changeset_num, count) + end def find_repository @repository = Repository.find(params[:id]) 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/controllers/subfield_subdomain_dirs_controller.rb b/app/controllers/subfield_subdomain_dirs_controller.rb new file mode 100644 index 000000000..90c6a7a92 --- /dev/null +++ b/app/controllers/subfield_subdomain_dirs_controller.rb @@ -0,0 +1,10 @@ +class SubfieldSubdomainDirsController < ApplicationController + def update + @org_subfield = OrgSubfield.find(params[:org_subfield_id]) + if @org_subfield.subfield_subdomain_dir + @org_subfield.subfield_subdomain_dir.update_attribute(:name, :params[:sub_dir_name]) + else + SubfieldSubdomainDir.create(:org_subfield_id => @org_subfield.id, :name => params[:sub_dir_name]) + end + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5b7cca7fe..be9c59992 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.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 + # 获取组织成员中文名字 def get_org_member_role_name member case member.roles[0].name @@ -2784,8 +2790,7 @@ int main(int argc, char** argv){ #代码提交数量 def changesets_num project g = Gitlab.client - project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count - # # commits_total_count(project.gpid) + project.gpid.nil? ? 0 : g.project(project.gpid).commit_count # project.changesets.count end diff --git a/app/helpers/subfield_subdomain_dirs_helper.rb b/app/helpers/subfield_subdomain_dirs_helper.rb new file mode 100644 index 000000000..584de578c --- /dev/null +++ b/app/helpers/subfield_subdomain_dirs_helper.rb @@ -0,0 +1,2 @@ +module SubfieldSubdomainDirsHelper +end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index d90b0368e..3088714ee 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -90,7 +90,7 @@ class Attachment < ActiveRecord::Base before_save :files_to_final_location,:act_as_course_activity after_create :office_conver, :be_user_score,:act_as_forge_activity,:create_attachment_ealasticsearch_index after_update :office_conver, :be_user_score,:update_attachment_ealasticsearch_index - after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index + after_destroy :delete_from_disk,:down_user_score,:delete_attachment_ealasticsearch_index#, :decrease_attchments_count # add by nwb # 获取所有可公开的资源文件列表 @@ -617,6 +617,7 @@ class Attachment < ActiveRecord::Base self.__elasticsearch__.index_document end end + def update_attachment_ealasticsearch_index if self.is_public == 1 && ( ((self.container_type == 'Project' or self.container_type == 'Version') && Project.find(self.container_id).is_public == 1) || ( self.container_type == 'Course' && Course.find(self.container_id).is_public == 1) || @@ -632,12 +633,20 @@ class Attachment < ActiveRecord::Base end end end + def delete_attachment_ealasticsearch_index begin self.__elasticsearch__.delete_document rescue => e end end + + # def decrease_attchments_count + # if self.container_type == "Project" + # count = self.container.attachments_count + # #self.container.update_attribute(:attachments_count, self.container.attachments_count - 1) + # end + # end end # Delete the previous articles index in Elasticsearch 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/issue.rb b/app/models/issue.rb index 4dfa643fa..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' @@ -83,9 +84,9 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message + after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message, :add_issues_count after_update :be_user_score,:update_activity - after_destroy :down_user_score + after_destroy :down_user_score, :decrease_issues_count # after_create :be_user_score # end @@ -132,7 +133,7 @@ class Issue < ActiveRecord::Base update_forge_activity(self.class, self.id) update_org_activity(self.class, self.id) end - + # fq def act_as_activity self.acts << Activity.new(:user_id => self.author_id) @@ -171,6 +172,22 @@ class Issue < ActiveRecord::Base end end + # 创建issue的时候,issues_count加1 + def add_issues_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 + 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 + # 更新缺陷 #def act_as_forge_message_update # unless self.author_id == self.assigned_to_id diff --git a/app/models/journal.rb b/app/models/journal.rb index e1464a703..88b71d9ff 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -48,14 +48,14 @@ class Journal < ActiveRecord::Base :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" + "(#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"} - before_create :split_private_notes + before_create :split_private_notes, :add_journals_count # fq after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message # end #after_destroy :down_user_score #before_save :be_user_score - after_destroy :down_user_score + after_destroy :down_user_score, :decrease_issues_journal_count scope :visible, lambda {|*args| user = args.shift || User.current @@ -214,4 +214,20 @@ class Journal < ActiveRecord::Base end end + + # 减少留言数量统计 + def decrease_issues_journal_count + unless self.issue.project.nil? + project = self.issue.project + project.update_attribute(:journals_count, project.journals_count - 1) + end + end + + # issue留言总数更新 + def add_journals_count + if !self.issue.project.nil? && self.journalized_type == "Issue" && self.issue.project.project_score.nil? + project = self.issue.project + 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 b11b2cc1d..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 # 课程/项目 消息 @@ -76,9 +75,9 @@ class Message < ActiveRecord::Base validates_length_of :subject, :maximum => 255 validate :cannot_reply_to_locked_topic, :on => :create - after_create :add_author_as_watcher, :reset_counters! + after_create :add_author_as_watcher, :reset_counters!, :add_boards_count after_update :update_messages_board, :update_activity - after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets + after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message #before_save :be_user_score @@ -127,6 +126,38 @@ class Message < ActiveRecord::Base end end + # 发帖精辟更新发帖总数 + def add_boards_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 + def reset_counters! if parent && parent.id Message.update_all({:last_reply_id => parent.children.maximum(:id)}, {:id => parent.id}) diff --git a/app/models/news.rb b/app/models/news.rb index e00437fd8..7c44f7e8a 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -55,9 +55,9 @@ class News < ActiveRecord::Base :author_key => :author_id acts_as_watchable - after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail + after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count after_update :update_activity - after_destroy :delete_kindeditor_assets + after_destroy :delete_kindeditor_assets, :decrease_news_count scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -115,10 +115,24 @@ class News < ActiveRecord::Base end private + def add_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 + + 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 def add_author_as_watcher Watcher.create(:watchable => self, :user => author) end + ## fq def act_as_activity self.acts << Activity.new(:user_id => self.author_id) 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/org_subfield.rb b/app/models/org_subfield.rb index 0747114ca..b109ba042 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -1,5 +1,6 @@ class OrgSubfield < ActiveRecord::Base belongs_to :organization, :foreign_key => :organization_id + has_one :subfield_subdomain_dir,:dependent => :destroy has_many :org_document_comments, :dependent => :destroy has_many :files has_many :org_subfield_messages, :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 cd4036810..32677143d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1223,6 +1223,7 @@ class Project < ActiveRecord::Base self.__elasticsearch__.index_document end end + def update_project_ealasticsearch_index if self.is_public #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性 begin @@ -1238,11 +1239,11 @@ class Project < ActiveRecord::Base end end end + def delete_project_ealasticsearch_index begin self.__elasticsearch__.delete_document rescue => e - end end diff --git a/app/models/subfield_subdomain_dir.rb b/app/models/subfield_subdomain_dir.rb new file mode 100644 index 000000000..9897e19ac --- /dev/null +++ b/app/models/subfield_subdomain_dir.rb @@ -0,0 +1,4 @@ +class SubfieldSubdomainDir < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :org_subfield +end diff --git a/app/models/user.rb b/app/models/user.rb index aa048888c..f3367db59 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -409,7 +409,7 @@ class User < Principal def get_at_show_name name = show_name - name = "#{name} #{self.login}" if name != self.login + (name != self.login) ? "#{name} #{self.login}" : name end #added by nie diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index b316aa406..3d07f69b2 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -205,7 +205,7 @@
-
  欢迎加入Trustie高校创新实践社区!老师、学生和科研人员可以在此开展各种在线协同学习、协同作业、协同开发等活动。

  Trustie是在中国推行大规模开放在线研究模式(MOORE)的支撑平台。
+
  欢迎加入Trustie创新实践社区!在这里,您的创新意识和创新潜力将得到充分发挥!目前已有超过200所高校和科研机构在平台中开展在线协同开发、协同学习和协同研究。

  Trustie社区的理想是:让创新过程变的更美好!
diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 0c43d0542..22df4499a 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -26,12 +26,21 @@ ) if User.current && User.current.id == activity.author.id %>
  • - <%= link_to( - l(:button_set_homepage), - {:controller => 'blogs',:action => 'set_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id}, - :method => :post, - :class => 'postOptionLink' - ) if User.current && User.current.id == activity.blog.author_id %> + <% if activity.id == activity.blog.homepage_id %> + <%= link_to( + l(:button_cancel_homepage), + {:controller => 'blogs',:action => 'cancel_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == activity.blog.author_id %> + <% else %> + <%= link_to( + l(:button_set_homepage), + {:controller => 'blogs',:action => 'set_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == activity.blog.author_id %> + <% end %>
  • diff --git a/app/views/blogs/_article_list.html.erb b/app/views/blogs/_article_list.html.erb index 182db9dd0..ca85c0ba2 100644 --- a/app/views/blogs/_article_list.html.erb +++ b/app/views/blogs/_article_list.html.erb @@ -43,11 +43,6 @@
    - <% if blog.homepage_id and BlogComment.where("id=?", blog.homepage_id).count > 0 %> - <% homepage = BlogComment.find(blog.homepage_id) %> - <%= render :partial => 'blogs/homepage', :locals => {:activity => homepage, :user_activity_id => homepage.id} %> - <% end %> - <% if User.current.logged? && User.current.id == @user.id %> <%= labelled_form_for @article, :url =>{:controller=>'blog_comments',:action => 'create',:user_id=>user.id , :blog_id => blog.id}, :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 30e1b69a5..99835c87d 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -36,7 +36,7 @@
    <%end%>
    -