分班模块的调整

dev_hjm_a
cxt 5 years ago
parent 164d3d4413
commit 22993dfb7c

@ -12,10 +12,10 @@ class CoursesController < ApplicationController
end
before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
:left_banner, :top_banner, :informs, :online_learning]
:left_banner, :top_banner, :informs, :online_learning, :course_groups]
before_action :check_account, only: [:new, :create, :apply_to_join_course, :join_excellent_course]
before_action :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
:left_banner, :top_banner, :apply_to_join_course, :exit_course]
:left_banner, :top_banner, :apply_to_join_course, :exit_course, :course_groups]
before_action :set_course, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
:set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers,
:top_banner, :left_banner, :add_teacher_popup, :add_teacher,
@ -28,7 +28,7 @@ class CoursesController < ApplicationController
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course,
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list,
:join_excellent_course, :export_couser_info, :export_member_act_score, :new_informs,
:delete_informs, :change_member_role]
:delete_informs, :change_member_role, :course_groups, :join_course_group]
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
@ -822,6 +822,26 @@ class CoursesController < ApplicationController
end
end
# 分班列表
def course_groups
@course_groups = @course.course_groups
@course_groups = @course_groups.where("name like ?", "%#{params[:search]}%") unless params[:search].blank?
@all_group_count = @course_groups.size
@teachers = @course.teachers.includes(:user, :teacher_course_groups) if @user_course_identity < Course::NORMAL
@current_group_id = @course.students.where(user_id: current_user.id).take&.course_group_id if @user_course_identity == Course::STUDENT
end
# 学生自动加入分班
def join_course_group
tip_exception("学生才能加入分班") if @user_course_identity != Course::STUDENT
course_group = CourseGroup.find_by!(id: params[:course_group_id], course_id: @course.id)
member = CourseMember.find_by!(user_id: current_user.id, course_id: @course.id, role: 4)
if course_group && member
member.update_attributes!(course_group_id: course_group.id)
normal_status(0, "加入成功")
end
end
# 将学生批量移动到某个分班
def transfer_to_course_group
ActiveRecord::Base.transaction do

@ -1,6 +1,18 @@
module CoursesHelper
# 是否有切换为学生的入口
def member_manager group, teachers
str = ""
members = teachers.select{|teacher| teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id) || teacher.teacher_course_groups.size == 0}
str = members.uniq.size == teachers.size ? "全部教师" : members.map{|member| member.user.real_name}.join("")
str
# teachers.each do |member|
# if member.teacher_course_groups.exists?(course_group_id: group.id) || member.teacher_course_groups.size == 0
# str << member.user.real_name
# end
# end
end
# 是否有切换为学生的入口
def switch_student_role is_teacher, course, user
is_teacher && course.course_members.where(user_id: user.id, role: %i(STUDENT)).exists?
end

@ -0,0 +1,11 @@
json.course_groups @course_groups.each do |group|
json.(group, :id, :course_members_count, :name)
json.invite_code group.invite_code if @user_course_identity < Course::STUDENT
json.member_manager member_manager(group, @teachers) if @user_course_identity < Course::NORMAL
end
if @user_course_identity == Course::STUDENT
json.current_group_id @current_group_id
end
json.none_group_member_count @course.none_group_count
json.group_count @all_group_count

@ -7,7 +7,7 @@ json.students do
json.student_id student.user.try(:student_id)
json.course_group_name student.course_group.try(:name)
json.course_member_id student.id
if @user_course_identity < Course::ASSISTANT_PROFESSOR
if @user_course_identity < Course::ASSISTANT_PROFESSOR && !params[:course_group_id].present?
json.member_roles student.user.course_role(@course)
end
json.user_phone student.user.hidden_phone

@ -370,6 +370,8 @@ Rails.application.routes.draw do
post 'join_excellent_course'
get 'tasks_list'
post 'update_task_position'
get 'course_groups'
post 'join_course_group'
end
collection do

Loading…
Cancel
Save