毕设任务列表和作品列表的优化

dev_forum
cxt 5 years ago
parent e7cec7b8a3
commit 795d4ecf71

@ -37,7 +37,7 @@ class GraduationTasksController < ApplicationController
@all_count = @course.graduation_tasks.size @all_count = @course.graduation_tasks.size
@published_count = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").size @published_count = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").size
@task_count = @tasks.size @task_count = @tasks.size
@tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works, course: [course_members: :teacher_course_groups]) @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works)
end end
# 任务问答 # 任务问答
@ -72,7 +72,7 @@ class GraduationTasksController < ApplicationController
@work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension]) @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension])
@all_work_count = @work_list.count @all_work_count = @work_list.count
@teachers = @course.teachers.where.not(user_id: current_user.id) @teachers = @course.teachers.where.not(user_id: current_user.id).includes(:user)
# 教师评阅搜索 0: 未评, 1 已评 # 教师评阅搜索 0: 未评, 1 已评
unless params[:teacher_comment].blank? unless params[:teacher_comment].blank?
graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id) graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id)
@ -123,6 +123,8 @@ class GraduationTasksController < ApplicationController
@work_count = @work_list.count @work_count = @work_list.count
@work_excel = @work_list @work_excel = @work_list
@work_list = @work_list.page(page).per(limit) @work_list = @work_list.page(page).per(limit)
@students = @course.students
@assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2
if params[:format] == "xlsx" if params[:format] == "xlsx"
complete_works = @work_excel.where("work_status > 0").size complete_works = @work_excel.where("work_status > 0").size

@ -67,7 +67,7 @@ module GraduationTasksHelper
# 作品数统计type 1 已提交 0 未提交 # 作品数统计type 1 已提交 0 未提交
def grduationwork_count task, type def grduationwork_count task, type
works = task.graduation_works works = task.graduation_works
type == 1 ? works.where("work_status !=?", 0).size : works.where("work_status =?", 0).size type == 1 ? works.select{|work| work.work_status != 0}.size : works.select{|work| work.work_status == 0}.size
end end
# 普通/分组 作业作品状态数组 # 普通/分组 作业作品状态数组

@ -68,7 +68,7 @@ class GraduationWork < ApplicationRecord
# 作品是否能够分配指导老师 # 作品是否能够分配指导老师
def assign_power?(course_identity) def assign_power?(course_identity)
course_identity < Course::STUDENT && self.graduation_task.cross_comment.present? && self.graduation_task.comment_status == 2 course_identity < Course::STUDENT && graduation_task.cross_comment && graduation_task.comment_status == 2
end end
# 老师评阅分 # 老师评阅分

@ -1,10 +1,6 @@
json.course_identity @identity json.course_identity @identity
json.course_public @course.is_public == 1 json.course_public @course.is_public == 1
json.is_end @course.is_end json.is_end @course.is_end
json.all_count @all_count
json.published_count @published_count
json.unpublished_count @all_count - @published_count
json.task_count @task_count
json.tasks @tasks.each do |task| json.tasks @tasks.each do |task|
# task_private = @identity > Course::STUDENT && !task.is_public # task_private = @identity > Course::STUDENT && !task.is_public
@ -29,3 +25,7 @@ json.tasks @tasks.each do |task|
end end
end end
json.all_count @all_count
json.published_count @published_count
json.unpublished_count @all_count - @published_count
json.task_count @task_count

@ -34,6 +34,7 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.work_count @work_count json.work_count @work_count
json.all_work_count @all_work_count json.all_work_count @all_work_count
end end
# 学生数据 # 学生数据
json.work_lists do json.work_lists do
json.array! @work_list do |work| json.array! @work_list do |work|
@ -41,7 +42,7 @@ if @task.published? || @user_course_identity < Course::STUDENT
json.user_id work.user.id json.user_id work.user.id
json.name work.user.real_name json.name work.user.real_name
json.student_id work.user.student_id json.student_id work.user.student_id
json.class_grouping_name work.class_grouping_name json.class_grouping_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name)
json.ultimate_score work.ultimate_score json.ultimate_score work.ultimate_score
if @task.have_grouping? if @task.have_grouping?
json.grouping_name work.grouping_name json.grouping_name work.grouping_name
@ -58,7 +59,7 @@ if @task.published? || @user_course_identity < Course::STUDENT
end end
json.late_penalty work.late_penalty if @task.allow_late json.late_penalty work.late_penalty if @task.allow_late
json.final_score work_final_score work, @current_user, @user_course_identity json.final_score work_final_score work, @current_user, @user_course_identity
json.assign work.assign_power?(@user_course_identity) json.assign @assign_power
json.view_work @view_work || @current_user.id == work.user_id json.view_work @view_work || @current_user.id == work.user_id
end end
end end

Loading…
Cancel
Save