实训作业的排序

dev_hs
cxt 6 years ago
parent 9b720cde16
commit 35ad9d249f

@ -40,6 +40,8 @@ class CoursesController < ApplicationController
before_action :validate_course_name, only: [:create, :update]
before_action :find_board, only: :board_list
before_action :validate_page_size, only: :mine
before_action :course_tasks, only: [:tasks_list, :update_task_position]
before_action :find_container, only: [:update_task_position]
if RUBY_PLATFORM =~ /linux/
require 'simple_xlsx_reader'
@ -1118,11 +1120,41 @@ class CoursesController < ApplicationController
end
def tasks_list
case params[:container_type]
when 'shixun_homework'
@tasks = @course.practice_homeworks
when 'common_homework'
@tasks = @course.normal_homeworks
when 'group_homework'
@tasks = @course.group_homeworks
when 'exercise'
@tasks = @course.exercises
when 'poll'
@tasks = @course.polls
when 'graduation_topic'
@tasks = @course.graduation_topics
when 'graduation_task'
@tasks = @course.graduation_tasks
when 'attachment'
@tasks = @course.attachments
else
tip_exception("请指定任务类型")
end
end
def update_task_position
tip_exception("缺少position参数") if params[:position].blank?
unless params[:position].to_i == @task.position
if params[:position].to_i < @task.position
@tasks.where("position < #{@task.position} and position >= ?", params[:position]).update_all("position = position + 1")
else
@tasks.where("position > #{@task.position} and position <= ?", params[:position]).update_all("position = position - 1")
end
@task.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
end
end
private
@ -1185,6 +1217,48 @@ class CoursesController < ApplicationController
end
end
def course_tasks
case params[:container_type]
when 'shixun_homework'
@tasks = @course.practice_homeworks
when 'common_homework'
@tasks = @course.normal_homeworks
when 'group_homework'
@tasks = @course.group_homeworks
when 'exercise'
@tasks = @course.exercises
when 'poll'
@tasks = @course.polls
when 'graduation_topic'
@tasks = @course.graduation_topics
when 'graduation_task'
@tasks = @course.graduation_tasks
when 'attachment'
@tasks = @course.attachments
else
tip_exception("请指定任务类型")
end
end
def find_container
case params[:container_type]
when 'shixun_homework', 'common_homework', 'group_homework'
@task = HomeworkCommon.find_by(id: params[:container_id])
when 'exercise'
@task = Exercise.find_by(id: params[:container_id])
when 'poll'
@task = Poll.find_by(id: params[:container_id])
when 'graduation_topic'
@task = GraduationTopic.find_by(id: params[:container_id])
when 'graduation_task'
@task = GraduationTask.find_by(id: params[:container_id])
when 'attachment'
@task = Attachment.find_by(id: params[:container_id])
else
tip_exception("container_type参数有误")
end
end
def student_act_score group_id, search
sql_select = %Q{SELECT cm.*,(
SELECT SUM(student_works.work_score)

@ -12,6 +12,7 @@ class HomeworkCommon < ApplicationRecord
belongs_to :course, counter_cache: true
belongs_to :homework_bank, optional: true
belongs_to :user
has_many :homework_challenge_settings, dependent: :destroy
has_one :homework_commons_shixun, dependent: :destroy

@ -0,0 +1,7 @@
json.tasks @tasks.each do |task|
json.user_name task.user.real_name
json.task_id task.id
json.task_name task.name
json.category task.course_second_category&.name
json.position task.position
end
Loading…
Cancel
Save