在班级的讨论区列表增加“历史讨论”入口

This commit is contained in:
cxt 2017-05-12 09:56:04 +08:00
parent 552b571762
commit b9311bef94
6 changed files with 133 additions and 18 deletions

View File

@ -229,6 +229,54 @@ class BoardsController < ApplicationController
end
end
def board_history
@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_on"
sort_type = @b_sort == 1 ? "asc" : "desc"
@course = Course.find(params[:course])
syllabus = @course.syllabus
boards = Board.where(:course_id => syllabus.courses.map(&:id))
@topics = Message.where(:board_id => boards.map(&:id), :parent_id => nil).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();
#根据 赞+回复数排序
if @order.to_i == 2
@type = 2
@topics.each do |topic|
all_comments = []
#count=get_all_children(all_comments, topic).count
count=Message.where("root_id = #{topic.id}").count
topic[:infocount] = get_praise_num(topic) + count
if topic[:infocount] < 0
topic[:infocount] = 0
end
end
@b_sort == 1 ? @topics = @topics.sort{|x,y| x[:infocount] <=> y[:infocount] } : @topics = @topics.sort{|x,y| y[:infocount] <=> x[:infocount] }
@topics = sort_by_sticky @topics
@topics = sortby_time_countcommon_hassticky @topics,sort_name
else
@type = 1
end
#分页
@limit = 15
@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
respond_to do |format|
format.js
end
end
def new
@board = @project.boards.build
@board.safe_attributes = params[:board]

View File

@ -0,0 +1,61 @@
<div class="listbox mt10">
<p class="list-h2">历史讨论区列表</p>
<div class="category">
<span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'boards', :action => 'board_history', :course =>@course.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'boards', :action => 'board_history', :course =>@course.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<%= link_to "人气", {:controller => 'boards', :action => 'board_history', :course =>@course.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "sortTxt", :remote => true %>
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'boards', :action => 'board_history', :course =>@course.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<div class="cl"></div>
</div>
<div class="bloglistbox">
<% if @topics.any? %>
<% @topics.each do |activity| %>
<div class="list-file">
<div><span class="item_list fl"></span>
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
<%= link_to activity.subject.to_s.html_safe, User.current.logged? ? board_message_path(activity.board_id, activity) : signin_url_without_domain, :target => '_blank', :class => "list-title-normal fl" %>
<% else %>
<%= link_to activity.parent.subject.to_s.html_safe, User.current.logged? ? board_message_path(activity.board_id, activity) : signin_url_without_domain, :target => '_blank', :class => "list-title-normal f1" %>
<% end %>
<% if activity.sticky == 1 %>
<span class="fl ml10 red-cir-btn">顶</span>
<% end%>
<% if activity.locked %>
<span class="fl ml10 green-cir-btn" title="已锁定">锁</span>
<% end %>
<%# u = User.where("id=?",activity.author_id).first%>
<div class="cl"></div>
</div>
<div class="ml15 mt10">
<span class="grayTxt mr15">
发帖人:<%= link_to activity.author.show_name, user_path(activity.author), :class => "link-blue" %>
</span>
<span class="grayTxt mr15">
班级:<%= link_to activity.board.course.name, course_path(activity.board.course), :class => "link-blue" %>
</span>
<span class="grayTxt">更新:<%= format_time(activity.children.any? ? activity.children.last[:created_on] : activity[:created_on] ) %></span>
<% all_comments = []%>
<% count=Message.where("root_id = #{activity.id}").count %>
<p class="list-info fr grayTxt"><span><%= count>0 ? "#{count}" : "0" %></span><span>回复</span><span>|</span><span><%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %></span><span>赞</span></p>
</div>
<div class="cl"></div>
</div>
<% end %>
<div>
<ul class="wlist" id="pages" >
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
<div class="cl"></div>
</div>
<% else %>
<div class="icons_tishi"><img src="/images/sy/icons_smile.png" width="110" height="110" alt="" ></div>
<p class="sy_tab_con_p">没有数据可以显示!</p>
<% end %>
</div>
</div>

View File

@ -0,0 +1 @@
$("#course-boardlist").html("<%= j(render :partial => 'sy_board_history') %>");

View File

@ -1,7 +1,11 @@
<div class = "cl"> </div>
<div id="course-boardlist">
<div class="listbox mt10" >
<p class="list-h2">讨论区列表</p>
<p class="list-h2">讨论区列表
<% if @board.parent_id.nil? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@board.course)) %>
<%= link_to '历史讨论', boards_board_history_path(:course => @board.course_id), :class => 'link-blue fr f14', :remote => true %>
<% end %>
</p>
<div class="category">
<span class="grayTxt ">排序:</span>
<%= link_to "时间", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "sortTxt", :remote => true %>

View File

@ -662,23 +662,23 @@
<!--:onmouseout => "message_titile_hide($(this))" %>-->
</li>
</div>
<div style="display: none" class="message_title_red system_message_style">
<p>
<%= User.current.lastname + User.current.firstname %>老师您好!您成功创建了一个班级,详情如下:
</p>
<p>班级名称:<%= ma.course_message.name %></p>
<p>开课学期:<%= ma.course_message.time.to_s + '年' + ma.course_message.term %></p>
<p>班级ID<span style="color:red;"><%= ma.course_message.id %></span></p>
<p>班级密码:<span style="color:red;"><%= ma.course_message.password %></span></p>
<p>学时总数:<%= ma.course_message.class_period %></p>
<p>创建时间:<%= format_time(ma.course_message.created_at) %></p>
<p>您可以点击左上角的“配置”按钮,修改班级基本信息,添加及删除班级成员。您也可以把邀请码告诉学生和其他成员,让他们输入邀请码加入班级。</p>
<% if ma.course_message.is_public %>
<p>您的班级是公开的,所有人都能访问您的班级。若不想设置为公开,您可以在配置中设置。</p>
<% else %>
<p>您的班级是私有的,非班级成员不能访问您的班级。如果想设置为公开,您可以在配置中设置。</p>
<% end %>
</div>
<!--<div style="display: none" class="message_title_red system_message_style">-->
<!--<p>-->
<%#= User.current.lastname + User.current.firstname %>老师您好!您成功创建了一个班级,详情如下:
<!--</p>-->
<!--<p>班级名称:<%#= ma.course_message.name %></p>-->
<!--<p>开课学期:<%#= ma.course_message.time.to_s + '年' + ma.course_message.term %></p>-->
<!--<p>班级ID<span style="color:red;"><%#= ma.course_message.id %></span></p>-->
<!--<p>班级密码:<span style="color:red;"><%#= ma.course_message.password %></span></p>-->
<!--<p>学时总数:<%#= ma.course_message.class_period %></p>-->
<!--<p>创建时间:<%#= format_time(ma.course_message.created_at) %></p>-->
<!--<p>您可以点击左上角的“配置”按钮,修改班级基本信息,添加及删除班级成员。您也可以把邀请码告诉学生和其他成员,让他们输入邀请码加入班级。</p>-->
<!--<%# if ma.course_message.is_public %>-->
<!--<p>您的班级是公开的,所有人都能访问您的班级。若不想设置为公开,您可以在配置中设置。</p>-->
<!--<%# else %>-->
<!--<p>您的班级是私有的,非班级成员不能访问您的班级。如果想设置为公开,您可以在配置中设置。</p>-->
<!--<%# end %>-->
<!--</div>-->
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>

View File

@ -551,6 +551,7 @@ RedmineApp::Application.routes.draw do
post 'boards/:board_id/topics/:id/replies', :to => 'messages#reply'
post 'boards/:board_id/topics/:id/edit', :to => 'messages#edit'
post 'boards/:board_id/topics/:id/destroy', :to => 'messages#destroy',:as=>'delete_board_message'
get 'boards/board_history', :to => 'boards#board_history'
match 'messages/join_org_subfield', :to => 'messages#join_org_subfield'
match 'messages/get_subfield_on_click_org', :to => 'messages#get_subfield_on_click_org'
match 'messages/join_org_subfields', :to => 'messages#join_org_subfields'