From 26e6ecba6dc09350e78263d5d3769147421cd5a9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 18:53:56 +0800 Subject: [PATCH 1/2] fix bug --- app/controllers/exercises_controller.rb | 17 +++++++++-------- app/controllers/polls_controller.rb | 2 +- app/models/course.rb | 2 +- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 762c12797..2239f570d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -436,7 +436,7 @@ class ExercisesController < ApplicationController exercise_status = @exercise.get_exercise_status(current_user.id) - if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 + if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @exercise.unified_setting @@ -450,7 +450,7 @@ class ExercisesController < ApplicationController answer_open = params[:answer_open] ? true : false #答案是否公开 # 统一设置或者分班为0,则更新试卷,并删除试卷分组 - if unified_setting || (course_group_ids.count == 0) + if unified_setting || (course_group_ids.size == 0) params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time params_end_time = nil if params[:end_time].blank? @@ -798,12 +798,13 @@ class ExercisesController < ApplicationController if exercise_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? - user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) - if user_course_groups.present? - teacher_course_group_ids = user_course_groups.pluck(:course_group_id) - else - teacher_course_group_ids = @course.course_groups.pluck(:id) - end + # user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) + # if user_course_groups.present? + # teacher_course_group_ids = user_course_groups.pluck(:course_group_id) + # else + # teacher_course_group_ids = @course.course_groups.pluck(:id) + # end + teacher_course_group_ids = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == teacher_course_group_ids.sort #开始为统一设置 exercise.exercise_group_settings.destroy_all new_ex_status = set_exercise_status(exercise.publish_time,Time.now) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 38fa973b5..ae93357cc 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -691,7 +691,7 @@ class PollsController < ApplicationController course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 poll_status = @poll.get_poll_status(current_user.id) - if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 + if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @poll.unified_setting diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..dec8c1b50 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -121,7 +121,7 @@ class Course < ApplicationRecord end #当前老师的班级id - def teacher_course_group_ids(user_id) + def teacher_course_ids(user_id) course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 if course_teacher_member.blank? if none_group_count > 0 #有未分班的,则发布到未发布分班 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e2623c692..b3feec12c 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -66,7 +66,7 @@ class Exercise < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def common_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布分班 un_group_ids = [0] diff --git a/app/models/poll.rb b/app/models/poll.rb index fd9093fcc..b498eda4e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -62,7 +62,7 @@ class Poll < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布 un_group_ids = [0] From 45a0f6cf2c3d42793b01d2bf99467d687c2ac777 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 20 Jun 2019 19:04:05 +0800 Subject: [PATCH 2/2] modify school list apu --- app/controllers/schools_controller.rb | 10 +++++++--- app/views/schools/school_list.json.jbuilder | 1 - .../modules/Courses/coursesPublic/form/SchoolSelect.js | 4 ++-- public/react/src/modules/Courses/new/CoursesNew.js | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 app/views/schools/school_list.json.jbuilder diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 1551091aa..11932be42 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,8 +1,12 @@ class SchoolsController < ApplicationController + def school_list + schools = School.all + search = params[:search].to_s.strip + if search.present? + schools = schools.where('name Like ?', "%#{search}%") + end - def school_list - q = params[:search] ? params[:search].strip : "" - @schools = School.where("name like ?", "%#{q}%").pluck(:name) + render_ok(school_names: schools.pluck(:name)) end end diff --git a/app/views/schools/school_list.json.jbuilder b/app/views/schools/school_list.json.jbuilder deleted file mode 100644 index 1e2c89897..000000000 --- a/app/views/schools/school_list.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.shools_name @schools \ No newline at end of file diff --git a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js index db62c50b6..e1a9062e3 100644 --- a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js +++ b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js @@ -34,9 +34,9 @@ class SchoolSelect extends Component{ } }) .then((response) => { - if (response.data.shools_name) { + if (response.data.school_names) { if (currentValue === value) { - callback(response.data.shools_name); + callback(response.data.school_names); } } }) diff --git a/public/react/src/modules/Courses/new/CoursesNew.js b/public/react/src/modules/Courses/new/CoursesNew.js index d8fb83974..6c0158f21 100644 --- a/public/react/src/modules/Courses/new/CoursesNew.js +++ b/public/react/src/modules/Courses/new/CoursesNew.js @@ -314,7 +314,7 @@ class CoursesNew extends Component { } }).then((result)=>{ this.setState({ - searchlistscholl:result.data.shools_name, + searchlistscholl:result.data.school_names, scholl:value }) this.props.form.setFieldsValue({