|
|
@ -62,13 +62,24 @@ class BoardsController < ApplicationController
|
|
|
|
else
|
|
|
|
else
|
|
|
|
render_403
|
|
|
|
render_403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def show
|
|
|
|
def show
|
|
|
|
# 讨论区消息状态更新(已读和未读)
|
|
|
|
# 讨论区消息状态更新(已读和未读)
|
|
|
|
|
|
|
|
@order, @b_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#确定 sort_type 1升序 2 降序
|
|
|
|
|
|
|
|
if @order.to_i == @type.to_i
|
|
|
|
|
|
|
|
@b_sort = @b_sort.to_i == 1 ? 2 : 1
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@b_sort = 2
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort_name = "updated_at"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sort_type = @b_sort == 1 ? "asc" : "desc"
|
|
|
|
|
|
|
|
|
|
|
|
if @project
|
|
|
|
if @project
|
|
|
|
ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
|
|
|
|
ForgeMessage.where("user_id =? and project_id =? and viewed =?", User.current.id, @project.id, 0).update_all(:viewed => true)
|
|
|
|
# 更新@消息为已读
|
|
|
|
# 更新@消息为已读
|
|
|
@ -82,10 +93,10 @@ class BoardsController < ApplicationController
|
|
|
|
CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
|
|
|
|
CourseMessage.where("user_id =? and course_id =? and viewed =?", User.current.id, @course.id, 0).update_all(:viewed => true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
sort_init 'updated_on', 'desc'
|
|
|
|
# sort_init 'updated_on', 'desc'
|
|
|
|
sort_update 'created_on' => "#{Message.table_name}.created_on",
|
|
|
|
# sort_update 'created_on' => "#{Message.table_name}.created_on",
|
|
|
|
'replies' => "#{Message.table_name}.replies_count",
|
|
|
|
# 'replies' => "#{Message.table_name}.replies_count",
|
|
|
|
'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
|
|
|
# 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
|
|
|
|
|
|
|
|
|
|
|
|
@is_new = params[:is_new]
|
|
|
|
@is_new = params[:is_new]
|
|
|
|
@topic_count = @board ? @board.topics.count : 0
|
|
|
|
@topic_count = @board ? @board.topics.count : 0
|
|
|
@ -93,26 +104,31 @@ class BoardsController < ApplicationController
|
|
|
|
if @board
|
|
|
|
if @board
|
|
|
|
limit = 10;
|
|
|
|
limit = 10;
|
|
|
|
@topic_count = @board.topics.count();
|
|
|
|
@topic_count = @board.topics.count();
|
|
|
|
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
|
|
|
@topic_pages = 0#(params[:page] ? params[:page].to_i + 1 : 0) *10
|
|
|
|
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
|
|
|
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").
|
|
|
|
limit(limit).offset(@topic_pages).includes(:last_reply).
|
|
|
|
offset(@topic_pages).includes(:last_reply).
|
|
|
|
preload(:author, {:last_reply => :author}).all();
|
|
|
|
preload(:author, {:last_reply => :author}).all();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@topics = [];
|
|
|
|
@topics = [];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif @course
|
|
|
|
elsif @course
|
|
|
|
if (@board)
|
|
|
|
if (@board)
|
|
|
|
limit = 10;
|
|
|
|
|
|
|
|
@topic_count = @board.topics.count();
|
|
|
|
@topic_count = @board.topics.count();
|
|
|
|
@topic_pages = (params[:page] ? params[:page].to_i + 1 : 0) *10
|
|
|
|
@topic_pages = 0 #(params[:page] ? params[:page].to_i + 1 : 0) *10
|
|
|
|
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) desc").
|
|
|
|
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
|
|
|
|
limit(limit).offset(@topic_pages).includes(:last_reply).
|
|
|
|
|
|
|
|
preload(:author, {:last_reply => :author}).all();
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
@topics = [];
|
|
|
|
@topics = [];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#分页
|
|
|
|
|
|
|
|
@limit = 10
|
|
|
|
|
|
|
|
@is_remote = true
|
|
|
|
|
|
|
|
@atta_count = @topics.count
|
|
|
|
|
|
|
|
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
|
|
|
|
|
|
|
|
@offset ||= @atta_pages.offset
|
|
|
|
|
|
|
|
@topics = paginateHelper @topics,@limit
|
|
|
|
|
|
|
|
|
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
|
@page = params[:page] ? params[:page].to_i + 1 : 0
|
|
|
|
@message = Message.new(:board => @board)
|
|
|
|
@message = Message.new(:board => @board)
|
|
|
|
#modify by nwb
|
|
|
|
#modify by nwb
|
|
|
|