班级讨论区

This commit is contained in:
cxt 2017-07-26 16:28:34 +08:00
parent 125ab3b3bc
commit 79dca41031
6 changed files with 103 additions and 113 deletions

View File

@ -21,7 +21,7 @@ class BoardsController < ApplicationController
before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields]
before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name, :update_boards_position, :update_boards_name]
accept_rss_auth :index, :show
helper :sort
include SortHelper
@ -146,7 +146,7 @@ class BoardsController < ApplicationController
if (@board)
@topic_count = @board.topics.count();
@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) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.updated_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
else
@board = @contest.boards.build
@board.name = " #{l(:label_board_contest) }"#self.name
@ -156,7 +156,7 @@ class BoardsController < ApplicationController
if @board.save
@topic_count = @board.topics.count();
@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) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
@topics = @board.topics.reorder("#{Message.table_name}.sticky DESC, COALESCE(last_replies_messages.created_on, #{Message.table_name}.updated_on) #{sort_type}").offset(@topic_pages).includes(:last_reply).preload(:author, {:last_reply => :author}).all();
else
@topics = []
end
@ -183,7 +183,7 @@ class BoardsController < ApplicationController
end
#分页
@limit = 1
@limit = 10
@is_remote = true
@atta_count = @topics.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@ -370,16 +370,16 @@ class BoardsController < ApplicationController
end
def update_boards_name
@board.update_attribute("name", params[:name])
@board.update_attribute("description", params[:name])
@board.update_attribute("name", params[:name])
@board.update_attribute("description", params[:name])
@course_board = @course.boards.where("parent_id is NULL").first
@board = @course_board.children.order("position asc")
@board_count = @board.count
@course_board = @course.boards.where("parent_id is NULL").first
@board = @course_board.children.order("position asc")
@board_count = @board.count
respond_to do |format|
format.js
end
respond_to do |format|
format.js
end
end
def join_to_org_subfields
@ -392,7 +392,7 @@ class BoardsController < ApplicationController
end
end
private
private
def redirect_to_settings_in_projects
redirect_to settings_project_url(@project, :tab => 'boards')
end

View File

@ -61,16 +61,16 @@ class MessagesController < ApplicationController
course_messages = CourseMessage.where("user_id =? and course_message_type =? and course_message_id =? and course_id =? and viewed =?", User.current.id, 'Message', @topic.id, @course.id, 0)
course_messages.update_all(:viewed => true)
#@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
#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
# 班级帖子回复消息设为已读
@replies.each do |comment|
course_message = CourseMessage.where(:course_message_type => 'Message', :course_message_id => comment.id, :user_id => User.current.id, :viewed => 0)
course_message.update_all(:viewed => 1)
course_message = CourseMessage.where(:course_message_type => 'Message', :course_message_id => comment.id, :user_id => User.current.id, :viewed => 0)
course_message.update_all(:viewed => 1)
end
@left_nav_type = 2
respond_to do |format|
@ -133,6 +133,10 @@ class MessagesController < ApplicationController
# Create a new topic
def new
end
def create
if User.current.logged?
@message = Message.new
@message.author = User.current
@ -437,8 +441,8 @@ class MessagesController < ApplicationController
:created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky)
@message.attachments.each do |attach|
mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest,
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
:is_public => attach.is_public, :quotes => 0)
:downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype,
:is_public => attach.is_public, :quotes => 0)
end
# OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type)
# org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)

View File

@ -1,60 +1,58 @@
<% if false %>
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_topic(){
$("#message_subject").val("");
$("#subjectmsg").text("");
if(document.getElementById("message_sticky") && document.getElementById("message_locked")){
document.getElementById("message_sticky").checked=false;
document.getElementById("message_locked").checked=false;
<script type="text/javascript">
$(function(){
$("#RSide").removeAttr("id");
$("#Container").css("width","1000px");
});
function reset_topic(){
$("#message_subject").val("");
$("#subjectmsg").text("");
if(document.getElementById("message_sticky") && document.getElementById("message_locked")){
document.getElementById("message_sticky").checked=false;
document.getElementById("message_locked").checked=false;
}
$("#topic_attachments").html("<%= escape_javascript(render :partial => 'attachments/form_course', :locals => {:container => Message.new, :isReply => @isReply})%>");
message_content_editor.html("");
$("#topic_editor").toggle();
}
$("#topic_attachments").html("<%= escape_javascript(render :partial => 'attachments/form_course', :locals => {:container => Message.new, :isReply => @isReply})%>");
message_content_editor.html("");
$("#topic_editor").toggle();
}
<% if @is_new%>
$(function(){
$("#message_subject").focus();
});
<%end%>
</script>
<% if @is_new%>
$(function(){
$("#message_subject").focus();
});
<%end%>
</script>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName break_word" style="width: 600px;">
<%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner">
<div class="NewsBannerName break_word" style="width: 600px;">
<%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
</div>
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@board.course)) %>
<% if is_teacher %>
<%= link_to "添加子栏目", settings_course_path(@board.course.id,'boards'), :class => "link-blue fr mt5" %>
<% end %>
</div>
<div nhname="topic_form">
<% if User.current.logged? %>
<%= labelled_form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'},
:html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'course_new', :locals => {:f => f, :topic => @message, :edit_mode => false, :course => @board.course} %>
<% end %>
<% end %>
</div>
<%= render :partial=> 'course_show_detail',:locals =>{:topics => @topics, :page => 0} %>
</div>
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@board.course)) %>
<% if is_teacher %>
<%= link_to "添加子栏目", settings_course_path(@board.course.id,'boards'), :class => "link-blue fr mt5" %>
<% end %>
</div>
<div nhname="topic_form">
<% if User.current.logged? %>
<%= labelled_form_for @message, :url =>{:controller=>'messages',:action => 'new', :board_id => @board.id, :is_board => 'true'},
:html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %>
<%= render :partial => 'course_new', :locals => {:f => f, :topic => @message, :edit_mode => false, :course => @board.course} %>
<% end %>
<% end %>
</div>
<%= render :partial=> 'course_show_detail',:locals =>{:topics => @topics, :page => 0} %>
</div>
<% end %>
<div class="homepageRight mt0 ml10">
<div class="homepageRightBanner user_bg_shadow clearfix">
<p class="color-grey fl font-16">全部帖子</p><span class="btn-cir btn-cir-grey ml5 mt5 fl"><%= @topics.count %></span>
<a href="<%= new_disscuss_shixuns_path %>" class=" task-btn task-btn-green fr">我要发布</a>
</div>
<div id="course-boardlist_new">
<%= render :partial => "course_show_detail", :locals => {:topics => @topics, :page => 0} %>
<div class="with85 fl">
<div class="ml15 user_bg_shadow">
<div class="homepageRightBanner user_bg_shadow clearfix">
<p class="color-grey fl font-16">全部帖子</p><span class="btn-cir btn-cir-grey ml5 mt5 fl"><%= @topics.count %></span>
<a href="<%= new_board_message_path(:board_id => @board.id) %>" class=" task-btn task-btn-green fr">我要发布</a>
</div>
<div id="course-boardlist_new">
<%= render :partial => "course_show_detail", :locals => {:topics => @topics, :page => 0} %>
</div>
</div>
</div>

View File

@ -3,8 +3,8 @@
<%= javascript_include_tag "create_kindeditor" %>
<% end %>
<% if @topics %>
<%= render :partial => 'users/course_boardlist', :locals => {:topics => @topics ? @topics: topics , :is_course => 1, :is_board=>1} %>
<% if @topics.count > 0 %>
<%= render :partial => 'users/course_boardlist', :locals => {:topics => @topics, :is_course => 1, :is_board=>1} %>
<% else %>
<%= render :partial => "welcome/no_data" %>
<% end %>

View File

@ -1,13 +1,7 @@
<p class=" panel-bg-grey clearfix">
<%= link_to "时间", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "link-color-grey fr mr15", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<span class=" mr5 ml5 fr">|</span>
<%= link_to "人气", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "link-color-grey fr", :remote => true %>
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 2 }, :class => "#{@b_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %>
<% end %>
<p class="panel-bg-grey clearfix">
<%= link_to "热度排序", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 2}, :class => "#{@order.to_i == 2 ? 'link-color-green' : 'link-color-grey'} fr mr15", :remote => true %>
<span class="mr5 ml5 fr">|</span>
<%= link_to "时间排序", {:controller => 'boards', :action => 'index', :board_id =>@board.id, :type => @type, :sort => @b_sort, :order => 1}, :class => "#{@order.to_i == 1 ? 'link-color-green' : 'link-color-grey'} fr", :remote => true %>
<!--<a href="#" class="link-color-grey fr mr15">热度排序 </a>-->
<!--<span class=" mr5 ml5 fr">|</span>-->
@ -28,16 +22,17 @@
<%= link_to activity.parent.subject.to_s.html_safe, User.current.logged? ? board_message_path(activity.board_id, activity) : signin_url_without_domain, :class => "panel-list-title hide fl" %>
<% end %>
</h6>
<!--<a href="#" class="panel-list-title hide fl">开启实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?</a>-->
<% if activity.sticky == 1 %>
<span class="btn-cir btn-cir-red fl mt5 ml5">顶</span>
<% end %>
<!--<span class="btn-cir btn-cir-red fl mt5 ml5">置顶</span></h6>-->
<!--<a href="#" class="panel-list-title hide fl">开启实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?实训就训”就是参加实训吗?</a>-->
<% if activity.sticky == 1 %>
<span class="btn-cir btn-cir-red fl mt5 ml5">顶</span>
<% end %>
<!--<span class="btn-cir btn-cir-red fl mt5 ml5">置顶</span></h6>-->
<div class="cl"></div>
<p class=" color-grey panel-lightgrey ">
<p class=" color-grey panel-lightgrey">
<%= %>
<a href="#" class="panel-name-small hide fl mr15"><%= activity.author.try(:identity) %></a>
<span class=" fl mr15">发表于<%= time_from_now activity.created_on %></span>
<span class=" fl mr15">更新于<%= time_from_now activity.updated_on %></span>
<span class="fl mr15">发表于<%= time_from_now activity.created_on %></span>
<span class="fl mr15">更新于<%= time_from_now activity.updated_on %></span>
<%= link_to activity.author.show_real_name, user_path(activity.author), :class => "panel-name-small hide fl mr15 ml10" %>
<% count = Message.where("root_id = #{activity.id}").count %>
<% if count >0 %>
@ -62,24 +57,17 @@
</div>
</div>
<!--<div style="text-align:center;" class="new_expand">-->
<!--<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">-->
<!--<ul id="homework_pository_ref_pages">-->
<!--<li><a href="" class="pages-big" data-remote="true">上一页</a></li>-->
<!--<li><a class="active">1</a></li>-->
<!--<li><a href="" class="page c_blue" data-remote="true">2</a></li>-->
<!--<li><a href="" class="page c_blue" data-remote="true">3</a></li>-->
<!--<li><a href="" class="pages-big pages-border-right" data-remote="true">下一页</a></li>-->
<!--</ul>-->
<!--<div class="cl"></div>-->
<!--</div>-->
<!--<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">-->
<!--<ul id="homework_pository_ref_pages">-->
<!--<li><a href="" class="pages-big" data-remote="true">上一页</a></li>-->
<!--<li><a class="active">1</a></li>-->
<!--<li><a href="" class="page c_blue" data-remote="true">2</a></li>-->
<!--<li><a href="" class="page c_blue" data-remote="true">3</a></li>-->
<!--<li><a href="" class="pages-big pages-border-right" data-remote="true">下一页</a></li>-->
<!--</ul>-->
<!--<div class="cl"></div>-->
<!--</div>-->
<!--</div>-->
<!--当讨论区没有列表时,显示无数据提示-->
</div>
</div>

View File

@ -729,7 +729,7 @@ RedmineApp::Application.routes.draw do
match 'users/:id/leave_email_activation_message', :to => 'words#leave_email_activation_message', :via => :post, :as => "leave_email_activation_message"
# boards
match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post], :as => 'new_board_message'
match 'boards/:board_id/topics/new', :to => 'messages#new', :via => :get, :as => 'new_board_message'
match 'boards/:id/join_to_org_subfields', :to => 'boards#join_to_org_subfields'
match 'boards/:id/update_position', :to => 'boards#update_position', :via => :post
match 'boards/:id/update_boards_position', :to => 'boards#update_boards_position', :via => :post