From 70042fe91fa016cf91f501fdd9416ed124af7aeb Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 23 Sep 2016 16:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 56 +++++++++---------- app/helpers/application_helper.rb | 7 ++- app/models/blog_comment.rb | 2 + app/models/comment.rb | 2 + app/models/contest.rb | 1 + app/models/homework_common.rb | 2 + app/models/issue.rb | 1 + app/models/journal.rb | 2 + app/models/journals_for_message.rb | 2 + app/models/memo.rb | 2 + app/models/message.rb | 1 + app/models/news.rb | 3 + app/models/org_document_comment.rb | 2 + app/models/praise_tread_cache.rb | 3 +- app/models/syllabus.rb | 2 + app/views/messages/_course_show.html.erb | 6 +- .../messages/_org_subfield_show.html.erb | 6 +- app/views/messages/_project_show.html.erb | 6 +- app/views/praise_tread/_praise.html.erb | 4 +- 19 files changed, 68 insertions(+), 42 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 37383712f..5731244c3 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -38,47 +38,45 @@ class MessagesController < ApplicationController # Show a topic and its replies def show @isReply = true - page = params[:page] - # Find the page of the requested reply - if params[:r] && page.nil? - offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) - page = 1 + offset / REPLIES_PER_PAGE - end + # page = params[:page] + # # Find the page of the requested reply + # if params[:r] && page.nil? + # offset = @topic.children.count(:conditions => ["#{Message.table_name}.id < ?", params[:r].to_i]) + # page = 1 + offset / REPLIES_PER_PAGE + # end all_comments = [] - @reply_count = get_all_children(all_comments, @topic).count + @replies = get_all_children(all_comments, @topic) + @reply_count = @replies.count @reply = Message.new(:subject => "RE: #{@message.subject}") if @course - messages_replies = @topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC"). + #@replies = @topic.children. + #includes(:author, :attachments, :praise_tread_cache, {:board => :project}). + #reorder("#{Message.table_name}.created_on DESC"). #limit(@reply_pages.per_page). #offset(@reply_pages.offset). - all - @replies = paginateHelper messages_replies,10 - @reply = Message.new(:subject => "RE: #{@message.subject}") + #all + #@replies = paginateHelper messages_replies,10 @left_nav_type = 2 render :action => "show", :layout => "base_courses"#by young elsif @project - @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - @replies = @topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC"). - limit(@reply_pages.per_page). - offset(@reply_pages.offset). - all + #@reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + # @replies = @topic.children. + # includes(:author, :attachments, {:board => :project}). + # reorder("#{Message.table_name}.created_on DESC"). + # limit(@reply_pages.per_page). + # offset(@reply_pages.offset). + # all - @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_projects"#by young else - @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page - @replies = @topic.children. - includes(:author, :attachments, {:board => :project}). - reorder("#{Message.table_name}.created_on DESC"). - limit(@reply_pages.per_page). - offset(@reply_pages.offset). - all + # @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + # @replies = @topic.children. + # includes(:author, :attachments, {:board => :project}). + # reorder("#{Message.table_name}.created_on DESC"). + # limit(@reply_pages.per_page). + # offset(@reply_pages.offset). + # all - @reply = Message.new(:subject => "RE: #{@message.subject}") @organization = @org_subfield.organization render :action => "show", :layout => "base_org"#by young end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8b5b594bd..511266ba1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -3246,7 +3246,12 @@ end #获取所有子节点 def get_all_children result, jour - if (jour.kind_of? JournalsForMessage) || (jour.kind_of? Message) || (jour.kind_of? BlogComment) || (jour.kind_of? OrgDocumentComment) + if jour.kind_of? JournalsForMessage + jour.children.includes(:author, :praise_tread_cache).each do |jour_child| + result << jour_child + get_all_children result, jour_child + end + elsif (jour.kind_of? Message) || (jour.kind_of? BlogComment) || (jour.kind_of? OrgDocumentComment) jour.children.each do |jour_child| result << jour_child get_all_children result, jour_child diff --git a/app/models/blog_comment.rb b/app/models/blog_comment.rb index 8959e9c29..6290840a3 100644 --- a/app/models/blog_comment.rb +++ b/app/models/blog_comment.rb @@ -12,6 +12,8 @@ class BlogComment < ActiveRecord::Base belongs_to :last_reply, :class_name => 'BlogComment', :foreign_key => 'last_comment_id' # 虚拟关联 has_many :user_acts, :class_name => 'UserAcivity',:as =>:act + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy acts_as_watchable validates_presence_of :title, :content diff --git a/app/models/comment.rb b/app/models/comment.rb index 633c9a825..27a917b93 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -27,6 +27,8 @@ class Comment < ActiveRecord::Base has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy #end + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy acts_as_event :datetime => :updated_on, :description => :comments, :type => 'news', diff --git a/app/models/contest.rb b/app/models/contest.rb index 650e363a8..4fbd5441e 100644 --- a/app/models/contest.rb +++ b/app/models/contest.rb @@ -13,6 +13,7 @@ class Contest < ActiveRecord::Base has_many :join_in_competitions, foreign_key: 'competition_id', :dependent => :destroy has_many :join_in_contests, class_name: 'JoinInCompetition', foreign_key: 'competition_id', :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :contestnotifications, :dependent => :destroy, :include => :author diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 7a082cecf..dfff273a0 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -19,6 +19,8 @@ class HomeworkCommon < ActiveRecord::Base has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :apply_homeworks, :dependent => :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy diff --git a/app/models/issue.rb b/app/models/issue.rb index 222a4f4e2..9c3c8d168 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -53,6 +53,7 @@ class Issue < ActiveRecord::Base has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy # end has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy # ForgeMessage虚拟关联(多态) has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy diff --git a/app/models/journal.rb b/app/models/journal.rb index f22015f47..f14484a31 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -35,6 +35,8 @@ class Journal < ActiveRecord::Base # 被ForgeMessage虚拟关联 has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy has_many :at_messages, as: :at_message, dependent: :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy acts_as_attachable attr_accessor :indice acts_as_tree :counter_cache => :comments_count, :order => "#{Journal.table_name}.created_on ASC" diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 68cb9da15..30d8120ef 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -68,6 +68,8 @@ class JournalsForMessage < ActiveRecord::Base has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy has_many :at_messages, as: :at_message, dependent: :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy validates :notes, presence: true, if: :is_homework_jour? after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, diff --git a/app/models/memo.rb b/app/models/memo.rb index ee9f4c8db..793d534d4 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -48,6 +48,8 @@ class Memo < ActiveRecord::Base acts_as_attachable has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + # 消息 has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy # end diff --git a/app/models/message.rb b/app/models/message.rb index 14add0d02..3192907fe 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -26,6 +26,7 @@ class Message < ActiveRecord::Base belongs_to :board,:touch => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy # has_many :org_subfield_messages, :dependent => :destroy # has_many :org_subfields, :through => :org_subfield_messages diff --git a/app/models/news.rb b/app/models/news.rb index 58bbc40ac..0a893e34e 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -40,6 +40,9 @@ class News < ActiveRecord::Base has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy #end + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + #转发表 has_many :forwards, :as => :from, :dependent => :destroy diff --git a/app/models/org_document_comment.rb b/app/models/org_document_comment.rb index dd7734a54..a87fe783f 100644 --- a/app/models/org_document_comment.rb +++ b/app/models/org_document_comment.rb @@ -6,6 +6,8 @@ class OrgDocumentComment < ActiveRecord::Base belongs_to :organization belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id' has_many :editor_of_documents, :dependent => :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc" acts_as_attachable has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy diff --git a/app/models/praise_tread_cache.rb b/app/models/praise_tread_cache.rb index 739b45876..27f4104fc 100644 --- a/app/models/praise_tread_cache.rb +++ b/app/models/praise_tread_cache.rb @@ -1,6 +1,7 @@ class PraiseTreadCache < ActiveRecord::Base attr_accessible :object_id,:object_type,:praise_num,:tread_num - + belongs_to :object, :polymorphic => true + def plus(flag,num) case flag when 0 diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 0c23c1b13..f72463503 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -10,6 +10,8 @@ class Syllabus < ActiveRecord::Base has_many :courses has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :syllabus_members, :dependent => :destroy + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy attr_accessible :description, :user_id, :title, :eng_name, :syllabus_type, :credit, :hours, :theory_hours, :practice_hours, :applicable_major, :pre_course safe_attributes 'title','user', 'description', 'eng_name', 'syllabus_type', 'credit', 'hours', 'theory_hours', 'practice_hours', 'credit', 'applicable_major', 'pre_course' diff --git a/app/views/messages/_course_show.html.erb b/app/views/messages/_course_show.html.erb index 95c9b7df1..abdeef255 100644 --- a/app/views/messages/_course_show.html.erb +++ b/app/views/messages/_course_show.html.erb @@ -93,10 +93,10 @@ - <% all_comments = []%> - <% comments = get_all_children(all_comments, @topic) %> + <%# all_comments = []%> + <%# comments = get_all_children(all_comments, @topic) %>
- <% comments.each_with_index do |reply,i| %> + <% @replies.each do |reply| %>