后台管理页面的课程列表和课堂列表

dev_forge
cxt 5 years ago
parent 0eb0868b7e
commit 2f8d4a0fdd

@ -0,0 +1,60 @@
$(document).on('turbolinks:load', function() {
var $modal = $('.modal.admin-merge-course-list-modal');
if ($modal.length > 0) {
var $form = $modal.find('form.admin-merge-course-list-form');
var $originCourseListIdInput = $form.find('input[name="origin_course_list_id"]');
$form.validate({
errorElement: 'span',
errorClass: 'danger text-danger',
rules: {
course_list_name: {
required: true
}
},
messages: {
course_list_name: {
required: '请输入课程名称'
}
}
});
// modal ready fire
$modal.on('show.bs.modal', function (event) {
var $link = $(event.relatedTarget);
var couresListId = $link.data('courseListId');
var url = $link.data('url');
$originCourseListIdInput.val(couresListId);
$form.data('url', url);
});
$modal.on('click', '.submit-btn', function(){
$form.find('.error').html('');
if ($form.valid()) {
var url = $form.data('url');
$.ajax({
method: 'POST',
dataType: 'json',
url: url,
data: $form.serialize(),
success: function(){
$.notify({ message: '操作成功' });
$modal.modal('hide');
setTimeout(function(){
window.location.reload();
}, 500);
},
error: function(res){
var data = res.responseJSON;
$form.find('.error').html(data.message);
}
});
}
});
}
});

@ -0,0 +1,35 @@
class Admins::CourseListsController < Admins::BaseController
def index
course_lists = Admins::CourseListQuery.call(params)
@course_lists = paginate course_lists.preload(:courses, :user)
@params_page = params[:page] || 1
respond_to do |format|
format.js
format.html
end
end
def destroy
CourseList.find(params[:id]).destroy!
render_delete_success
end
def merge
origin_course_list = CourseList.find_by!(id: params[:origin_course_list_id])
o_courselist = CourseList.find_by(name: params[:course_list_name])
if o_courselist
origin_course_list.courses.each do |course|
course.update!(name: course.name.sub(origin_course_list.name, params[:course_list_name]), course_list_id: o_courselist.id)
end
origin_course_list.destroy
else
origin_course_list.courses.each do |course|
course.update!(name: course.name.sub(origin_course_list.name, params[:course_list_name]))
end
origin_course_list.update!(name: params[:course_list_name])
end
render_ok
end
end

@ -0,0 +1,26 @@
class Admins::CoursesController < Admins::BaseController
before_action :find_course, except: [:index]
def index
default_sort('created_at', 'desc')
courses = Admins::CourseQuery.call(params)
@ended_courses = courses.where(is_end: 1).size
@processed_courses = courses.where(is_end: 0).size
@courses = paginate courses.includes(:school, :students, :attachments, :homework_commons, teacher: :user_extension)
end
def destroy
if @course.is_delete == 0
@course.delete!
Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id,
container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name)
end
end
private
def find_course
@course = Course.find_by!(id: params[:id])
end
end

@ -31,6 +31,7 @@ class Course < ApplicationRecord
has_many :graduation_groups, dependent: :destroy
has_many :course_members, dependent: :destroy
has_many :students, -> { course_students }, class_name: 'CourseMember'
has_many :teacher_course_members, -> { teachers_and_admin }, class_name: 'CourseMember'
has_many :teacher_users, through: :teacher_course_members, source: :user
has_many :course_messages, dependent: :destroy
@ -238,11 +239,6 @@ class Course < ApplicationRecord
course_members.where(role: %i[CREATOR PROFESSOR])
end
# 课堂学生
def students
course_members.where(role: %i[STUDENT])
end
# 更新课程的访问人数
def update_visits(new_visits)
update_attributes(visits: new_visits)
@ -371,6 +367,19 @@ class Course < ApplicationRecord
count = course_challeng_count == 0 ? 0 : ((my_challenge_count.to_f / course_challeng_count).round(2) * 100).to_i
end
# 课堂实训作业的评测次数
def evaluate_count
course_user_ids = students.pluck(:user_id)
shixun_ids = homework_commons.joins(:homework_commons_shixun).where(homework_type: 4).pluck(:shixun_id)
return 0 if shixun_ids.blank?
Game.joins(:challenge).where(challenges: {shixun_id: shixun_ids}, games: {user_id: course_user_ids}).sum(:evaluate_count)
end
# 课堂作业数
def course_homework_count type
homework_commons.select{|homework| homework.homework_type == type}.size
end
private
#创建课程后,给该用户发送消息

@ -5,4 +5,5 @@ class CourseList < ApplicationRecord
has_many :exercise_banks
has_many :gtask_banks
has_many :gtopic_banks
belongs_to :user
end

@ -0,0 +1,30 @@
class Admins::CourseListQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :created_at, default_by: :created_at, default_direction: :desc
def initialize(params)
@params = params
end
def call
course_lists = CourseList.all
# 关键字模糊查询
keyword = params[:keyword].to_s.strip
if keyword.present?
search_type = params[:search_type] || "0"
case search_type
when "0"
course_lists = course_lists.joins(:user)
.where('CONCAT(lastname, firstname) like :keyword', keyword: "%#{keyword}%")
when "1"
course_lists = course_lists.where('name like :keyword', keyword: "%#{keyword}%")
end
end
custom_sort(course_lists, params[:sort_by], params[:sort_direction])
end
end

@ -0,0 +1,44 @@
class Admins::CourseQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :created_at, default_by: :created_at, default_direction: :desc, default_table: 'courses'
def initialize(params)
@params = params
end
def call
courses = Course.all
courses = courses.where(id: params[:id]) if params[:id].present?
# 状态过滤
status =
case params[:status].to_s.strip
when 'processing' then 0
when 'ended' then 1
end
courses = courses.where(is_end: status) if status
# 单位
if params[:school_id].present?
courses = courses.where(school_id: params[:school_id])
end
# 首页展示
if params[:homepage_show].present? && params[:homepage_show].to_s == 'true'
courses = courses.where(homepage_show: true)
end
# 关键字
keyword = params[:keyword].to_s.strip
if keyword
sql = 'CONCAT(lastname, firstname) LIKE :keyword OR courses.name LIKE :keyword OR course_lists.name LIKE :keyword'
courses = courses.joins(:teacher, :course_list).where(sql, keyword: "%#{keyword}%")
end
custom_sort(courses, params[:sort_by], params[:sort_direction])
end
end

@ -0,0 +1,22 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('课程列表') %>
<% end %>
<div class="box search-form-container course-list-list-form">
<%= form_tag(admins_course_lists_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group">
<label>搜索类型:</label>
<% auto_trial_options = [['创建者姓名', 0], ['课程名称', 1]] %>
<%= select_tag(:search_type, options_for_select(auto_trial_options), class: 'form-control') %>
</div>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '输入关键字搜索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3','data-disable-with': '搜索中...') %>
<%= link_to "清除",admins_course_lists_path,class: "btn btn-default",id:"course-lists-clear-search",'data-disable-with': '清除中...' %>
<% end %>
</div>
<div class="box admin-list-container course-list-list-container">
<%= render partial: 'admins/course_lists/shared/list', locals: { courses: @course_lists } %>
</div>
<%= render 'admins/course_lists/shared/merge_course_list_modal' %>

@ -0,0 +1 @@
$(".course-list-list-container").html("<%= j render partial: 'admins/course_lists/shared/list', locals: { courses: @course_lists }%>");

@ -0,0 +1,37 @@
<table class="table table-hover text-center shixuns-list-table">
<thead class="thead-light">
<th width="4%">序号</th>
<th width="8%">ID</th>
<th width="38%" class="text-left">课程名称</th>
<th width="10%">课堂数</th>
<th width="10%">创建者</th>
<th width="12%"><%= sort_tag('创建时间', name: 'created_at', path: admins_course_lists_path) %></th>
<th width="18%">操作</th>
</thead>
<tbody>
<% if courses.present? %>
<% courses.each_with_index do |course_list,index| %>
<tr id="course-list-item-<%= course_list.id %>">
<td><%= list_index_no(@params_page.to_i, index) %></td>
<td><%= course_list.id %></td>
<td class="text-left"><%= course_list.name %></td>
<% course_count = course_list.courses.size %>
<td><%= course_count %></td>
<td><%= link_to course_list.user.try(:real_name),"/users/#{course_list.user.try(:login)}",target:'_blank' %></td>
<td><%= format_time course_list.created_at %></td>
<td class="operate">
<% if course_count == 0 %>
<%= delete_link '删除', admins_course_list_path(course_list, element: ".course-list-item-#{course_list.id}"), class: 'delete-department-action' %>
<% end %>
<%= javascript_void_link '修改', class: 'action', data: { course_list_id: course_list.id,
toggle: 'modal', target: '.admin-merge-course-list-modal', url: merge_admins_course_lists_path } %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: courses } %>

@ -0,0 +1,29 @@
<div class="modal fade admin-merge-course-list-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">修改课程</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="admin-merge-course-list-form" data-url="<%= merge_admins_course_lists_path %>">
<%= hidden_field_tag(:origin_course_list_id, nil) %>
<div class="form-group d-flex">
<label for="course_list_id" class="col-form-label">更改为:</label>
<div class="d-flex flex-column-reverse w-75">
<input id="course_list_name" name="course_list_name" placeholder="请输入课程名称" class="form-control">
</div>
</div>
<div class="error text-danger"></div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary submit-btn">确认</button>
</div>
</div>
</div>
</div>

@ -0,0 +1,2 @@
alert("删除成功");
$(".course-item-<%= @course.id %>").find(".delete-course-action").remove();

@ -0,0 +1,33 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('课堂列表') %>
<% end %>
<div class="box search-form-container course-list-form">
<%= form_tag(admins_courses_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<div class="form-group mr-1">
<label for="status">状态:</label>
<% status_options = [['全部', ''], ["正在进行(#{@processed_courses})", 'processing'], ["已结束#{@ended_courses}", 'ended']] %>
<%= select_tag(:status, options_for_select(status_options), class: 'form-control') %>
</div>
<div class="form-group col-12 col-md-3">
<label for="school_name">单位:</label>
<%= select_tag :school_id, options_for_select([''], params[:school_id]), class: 'form-control school-select flex-1' %>
</div>
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-12 col-md-2 mr-3', placeholder: '创建者/课堂名称/课程名称检索') %>
<div class="form-check mr-2">
<%= hidden_field_tag(:homepage_show, false, id:'') %>
<%= check_box_tag(:homepage_show, true, params[:homepage_show].to_s == 'true', class: 'form-check-input') %>
<label class="form-check-label" for="homepage_show">只看首页展示</label>
</div>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
</div>
<div class="box admin-list-container course-list-container">
<%= render partial: 'admins/courses/shared/list', locals: { courses: @courses } %>
</div>

@ -0,0 +1 @@
$('.course-list-container').html("<%= j( render partial: 'admins/courses/shared/list', locals: { courses: @courses } ) %>");

@ -0,0 +1,64 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="4%">ID</th>
<th width="10%" class="text-left">课堂名称</th>
<th width="6%">成员</th>
<th width="4%">资源</th>
<th width="4%">普通作业</th>
<th width="4%">分组作业</th>
<th width="4%">实训作业</th>
<th width="4%">试卷</th>
<th width="7%">评测次数</th>
<th width="4%">私有</th>
<th width="6%">状态</th>
<th width="10%">单位</th>
<th width="7%">创建者</th>
<th width="10%"><%= sort_tag('创建时间', name: 'created_at', path: admins_courses_path) %></th>
<th width="4%">首页</th>
<th width="6%">邮件通知</th>
<th width="6%">操作</th>
</tr>
</thead>
<tbody>
<% if courses.present? %>
<% courses.each do |course| %>
<tr class="course-item-<%= course.id %>">
<td><%= course.id %></td>
<td class="text-left">
<%= link_to(course.name, "/courses/#{course.id}", target: '_blank') %>
</td>
<td><%= course.course_members_count %></td>
<td><%= get_attachment_count(course, 0) %></td>
<td><%= course.course_homework_count(1) %></td>
<td><%= course.course_homework_count(3) %></td>
<td><%= course.course_homework_count(4) %></td>
<td><%= course.exercises_count %></td>
<td><%= course.evaluate_count %></td>
<td><%= course.is_public == 1 ? "--" : "√" %></td>
<td><%= course.is_end ? "已结束" : "正在进行" %></td>
<td><%= course.school.name %></td>
<td><%= course.teacher&.real_name %></td>
<td><%= course.created_at&.strftime('%Y-%m-%d %H:%M') %></td>
<td>
<input type="checkbox" name="homepage_show" value="<%= course.id %>" <%= course.homepage_show ? "checked" : "" %> class="magic-checkbox" id="course_homepage_show_<%= course.id %>">
<label style="top:-14px;" class="ml20" for="course_homepage_show_<%= course.id %>"></label>
</td>
<td>
<input type="checkbox" name="email_notify" value="<%= course.id %>" <%= course.email_notify ? "checked" : "" %> class="magic-checkbox" id="course_email_notify_<%= course.id %>">
<label style="top:-14px;" class="ml20" for="course_email_notify_<%= course.id %>"></label>
</td>
<td class="action-container">
<% if course.is_delete == 0 %>
<%= delete_link '删除', admins_course_path(course, element: ".course-item-#{course.id}"), class: 'delete-course-action' %>
<% end %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: courses } %>

@ -32,8 +32,17 @@
<li>
<%= sidebar_item_group('#subject-submenu', '实践课程', icon: 'th-list') do %>
<li><%= sidebar_item(admins_subjects_path, '课程列表', icon: 'cog', controller: 'admins-subjects') %></li>
<% end %>
<li><%= sidebar_item(admins_subjects_path, '课程列表', icon: 'cog', controller: 'admins-subjects') %></li>
<% end %>
</li>
<li>
<%= sidebar_item_group('#course-submenu', '课堂管理', icon: 'book') do %>
<li><%= sidebar_item(admins_course_lists_path, '课程列表', icon: 'list', controller: 'admins-course_lists') %></li>
<li><%= sidebar_item(admins_courses_path, '课堂列表', icon: 'list', controller: 'admins-courses') %></li>
<!-- <li><%#= sidebar_item(admins_mirror_repositories_path, '镜像管理', icon: 'cubes', controller: 'admins-mirror_repositories') %></li>-->
<!-- <li><%#= sidebar_item(admins_myshixuns_path, '学员实训列表', icon: 'server', controller: 'admins-myshixuns') %></li>-->
<% end %>
</li>
<li>

@ -1172,6 +1172,16 @@ Rails.application.routes.draw do
resources :partners, only: [:index, :create, :destroy] do
resources :customers, only: [:index, :create, :destroy]
end
resources :course_lists, only: [:index, :destroy] do
post :merge, on: :collection
end
resources :courses, only: [:index, :destroy] do
post :hidden, on: :member
post :homepage_show, on: :member
post :email_notify, on: :member
end
end
namespace :cooperative do

Loading…
Cancel
Save