From 77b610851afdeaa25e61964a72711603a27d532f Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Mon, 23 Sep 2019 11:23:39 +0800
Subject: [PATCH 1/8] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E6=B6=88=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 9 ++++++--
app/decorators/tiding_decorator.rb | 9 ++++++++
app/jobs/course_delete_student_notify_job.rb | 22 +++++++++++++++++++
config/locales/tidings/zh-CN.yml | 4 ++--
.../course_delete_student_notify_job_spec.rb | 5 +++++
5 files changed, 45 insertions(+), 4 deletions(-)
create mode 100644 app/jobs/course_delete_student_notify_job.rb
create mode 100644 spec/jobs/course_delete_student_notify_job_spec.rb
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index d2c9f88d2..1ca907080 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -307,8 +307,8 @@ class CoursesController < ApplicationController
def destroy
if @course.is_delete == 0
@course.delete!
- Tiding.create!(user_id: @course.tea_id, trigger_user_id: 0, container_id: @course.id,
- container_type: 'Course', tiding_type: 'Delete', extra: @course.name)
+ 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)
normal_status(0, "成功")
else
normal_status(-1, "课堂已删除,无需重复操作")
@@ -572,6 +572,10 @@ class CoursesController < ApplicationController
tip_exception("删除失败") if course_member.CREATOR? or course_member.STUDENT?
course_student = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[STUDENT])
+ # Tiding.create!(user_id: course_member.user_id, trigger_user_id: current_user.id, container_id: @course.id,
+ # container_type: 'DeleteCourseMember', tiding_type: 'System', belong_container: @course, extra: @course.name)
+ CourseDeleteStudentNotifyJob.perform_later(@course.id, [course_member.user_id], current_user.id)
+
course_member.destroy!
course_student.update_attributes(is_active: 1) if course_student.present? && !course_student.is_active
normal_status(0, "删除成功")
@@ -802,6 +806,7 @@ class CoursesController < ApplicationController
end
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
+ CourseDeleteStudentNotifyJob.perform_later(@course.id, student_ids, current_user.id) if student_ids.present?
normal_status(0, "操作成功")
rescue => e
uid_logger(e.message)
diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb
index b4f851e5f..b1284d3d4 100644
--- a/app/decorators/tiding_decorator.rb
+++ b/app/decorators/tiding_decorator.rb
@@ -134,6 +134,15 @@ module TidingDecorator
end
end
+ def delete_course_content
+ I18n.t(locale_format) % container.name
+ end
+
+ def delete_course_member_content
+ name = Course.find_by(id: container_id)&.name
+ I18n.t(locale_format) % [trigger_user&.show_real_name, name]
+ end
+
def shixun_content
I18n.t(locale_format) % container.name
end
diff --git a/app/jobs/course_delete_student_notify_job.rb b/app/jobs/course_delete_student_notify_job.rb
new file mode 100644
index 000000000..898fc97c9
--- /dev/null
+++ b/app/jobs/course_delete_student_notify_job.rb
@@ -0,0 +1,22 @@
+# 删除课堂用户
+class CourseDeleteStudentNotifyJob < ApplicationJob
+ queue_as :notify
+
+ def perform(course_id, student_ids, trigger_user_id)
+ course = Course.find_by(id: course_id)
+ return if course.blank?
+
+ attrs = %i[user_id trigger_user_id container_id container_type belong_container_id
+ belong_container_type tiding_type created_at updated_at]
+
+ same_attrs = {
+ trigger_user_id: trigger_user_id, container_id: course.id, container_type: 'DeleteCourseMember',
+ belong_container_id: course.id, belong_container_type: 'Course', tiding_type: 'System'
+ }
+ Tiding.bulk_insert(*attrs) do |worker|
+ student_ids.each do |user_id|
+ worker.add same_attrs.merge(user_id: user_id)
+ end
+ end
+ end
+end
diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml
index 557f3f79b..8e5224ddf 100644
--- a/config/locales/tidings/zh-CN.yml
+++ b/config/locales/tidings/zh-CN.yml
@@ -58,8 +58,8 @@
"2_end": "你提交的试用授权申请,审核未通过
原因:%{reason}"
Apply_end: "提交了试用授权申请"
Course_end: "你创建了课堂:%s"
- Course:
- Delete_end: "你删除了课堂:%s"
+ DeleteCourse_end: "你删除了课堂:%s"
+ DeleteCourseMember_end: "%s 将你从课堂中删除了:%s"
Shixun_end: "你创建了实训:%s"
Subject_end: "你创建了实践课程:%s"
ArchiveCourse_end: "你的课堂已经归档:%s"
diff --git a/spec/jobs/course_delete_student_notify_job_spec.rb b/spec/jobs/course_delete_student_notify_job_spec.rb
new file mode 100644
index 000000000..75cff4162
--- /dev/null
+++ b/spec/jobs/course_delete_student_notify_job_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe CourseDeleteStudentNotifyJob, type: :job do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
From c8b30dd633dd3885021c870901b8b7c23ea1b906 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Mon, 23 Sep 2019 17:18:05 +0800
Subject: [PATCH 2/8] =?UTF-8?q?=E8=A1=A5=E5=81=9A=E8=AF=BE=E5=A0=82?=
=?UTF-8?q?=E6=B6=88=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../exercise_questions_controller.rb | 12 ++++++-
.../graduation_works_controller.rb | 5 +++
app/controllers/student_works_controller.rb | 12 ++++++-
app/decorators/tiding_decorator.rb | 10 +++++-
app/jobs/resubmit_student_work_notify_job.rb | 33 +++++++++++++++++++
config/locales/tidings/zh-CN.yml | 6 ++--
.../resubmit_student_work_notify_job_spec.rb | 5 +++
7 files changed, 77 insertions(+), 6 deletions(-)
create mode 100644 app/jobs/resubmit_student_work_notify_job.rb
create mode 100644 spec/jobs/resubmit_student_work_notify_job_spec.rb
diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb
index bb28fff54..9eeba6adc 100644
--- a/app/controllers/exercise_questions_controller.rb
+++ b/app/controllers/exercise_questions_controller.rb
@@ -656,7 +656,17 @@ class ExerciseQuestionsController < ApplicationController
:exercise_answer_id => ex_answer_comment_id
}
@exercise_comments = ExerciseAnswerComment.new(comment_option)
- @exercise_comments.save
+ @exercise_comments.save!
+
+ # 给被评阅人发送消息,同一个教师评阅无需重复发消息
+
+ unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists?
+ Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id,
+ container_type: "Exercise", parent_container_id: @exercise.id,
+ parent_container_type: "ExerciseScore", belong_container_id: @course.id,
+ belong_container_type: 'Course', tiding_type: "Exercise")
+ end
+
end
rescue Exception => e
uid_logger_error(e.message)
diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb
index 204e0e5d4..3d516b4b1 100644
--- a/app/controllers/graduation_works_controller.rb
+++ b/app/controllers/graduation_works_controller.rb
@@ -371,6 +371,11 @@ class GraduationWorksController < ApplicationController
new_score.save!
@work.update_attributes(ultimate_score: 1, work_score: params[:score].to_f)
+ Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id,
+ container_type: "AdjustScore", parent_container_id: @task.id,
+ parent_container_type: "GraduationTask", belong_container_id: @course.id,
+ belong_container_type: 'Course', tiding_type: "GraduationTask")
+
normal_status("调分成功")
rescue Exception => e
uid_logger(e.message)
diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb
index 2612510c5..a4e08b90a 100644
--- a/app/controllers/student_works_controller.rb
+++ b/app/controllers/student_works_controller.rb
@@ -224,7 +224,7 @@ class StudentWorksController < ApplicationController
raise ActiveRecord::Rollback
end
- SubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids) if student_ids.present?
+ ResubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids) if student_ids.present?
end
end
@@ -333,6 +333,11 @@ class StudentWorksController < ApplicationController
@work.update_attributes(update_time: Time.now)
+ # 补交附件时给评阅过作品的教师、助教发消息
+ unless @work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(user_id).uniq.blank?
+ ResubmitStudentWorkNotifyJob.perform_later(@homework.id, [current_user.id])
+ end
+
normal_status(0, "提交成功")
rescue Exception => e
uid_logger(e.message)
@@ -551,6 +556,11 @@ class StudentWorksController < ApplicationController
@work.work_score = params[:score].to_f
@work.save!
+ Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id,
+ container_type: "AdjustScore", parent_container_id: @homework.id,
+ parent_container_type: "HomeworkCommon", belong_container_id: @course.id,
+ belong_container_type: 'Course', tiding_type: "HomeworkCommon")
+
normal_status(0,"调分成功")
rescue Exception => e
uid_logger(e.message)
diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb
index b1284d3d4..9dc439377 100644
--- a/app/decorators/tiding_decorator.rb
+++ b/app/decorators/tiding_decorator.rb
@@ -340,13 +340,21 @@ module TidingDecorator
end
def student_work_content
- I18n.t(locale_format(extra.nil?)) % container&.homework_common.try(:name)
+ I18n.t(locale_format) % container&.homework_common.try(:name)
+ end
+
+ def resubmit_student_work_content
+ I18n.t(locale_format) % container&.homework_common.try(:name)
end
def student_works_score_content
I18n.t(locale_format(extra)) % container&.student_work&.homework_common.try(:name)
end
+ def adjust_score_content
+ I18n.t(locale_format) % parent_container.try(:name)
+ end
+
def challenge_work_score_content
I18n.t(locale_format) % container&.comment
end
diff --git a/app/jobs/resubmit_student_work_notify_job.rb b/app/jobs/resubmit_student_work_notify_job.rb
new file mode 100644
index 000000000..1a67aa3ad
--- /dev/null
+++ b/app/jobs/resubmit_student_work_notify_job.rb
@@ -0,0 +1,33 @@
+class ResubmitStudentWorkNotifyJob < ApplicationJob
+ queue_as :notify
+
+ def perform(homework_id, student_ids)
+ homework = HomeworkCommon.find_by(id: homework_id)
+ return if homework.blank? || student_ids.blank?
+ course = homework.course
+
+ attrs = %i[user_id trigger_user_id container_id container_type parent_container_id parent_container_type
+ belong_container_id belong_container_type tiding_type viewed created_at updated_at]
+
+ same_attrs = {
+ container_type: 'ResubmitStudentWork', parent_container_id: homework.id, parent_container_type: 'HomeworkCommon',
+ belong_container_id: course.id, belong_container_type: 'Course', tiding_type: 'HomeworkCommon', viewed: 0
+ }
+ Tiding.bulk_insert(*attrs) do |worker|
+ student_ids.each do |user_id|
+ next unless User.exists?(id: user_id)
+
+ work = homework.student_works.find_by(user_id: user_id)
+ next if work.blank?
+ score_user_ids = work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(user_id).uniq
+ next if score_user_ids.blank?
+
+ attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id)
+
+ score_user_ids.each do |user_id|
+ worker.add attrs.merge(user_id: user_id)
+ end
+ end
+ end
+ end
+end
diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml
index 8e5224ddf..f484efdc1 100644
--- a/config/locales/tidings/zh-CN.yml
+++ b/config/locales/tidings/zh-CN.yml
@@ -185,13 +185,13 @@
NearlyEnd_end: "作业的提交截止时间快到啦:%{name}"
AppealNearlyEnd_end: "作品的匿评申诉时间快到啦:%{name}"
EvaluationNearlyEnd_end: "作业的匿评截止时间快到啦:%{name}"
- StudentWork:
- true_end: "提交了作品:%s"
- false_end: "重新提交了作品,建议您重新评阅:%s"
+ StudentWork_end: "提交了作品:%s"
+ ResubmitStudentWork_end: "重新提交了作品,建议您重新评阅作品:%s"
StudentWorksScore:
1_end: "评阅了你的作品:%s"
2_end: "评阅了你的作品:%s"
3_end: "有人匿评了你的作品:%s"
+ AdjustScore_end: "调整了你的作品得分:%s"
ChallengeWorkScore_end: "调整了你的作品分数:%s"
StudentWorksScoresAppeal:
UserAppealResult:
diff --git a/spec/jobs/resubmit_student_work_notify_job_spec.rb b/spec/jobs/resubmit_student_work_notify_job_spec.rb
new file mode 100644
index 000000000..53b354b22
--- /dev/null
+++ b/spec/jobs/resubmit_student_work_notify_job_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ResubmitStudentWorkNotifyJob, type: :job do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
From 8e1e5347067fe9b0e8d73fe242145ff26c62ba69 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Tue, 24 Sep 2019 11:19:25 +0800
Subject: [PATCH 3/8] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../graduation_works_controller.rb | 24 ++++++++++++++++---
config/routes.rb | 1 +
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb
index 3d516b4b1..bc91cf4f7 100644
--- a/app/controllers/graduation_works_controller.rb
+++ b/app/controllers/graduation_works_controller.rb
@@ -1,18 +1,18 @@
class GraduationWorksController < ApplicationController
before_action :require_login, :check_auth
before_action :find_task, only: [:new, :create, :search_member_list, :check_project, :relate_project,
- :cancel_relate_project]
+ :cancel_relate_project, :delete_work]
before_action :find_work, only: [:show, :edit, :update, :revise_attachment, :supply_attachments, :comment_list,
:add_score, :delete_score, :adjust_score, :assign_teacher]
before_action :user_course_identity
before_action :task_public
before_action :teacher_allowed, only: [:add_score, :adjust_score, :assign_teacher]
before_action :course_student, only: [:new, :create, :edit, :update, :search_member_list, :relate_project,
- :cancel_relate_project]
+ :cancel_relate_project, :delete_work]
before_action :my_work, only: [:edit, :update, :revise_attachment]
before_action :published_task, only: [:new, :create, :edit, :update, :search_member_list, :relate_project,
:cancel_relate_project, :revise_attachment]
- before_action :edit_duration, only: [:edit, :update]
+ before_action :edit_duration, only: [:edit, :update, :delete_work]
before_action :open_work, only: [:show, :supply_attachments, :comment_list]
def new
@@ -47,6 +47,24 @@ class GraduationWorksController < ApplicationController
@members = @members.page(page).per(limit).includes(:course_group, user: :user_extension)
end
+ def delete_work
+ ActiveRecord::Base.transaction do
+ begin
+ work = @task.graduation_works.find_by!(user_id: params[:user_id])
+ tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id
+ work.update_attributes(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil,
+ update_time: nil, group_id: 0, commit_user_id: nil, final_score: nil, work_score: nil,
+ teacher_score: nil, teaching_asistant_score: nil, update_user_id: nil)
+ work.attachments.destroy_all
+ work.tidings.destroy_all
+ normal_status("删除成功")
+ rescue Exception => e
+ uid_logger(e.message)
+ tip_exception(e.message)
+ end
+ end
+ end
+
# 判断项目是否已有其他作品关联上了
def check_project
tip_exception("项目id不能为空") if params[:project_id].blank?
diff --git a/config/routes.rb b/config/routes.rb
index af7e0ee3b..e4199edb3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -539,6 +539,7 @@ Rails.application.routes.draw do
post 'relate_project'
get 'cancel_relate_project'
post 'revise_attachment'
+ delete 'delete_work'
end
member do
From a07cc733eccb6b8f7eb18e4420a1c82b352d7c49 Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 27 Sep 2019 09:53:40 +0800
Subject: [PATCH 4/8] ecs: api modify
---
.../ecs/course_targets/with_achievement_methods.json.jbuilder | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 app/views/ecs/course_targets/with_achievement_methods.json.jbuilder
diff --git a/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder
new file mode 100644
index 000000000..689504ec3
--- /dev/null
+++ b/app/views/ecs/course_targets/with_achievement_methods.json.jbuilder
@@ -0,0 +1,2 @@
+
+json.course_targets @course_targets, partial: 'ecs/course_targets/shared/ec_course_target_with_achievement_methods', as: :ec_course_target
From 40363b4d975045679173418ac15dae919314c1af Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Fri, 27 Sep 2019 10:08:14 +0800
Subject: [PATCH 5/8] =?UTF-8?q?=E9=87=91=E8=AF=BE=E5=9C=A8=E7=BA=BF?=
=?UTF-8?q?=E5=AD=A6=E4=B9=A0=E5=92=8C=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?=
=?UTF-8?q?=E7=9A=84=E7=AB=A0=E8=8A=82=E5=88=97=E8=A1=A8=E6=80=A7=E8=83=BD?=
=?UTF-8?q?=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/courses_controller.rb | 3 +-
app/controllers/exercises_controller.rb | 138 +++++++++---------
app/controllers/stages_controller.rb | 3 +-
app/helpers/stages_helper.rb | 4 +-
.../courses/online_learning.json.jbuilder | 2 +-
app/views/stages/_stage.json.jbuilder | 2 +-
app/views/stages/index.json.jbuilder | 2 +-
7 files changed, 77 insertions(+), 77 deletions(-)
diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index 812a139dc..0e093460f 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -269,8 +269,9 @@ class CoursesController < ApplicationController
def online_learning
@subject = @course.subject
- @stages = @course.course_stages
+ @stages = @course.course_stages.includes(:shixuns)
@user = current_user
+ @myshixuns = @user.myshixuns.where(shixun_id: @course.course_stage_shixuns.pluck(:shixun_id))
@start_learning = @user_course_identity == Course::STUDENT && @course.learning?(current_user.id)
end
diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb
index 3be35345e..28b5d84ef 100644
--- a/app/controllers/exercises_controller.rb
+++ b/app/controllers/exercises_controller.rb
@@ -25,85 +25,83 @@ class ExercisesController < ApplicationController
include ExercisesHelper
def index
- ActiveRecord::Base.transaction do
- begin
- # 按发布时间或创建时间排序
- @exercises_all = @course.exercises
- member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
- @current_user_ = current_user
-
- # 课堂的学生人数
- @course_all_members = @course.students #当前课堂的全部学生
- @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
-
- # exercises的不同用户群体的显示
- if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
- @is_teacher_or = 1
- @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
- elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的
- @is_teacher_or = 2
- @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0
- if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
- @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : []
- else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
- # 已发布 当前用户班级分组的 试卷id
- not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id)
- @exercises = member_show_exercises.where.not(id: not_exercise_ids)
- end
- else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
- @is_teacher_or = 0
- @exercises = member_show_exercises.unified_setting
+ begin
+ # 按发布时间或创建时间排序
+ @exercises_all = @course.exercises
+ member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷
+ @current_user_ = current_user
+
+ # 课堂的学生人数
+ @course_all_members = @course.students #当前课堂的全部学生
+ @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生
+
+ # exercises的不同用户群体的显示
+ if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教
+ @is_teacher_or = 1
+ @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同)
+ elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的
+ @is_teacher_or = 2
+ @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0
+ if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的)
+ @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : []
+ else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
+ # 已发布 当前用户班级分组的 试卷id
+ not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id)
+ @exercises = member_show_exercises.where.not(id: not_exercise_ids)
end
+ else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
+ @is_teacher_or = 0
+ @exercises = member_show_exercises.unified_setting
+ end
- if @exercises.size > 0
- if params[:type].present?
- choose_type = params[:type].to_i
- ex_setting_ids = []
- if @is_teacher_or != 2
- @exercises = @exercises.where("exercise_status = #{choose_type}")
- else
- case choose_type
- when 1
- ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id)
- when 2
- ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}")
- .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id)
- when 3
- ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id)
- end
- unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id)
- ex_ids = (ex_setting_ids + unified_setting_ids).uniq
- @exercises = @exercises.where(id: ex_ids)
+ if @exercises.size > 0
+ if params[:type].present?
+ choose_type = params[:type].to_i
+ ex_setting_ids = []
+ if @is_teacher_or != 2
+ @exercises = @exercises.where("exercise_status = #{choose_type}")
+ else
+ case choose_type
+ when 1
+ ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id)
+ when 2
+ ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}")
+ .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id)
+ when 3
+ ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id)
end
+ unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id)
+ ex_ids = (ex_setting_ids + unified_setting_ids).uniq
+ @exercises = @exercises.where(id: ex_ids)
end
+ end
- if params[:search].present?
- search_type = params[:search].to_s.strip
- @exercises = @exercises.exercise_search(search_type)
- end
-
- @exercises_select_count = @exercises.size # 全部页面,需返回
- @exercises = @exercises.distinct.order( "IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC") #出现错误
-
- # 分页
- @page = params[:page] || 1
- @limit = params[:limit] || 15
- @exercises = @exercises.page(@page).per(@limit)
- @exercises = @exercises&.includes(:published_settings)
- else
- @exercises = []
+ if params[:search].present?
+ search_type = params[:search].to_s.strip
+ @exercises = @exercises.exercise_search(search_type)
end
- @course_all_members_count = @course_all_members.size #当前课堂的学生数
- @exercises_count = @exercises_all.size # 全部页面,需返回
- @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
- @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的
+ @exercises_select_count = @exercises.size # 全部页面,需返回
+ @exercises = @exercises.distinct.order( "IF(ISNULL(publish_time),0,1), publish_time DESC,created_at DESC") #出现错误
- rescue Exception => e
- uid_logger_error(e.message)
- tip_exception(e.message)
- raise ActiveRecord::Rollback
+ # 分页
+ @page = params[:page] || 1
+ @limit = params[:limit] || 15
+ @exercises = @exercises.page(@page).per(@limit)
+ @exercises = @exercises&.includes(:published_settings)
+ else
+ @exercises = []
end
+
+ @course_all_members_count = @course_all_members.size #当前课堂的学生数
+ @exercises_count = @exercises_all.size # 全部页面,需返回
+ @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数
+ @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的
+
+ rescue Exception => e
+ uid_logger_error(e.message)
+ tip_exception(e.message)
+ raise ActiveRecord::Rollback
end
end
diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb
index b0b072f83..0abd3c362 100644
--- a/app/controllers/stages_controller.rb
+++ b/app/controllers/stages_controller.rb
@@ -6,7 +6,8 @@ class StagesController < ApplicationController
def index
@user = current_user
- @stages = @subject.stages
+ @stages = @subject.stages.includes(:shixuns)
+ @myshixuns = @user.myshixuns.where(shixun_id: @subject.stage_shixuns.pluck(:shixun_id))
end
def create
diff --git a/app/helpers/stages_helper.rb b/app/helpers/stages_helper.rb
index e0df514e3..93c466c46 100644
--- a/app/helpers/stages_helper.rb
+++ b/app/helpers/stages_helper.rb
@@ -1,8 +1,8 @@
module StagesHelper
# 章节实训的通关情况
- def stage_myshixun_status shixun, user
- myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).take
+ def stage_myshixun_status myshixun
+ # myshixun = Myshixun.where(user_id: user.id, shixun_id: shixun.id).take
myshixun.try(:status) == 1 ? 1 : 0
end
diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder
index b48cd9e23..95b44238c 100644
--- a/app/views/courses/online_learning.json.jbuilder
+++ b/app/views/courses/online_learning.json.jbuilder
@@ -1,5 +1,5 @@
json.stages @stages do |stage|
- json.partial! 'stages/stage', locals: {stage: stage, user:@user, subject:@subject}
+ json.partial! 'stages/stage', locals: {stage: stage, user: @user, subject: @subject, myshixuns: @myshixuns}
end
# json.description @subject&.description
diff --git a/app/views/stages/_stage.json.jbuilder b/app/views/stages/_stage.json.jbuilder
index db00ad844..e5d2be82d 100644
--- a/app/views/stages/_stage.json.jbuilder
+++ b/app/views/stages/_stage.json.jbuilder
@@ -15,7 +15,7 @@ json.shixuns_list do
json.shixun_name shixun.name
json.shixun_hidden shixun.hidden
json.identifier shixun.identifier
- json.complete_status stage_myshixun_status(shixun, user)
+ json.complete_status stage_myshixun_status(myshixuns.select{|ms| ms.shixun_id == shixun.id}.first)
json.shixun_status stage_shixun_status(subject.status, shixun.status, shixun.hidden)
end
end
\ No newline at end of file
diff --git a/app/views/stages/index.json.jbuilder b/app/views/stages/index.json.jbuilder
index d186088c4..b7c61d9cf 100644
--- a/app/views/stages/index.json.jbuilder
+++ b/app/views/stages/index.json.jbuilder
@@ -1,3 +1,3 @@
json.stages @stages do |stage|
- json.partial! 'stage', locals: {stage: stage, user:@user, subject:@subject}
+ json.partial! 'stage', locals: {stage: stage, user: @user, subject: @subject, myshixuns: @myshixuns}
end
\ No newline at end of file
From 3aa2c03d01a75f1fe8be946f01987002e902f878 Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 27 Sep 2019 10:08:54 +0800
Subject: [PATCH 6/8] ecs: fix
---
app/controllers/ecs/course_targets_controller.rb | 4 +++-
app/services/ecs/query_course_evaluation_service.rb | 2 +-
.../shared/_ec_course_evaluation_only.json.jbuilder | 2 +-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/app/controllers/ecs/course_targets_controller.rb b/app/controllers/ecs/course_targets_controller.rb
index 744840c39..e5ac4b36e 100644
--- a/app/controllers/ecs/course_targets_controller.rb
+++ b/app/controllers/ecs/course_targets_controller.rb
@@ -19,7 +19,9 @@ class Ecs::CourseTargetsController < Ecs::CourseBaseController
end
def with_achievement_methods
- @course_targets = current_course.ec_course_targets.includes(:ec_graduation_subitems, :ec_course_achievement_methods)
+ @course_targets = current_course.ec_course_targets
+ .includes(:ec_graduation_subitems,
+ ec_course_achievement_methods: [:ec_course_evaluation, :ec_course_evaluation_subitems])
end
private
diff --git a/app/services/ecs/query_course_evaluation_service.rb b/app/services/ecs/query_course_evaluation_service.rb
index 22e0ce1f4..fd1619076 100644
--- a/app/services/ecs/query_course_evaluation_service.rb
+++ b/app/services/ecs/query_course_evaluation_service.rb
@@ -29,7 +29,7 @@ class Ecs::QueryCourseEvaluationService < ApplicationService
support = subitem.ec_course_supports.find_by(ec_course_id: ec_course.id)
- weight = support.weights.to_f
+ weight = support&.weights.to_f
objective_achievement = (weight * ec_course.ec_year.calculation_value.to_f).round(3)
target_total_rates = 0
diff --git a/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder b/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
index 776d446f7..010109524 100644
--- a/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
+++ b/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
@@ -1 +1 @@
-json.extract! ec_course_evaluation, :id, :name, :evaluation_count, :status
+json.extract! ec_course_evaluation, :id, :name, :evluation_count, :status
From 89aed376b890965526c3c7755b9344823742518b Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 27 Sep 2019 10:11:13 +0800
Subject: [PATCH 7/8] fix ecs column name
---
app/models/ec_course_evaluation.rb | 1 +
.../shared/_ec_course_evaluation_only.json.jbuilder | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/app/models/ec_course_evaluation.rb b/app/models/ec_course_evaluation.rb
index 6b778de66..b3398d647 100644
--- a/app/models/ec_course_evaluation.rb
+++ b/app/models/ec_course_evaluation.rb
@@ -11,6 +11,7 @@ class EcCourseEvaluation < ApplicationRecord
enum score_type: { detail: 1, average: 2 }, _suffix: :score_type # :detail_score_type?, :average_score_type?
accepts_nested_attributes_for :ec_course_evaluation_subitems, allow_destroy: true
+ alias_method :evaluation_count, :evluation_count
def imported?
import_status?
diff --git a/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder b/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
index 010109524..776d446f7 100644
--- a/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
+++ b/app/views/ecs/course_evaluations/shared/_ec_course_evaluation_only.json.jbuilder
@@ -1 +1 @@
-json.extract! ec_course_evaluation, :id, :name, :evluation_count, :status
+json.extract! ec_course_evaluation, :id, :name, :evaluation_count, :status
From 4e8e88386df006a0f8c78f2d37ae8f82e898a0cb Mon Sep 17 00:00:00 2001
From: p31729568
Date: Fri, 27 Sep 2019 10:13:56 +0800
Subject: [PATCH 8/8] fix
---
app/models/ec_course_evaluation.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/ec_course_evaluation.rb b/app/models/ec_course_evaluation.rb
index b3398d647..e96f1c98b 100644
--- a/app/models/ec_course_evaluation.rb
+++ b/app/models/ec_course_evaluation.rb
@@ -11,7 +11,7 @@ class EcCourseEvaluation < ApplicationRecord
enum score_type: { detail: 1, average: 2 }, _suffix: :score_type # :detail_score_type?, :average_score_type?
accepts_nested_attributes_for :ec_course_evaluation_subitems, allow_destroy: true
- alias_method :evaluation_count, :evluation_count
+ alias_attribute :evaluation_count, :evluation_count
def imported?
import_status?