帖子详情页面的优化

This commit is contained in:
cxt 2016-09-23 16:44:49 +08:00
parent caf5602389
commit 70042fe91f
19 changed files with 68 additions and 42 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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',

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -93,10 +93,10 @@
</span>
</div>
</div>
<% all_comments = []%>
<% comments = get_all_children(all_comments, @topic) %>
<%# all_comments = []%>
<%# comments = get_all_children(all_comments, @topic) %>
<div class="" id="reply_div_<%= @topic.id %>">
<% comments.each_with_index do |reply,i| %>
<% @replies.each do |reply| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_message_description_<%= reply.id %>');

View File

@ -127,10 +127,10 @@
</div>
<div class="homepagePostReplyBannerTime"></div>
</div>
<% all_comments = [] %>
<% comments = get_all_children(all_comments, @topic) %>
<%# all_comments = [] %>
<%# comments = get_all_children(all_comments, @topic) %>
<div class="" id="reply_div_<%= @topic.id %>">
<% comments.each_with_index do |reply, i| %>
<% @replies.each_with_index do |reply, i| %>
<script type="text/javascript">
$(function () {
showNormalImage('reply_message_description_<%= reply.id %>');

View File

@ -157,10 +157,10 @@
</span>
</div>
</div>
<% all_comments = []%>
<% comments = get_all_children(all_comments, @topic) %>
<%# all_comments = []%>
<%# comments = get_all_children(all_comments, @topic) %>
<div class="" id="reply_div_<%= @topic.id %>">
<% comments.each_with_index do |reply,i| %>
<% @replies.each_with_index do |reply,i| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_message_description_<%= reply.id %>');

View File

@ -1,13 +1,13 @@
<% if PraiseTread.praised(activity) %>
<a href='<%= praise_tread_praise_plus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type }) %>' data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="点赞" >
<span class="likeText">赞</span>
<% num = get_praise_num(activity) %>
<% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %>
<span class="likeNum"><%= num > 0 ? "#{num}" : "" %></span>
</a>
<% else %>
<a href='<%= praise_tread_praise_minus_path({:obj_id=>activity.id,:obj_type=>activity.class,:user_activity_id=>user_activity_id,:type=>type }) %>' data-remote="true" class="<%=type == 'reply'? 'fr' : 'ml15' %> likeButton" title="取消点赞" >
<span class="likeText">已赞</span>
<% num = get_praise_num(activity) %>
<% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %>
<span class="likeNum"><%= num > 0 ? "#{num}" : "" %></span>
</a>
<% end %>