课程列表分为我创建的课程和我加入的课程

This commit is contained in:
cxt 2016-07-26 16:45:36 +08:00
parent 1e0ed2bfba
commit feb45a07bf
11 changed files with 214 additions and 154 deletions

View File

@ -41,7 +41,7 @@ class UsersController < ApplicationController
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,
:user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist]
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list]
before_filter :auth_user_extension, only: :show
#before_filter :rest_user_score, only: :show
#before_filter :select_entry, only: :user_projects
@ -3228,7 +3228,35 @@ class UsersController < ApplicationController
end
def user_courselist
@order, @c_sort,@type = params[:order] || 1, params[:sort] || 1, params[:type] || 1
@order, @c_sort, @type, @list_type = 1, 2, 1, 1
@my_syllabuses = @user.syllabuses
sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
@join_syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}")
@my_syllabuses = syllabus_course_list_sort @my_syllabuses
@join_syllabuses = syllabus_course_list_sort @join_syllabuses
@my_syllabuses = @my_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
@join_syllabuses = @join_syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]}
#分页
# @limit = 10
# @is_remote = true
# @atta_count = @syllabus.count
# @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
# @offset ||= @atta_pages.offset
# @syllabus = paginateHelper @syllabus,@limit
respond_to do |format|
format.html {render :layout => 'new_base_user'}
end
end
#课程列表的排序
def sort_syllabus_list
@order, @c_sort, @type, @list_type = params[:order] || 1, params[:sort] || 1, params[:type] || 1, params[:list_type] || 1
#确定 sort_type
if @order.to_i == @type.to_i
@ -3238,40 +3266,48 @@ class UsersController < ApplicationController
end
sort_name = "updated_at"
sort_type = @c_sort == 1 ? "asc" : "desc"
@courses = @user.courses.visible.where("is_delete =?", 0)
syllabus_ids = @courses.empty? ? '(-1)' : "(" + @courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
@syllabus = Syllabus.where("id in #{syllabus_ids} or user_id = #{User.current.id}").order("#{sort_name} #{sort_type}")
if @list_type.to_i == 1
@syllabuses = @user.syllabuses.order("updated_at desc")
else
sy_courses = @user.courses.visible.where("is_delete =? and tea_id != ?", 0, @user.id)
syllabus_ids = sy_courses.empty? ? '(-1)' : "(" + sy_courses.map{|course| !course.syllabus_id.nil? && course.syllabus_id}.join(",") + ")"
@syllabuses = Syllabus.where("id in #{syllabus_ids} and user_id != #{@user.id}").order("updated_at desc")
end
#根据 作业+资源数排序
if @order.to_i == 2
if @order.to_i == 1 #根据 班级更新时间排序
@syllabuses = syllabus_course_list_sort @syllabuses
@c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:last_update] <=> y[:last_update] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:last_update] <=> x[:last_update]})
@type = 1
elsif @order.to_i == 2 #根据 作业+资源数排序
@type = 2
@syllabus.each do |syllabus|
@syllabuses.each do |syllabus|
count = 0
courses = @courses.where("syllabus_id = #{syllabus.id}")
courses = syllabus.courses.not_deleted
courses.each do |c|
count += (User.current.admin? || User.current.allowed_to?(:as_teacher,c)) ? (c.homework_commons.count + visable_attachemnts_incourse(c).count) : (c.homework_commons.where("publish_time <= '#{Date.today}'").count + visable_attachemnts_incourse(c).count)
end
syllabus[:infocount] = count
end
@c_sort == 1 ? (@syllabus = @syllabus.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabus = @syllabus.sort{|x,y| y[:infocount] <=> x[:infocount]})
@syllabus = sortby_time_countcommon_nosticky @syllabus,sort_name
@c_sort == 1 ? (@syllabuses = @syllabuses.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@syllabuses = @syllabuses.sort{|x,y| y[:infocount] <=> x[:infocount]})
@syllabuses = sortby_time_countcommon_nosticky @syllabuses,sort_name
else
@type = 1
end
#分页
@limit = 10
@is_remote = true
@atta_count = @syllabus.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
@syllabus = paginateHelper @syllabus,@limit
respond_to do |format|
format.js
format.html {render :layout => 'new_base_user'}
end
end
#展开课程下的班级
def expand_courses
@syllabus = Syllabus.where("id = #{params[:syllabus_id]}").first
unless @syllabus.nil?
@courses = @syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc")
respond_to do |format|
format.js
end
end
end

View File

@ -690,4 +690,18 @@ module UsersHelper
end
result_ids
end
#课程的班级列表最近更新时间
def syllabus_course_list_sort syllabuses
syllabuses.each do |sy|
updated_at = sy.updated_at
courses = sy.courses.not_deleted
unless courses.empty?
course_ids = "(" + courses.map { |course| course.id}.join(",") + ")"
updated_at = CourseActivity.where("course_id in #{course_ids}").order("updated_at desc").first.updated_at
end
sy[:last_update] = updated_at
end
syllabuses
end
end

View File

@ -0,0 +1,28 @@
<% unless courses.nil? %>
<% courses.each_with_index do |course, i| %>
<li class="syllabus_class_list <%=i > 2 ? 'none' : '' %>">
<a href="<%=course_path(course.id) %>" target="_blank">
<span class="icons_sy_cir "></span>
<div class="fl">
<div class="syllabus_class_w ">
<p class="syllabus_class_title fl"><%=course.name %></p>
<span class="fr sy_p_grey hidden" style="max-width: 120px;">主讲老师:<%=course.teacher.show_name %></span>
<div class="cl"></div>
</div>
<div class="">
<p class="fl grayTxt ">更新:<%=format_date Time.at(course.updatetime) %><span class="mr10"></span>学期:<%=current_time_and_term(course) %></p>
<p class="list-info fr grayTxt"><span><%=studentCount course %></span><span>学生</span><span>|</span><span><%=visable_course_homework course %></span><span>作业</span><span>|</span><span><%=visable_attachemnts_incourse(@course).count %></span><span>资源</span></p>
<div class="cl"></div>
</div>
</div>
<span class="icons_sy_arrow fl mt19 ml10" ></span>
<div class="cl"></div>
</a>
</li>
<% end %>
<% if courses.count > 3 %>
<li class="syllabus_class_list_more" id="syllabus_class_list_more_<%=syllabus.id %>">
<a href="javascript:void(0);" id="expand_list_<%=syllabus.id %>" data-init="0" onclick="expand_course_list(<%=syllabus.id %>,'#syllabus_course_ul_<%=syllabus.id %> li','#expand_list_<%=syllabus.id %>',<%=courses.count %>)">共<%=courses.count %>个班级,点击全部展开</a>
</li>
<% end %>
<% end %>

View File

@ -0,0 +1,61 @@
<div class="syllabus_category">
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 2 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} fr", :style => "margin-right: 5px;", :remote => true %>
<% else %>
<%= link_to "", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 2 }, :class => "sortdownbtn sort_no fr", :style => "margin-right: 5px;", :remote => true %>
<% end %>
<%= link_to "人气", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 2 }, :class => "sortTxt fr", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 1 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} fr", :remote => true %>
<% else %>
<%= link_to "", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 1 }, :class => "sortdownbtn sort_no fr", :remote => true %>
<% end %>
<%= link_to "时间", {:controller => 'users', :action => 'sort_syllabus_list', :id =>@user,:list_type => list_type, :type => @type, :sort => @c_sort, :order => 1 }, :class => "sortTxt fr", :remote => true %>
<span class="grayTxt fl ">我<%= list_type == 1 ? "创建" : "加入"%>的课程</span>
<div class="cl"></div>
</div>
<% if syllabuses.any? %>
<% syllabuses.each_with_index do |syllabus, index|%>
<div class="syllabus_courses_box">
<% course_count = syllabus.courses.not_deleted.count %>
<div class="syllabus_courses_list" onclick="expand_courses(<%=syllabus.id %>,<%=course_count %>);" id="syllabus_courses_list_<%= syllabus.id %>">
<div class="<%=index == 0 ? 'sy_courses_open' : 'sy_courses_close' %>">
<span class="<%=index == 0 && course_count != 0 ? 'icons_sy_open' : 'icons_sy_close' %> fl mr5"></span>
<h3 class="syllabus_courses_title fl"><%=syllabus.title %></h3>
</div>
<p class="fl sy_p_grey">更新时间:<%=format_date syllabus.updated_at %>
<span class="mr10"></span>创建老师:<%=syllabus.user.show_name %>
<span class="mr10"></span>班级:<%=course_count %>
</p>
<div class="cl"></div>
</div>
<div class="syllabus_class_box <%=index == 0 ? '' : 'none' %>">
<ul id="syllabus_course_ul_<%=syllabus.id %>">
<% if index == 0 %>
<% courses = syllabus.courses.not_deleted.select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("updatetime desc") %>
<%= render :partial => 'users/courses_list', :locals => {:courses => courses, :syllabus => syllabus}%>
<% end %>
</ul>
</div><!--syllabus_class_box end-->
<div class="homepagePostSetting">
<ul>
<li class="icons_sy_setting">
<ul class="homepagePostSettiongText">
<li>
<%=link_to '查看课程', syllabus_path(syllabus.id), :class => 'postOptionLink',:target =>'_blank', :title => '查看课程' %>
</li>
<% if User.current == syllabus.user %>
<li><%=link_to '删除课程', delete_syllabus_syllabus_path(syllabus), :class => 'postOptionLink', :remote => 'true'%></li>
<% end %>
</ul>
</li>
</ul>
</div>
</div>
<% end %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@ -0,0 +1,3 @@
<div id="user_join_syllabus_list">
<%= render :partial => "users/syllabus_course_list", :locals => {:syllabuses => @join_syllabuses, :list_type => 2} %>
</div>

View File

@ -1,132 +1,3 @@
<div class="syllabus_box" id="course-list">
<h2 class="syllabus_h2_top"><span class="icon_course fl mt7 mr5"></span>课程列表</h2>
<div class="syllabus_category">
<span class="grayTxt fl">排序:</span>
<%= link_to "时间", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 1 }, :class => "sortTxt fl", :remote => true %>
<% if @type.to_i == 1 %>
<%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 1 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} fl", :remote => true %>
<% else %>
<%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 1 }, :class => "sortdownbtn sort_no fl", :remote => true %>
<% end %>
<%= link_to "人气", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 2 }, :class => "sortTxt fl", :remote => true %>
<% if @type.to_i == 2 %>
<%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 2 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} fl", :remote => true %>
<% else %>
<%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user, :type => @type, :sort => @c_sort, :order => 2 }, :class => "sortdownbtn sort_no fl", :remote => true %>
<% end %>
<div class="cl"></div>
</div>
<% if @syllabus.any? %>
<% @syllabus.each_with_index do |syllabus, index|%>
<div class="syllabus_courses_box">
<% courses = @courses.where("syllabus_id = #{syllabus.id}").select("courses.*,(SELECT MAX(updated_at) FROM `course_activities` WHERE course_activities.course_id = courses.id) AS updatetime").order("time desc") %>
<div class="syllabus_courses_list">
<div class="<%=index == 0 ? 'sy_courses_open' : 'sy_courses_close' %>">
<span class="<%=index == 0 && !courses.empty? ? 'icons_sy_open' : 'icons_sy_close' %> fl mr5"></span>
<h3 class="syllabus_courses_title fl"><%=syllabus.title %></h3>
</div>
<p class="fl sy_p_grey">更新时间:<%=format_date syllabus.updated_at %>
<span class="mr10"></span>创建老师:<%=syllabus.user.show_name %>
<span class="mr10"></span>班级:<%=courses.count %>
</p>
<div class="cl"></div>
</div>
<div class="syllabus_class_box <%=index == 0 ? '' : 'none' %>">
<ul id="syllabus_course_ul_<%=syllabus.id %>">
<% unless courses.nil? %>
<% courses.each_with_index do |course, i| %>
<li class="syllabus_class_list <%=i > 2 ? 'none' : '' %>">
<a href="<%=course_path(course.id) %>" target="_blank">
<span class="icons_sy_cir "></span>
<div class="fl">
<div class="syllabus_class_w ">
<p class="syllabus_class_title fl"><%=course.name %></p>
<span class="fr sy_p_grey hidden" style="max-width: 120px;">主讲老师:<%=course.teacher.show_name %></span>
<div class="cl"></div>
</div>
<div class="">
<p class="fl grayTxt ">更新:<%=format_date Time.at(course.updatetime) %><span class="mr10"></span>学期:<%=current_time_and_term(course) %></p>
<p class="list-info fr grayTxt"><span><%=studentCount course %></span><span>学生</span><span>|</span><span><%=visable_course_homework course %></span><span>作业</span><span>|</span><span><%=visable_attachemnts_incourse(@course).count %></span><span>资源</span></p>
<div class="cl"></div>
</div>
</div>
<span class="icons_sy_arrow fl mt19 ml10" ></span>
<div class="cl"></div>
</a>
</li>
<% end %>
<% if courses.count > 3 %>
<li class="syllabus_class_list_more" id="syllabus_class_list_more_<%=syllabus.id %>">
<a href="javascript:void(0);" id="expand_list_<%=syllabus.id %>" data-init="0" onclick="expand_course_list(<%=syllabus.id %>,'#syllabus_course_ul_<%=syllabus.id %> li','#expand_list_<%=syllabus.id %>',<%=courses.count %>)">共<%=courses.count %>个班级,点击全部展开</a>
</li>
<% end %>
<% end %>
</ul>
</div><!--syllabus_class_box end-->
<div class="homepagePostSetting">
<ul>
<li class="icons_sy_setting">
<ul class="homepagePostSettiongText">
<li>
<%=link_to '查看课程', syllabus_path(syllabus.id), :class => 'postOptionLink',:target =>'_blank', :title => '查看课程' %>
</li>
<% if User.current == syllabus.user %>
<li><%=link_to '删除课程', delete_syllabus_syllabus_path(syllabus), :class => 'postOptionLink', :remote => 'true'%></li>
<% end %>
</ul>
</li>
</ul>
</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 %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
</div>
<script type="text/javascript">
//如果右边的列表比左边的高度低则将右边的高度设为与左边对齐
$(function() {
var leftHeight = $("#LSide").height() - $(".fontGrey5").height() - 20;
var rightHeight = $(".homepageRight").height();
if (rightHeight < leftHeight) {
var diffHeight = leftHeight - rightHeight;
var tmpHeight = $(".syllabus_box").height() + diffHeight;
$(".syllabus_box").css("minHeight", tmpHeight);
}
$(".syllabus_courses_list").each(function(){
var syStaust = $(this).children(":first-child");
var classNum = $(this).next().children().children("li").size();
if(classNum>0){
if (syStaust.hasClass("sy_courses_open")){
$(this).toggle(function(){
$(this).next().hide();
$(this).children(":first-child").children(":first-child").addClass("icons_sy_close").removeClass("icons_sy_open");
},function(){
$(this).next().show();
$(this).children(":first-child").children(":first-child").addClass("icons_sy_open").removeClass("icons_sy_close");
});
}else{
$(this).toggle(function(){
$(this).next().show();
$(this).children(":first-child").children(":first-child").addClass("icons_sy_open").removeClass("icons_sy_close");
},function(){
$(this).next().hide();
$(this).children(":first-child").children(":first-child").addClass("icons_sy_close").removeClass("icons_sy_open");
});
}
}
});
});
</script>
<div id="user_syllabus_list">
<%= render :partial => "users/syllabus_course_list", :locals => {:syllabuses => @my_syllabuses, :list_type => 1} %>
</div>

View File

@ -0,0 +1,5 @@
<% unless @courses.empty? %>
$("#syllabus_course_ul_<%=@syllabus.id %>").html("<%=escape_javascript(render :partial => 'users/courses_list', :locals => {:courses => @courses, :syllabus => @syllabus}) %>");
$("#syllabus_course_ul_<%=@syllabus.id %>").parent().show();
$("#syllabus_course_ul_<%=@syllabus.id %>").parent().prev().children(":first-child").children(":first-child").toggleClass("icons_sy_close").toggleClass("icons_sy_open");
<% end %>

View File

@ -0,0 +1,5 @@
<% if @list_type.to_i == 1 %>
$("#user_syllabus_list").html('<%= escape_javascript(render :partial => "users/syllabus_course_list", :locals => {:syllabuses => @syllabuses, :list_type => 1}) %>');
<% else %>
$("#user_join_syllabus_list").html('<%= escape_javascript(render :partial => "users/syllabus_course_list", :locals => {:syllabuses => @syllabuses, :list_type => 2}) %>');
<% end %>

View File

@ -1 +1,35 @@
<%= render :partial => 'users/user_syllabus_list'%>
<div class="syllabus_box" id="course-list">
<h2 class="syllabus_h2_top"><span class="icon_course fl mt7 mr5"></span>课程列表</h2>
<%= render :partial => 'users/user_syllabus_list'%>
<div class="" style="height:20px; background:#eaebec;"></div>
<%= render :partial => 'users/user_join_syllabus_list'%>
</div>
<script type="text/javascript">
//如果右边的列表比左边的高度低则将右边的高度设为与左边对齐
$(function() {
var leftHeight = $("#LSide").height() - $(".fontGrey5").height() - 20;
var rightHeight = $(".homepageRight").height();
if (rightHeight < leftHeight) {
var diffHeight = leftHeight - rightHeight;
var tmpHeight = $(".syllabus_box").height() + diffHeight;
$(".syllabus_box").css("minHeight", tmpHeight);
}
});
function expand_courses(id, count){
var div = $("#syllabus_courses_list_"+id);
var classNum = div.next().children().children("li").size();
if(classNum>0){
div.next().toggle();
div.children(":first-child").children(":first-child").toggleClass("icons_sy_close").toggleClass("icons_sy_open");
} else if(count > 0) {
var str = div.next().children().eq(0).attr('id');
var id = str.substring(19);
$.get(
'/users/expand_courses?syllabus_id=' + id
);
}
}
</script>

View File

@ -563,6 +563,7 @@ RedmineApp::Application.routes.draw do
post "user_commit_homework"
post 'user_select_homework'
get 'all_journals'
get 'expand_courses'
end
member do
@ -619,6 +620,8 @@ RedmineApp::Application.routes.draw do
match 'user_courselist', :to => 'users#user_courselist', :via => :get, :as => "user_courselist"
match 'user_projectlist', :to => 'users#user_projectlist', :via => :get, :as => "user_projectlist"
match 'sort_syllabus_list', :to => 'users#sort_syllabus_list', :via => :get, :as => "sort_syllabus_list"
get 'edit_brief_introduction'
get "user_resource"
get "import_resources"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 22 KiB