From 9674838baf50d5caa31a4af7069996564703d8cb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 29 Aug 2019 16:50:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=88=86=E7=8F=AD?= =?UTF-8?q?=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190829084147_migrate_course_group_position.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/migrate/20190829084147_migrate_course_group_position.rb diff --git a/db/migrate/20190829084147_migrate_course_group_position.rb b/db/migrate/20190829084147_migrate_course_group_position.rb new file mode 100644 index 000000000..3a71baae4 --- /dev/null +++ b/db/migrate/20190829084147_migrate_course_group_position.rb @@ -0,0 +1,11 @@ +class MigrateCourseGroupPosition < ActiveRecord::Migration[5.2] + def change + Course.all.each do |course| + if course.course_groups.exists?(position: 0) + course.course_groups.each_with_index do |group, index| + group.update_attributes(position: index+1) + end + end + end + end +end From 32d72e243cedaa6a2116eb9353e502144312c2e8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 29 Aug 2019 17:06:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/question_banks_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/question_banks_controller.rb b/app/controllers/users/question_banks_controller.rb index e966b67e9..1f51b701c 100644 --- a/app/controllers/users/question_banks_controller.rb +++ b/app/controllers/users/question_banks_controller.rb @@ -18,8 +18,8 @@ class Users::QuestionBanksController < Users::BaseController def load_question_banks_solve_count question_bank_ids = @question_banks.map(&:id) @solve_count_map = - case params[:category] - when 'common', 'group' then + case params[:object_type] + when 'normal', 'group' then StudentWork.where(is_delete: false, work_status: [1, 2, 3]).joins(:homework_common) .where(homework_commons: { homework_bank_id: question_bank_ids }) .group('homework_commons.homework_bank_id').count @@ -42,14 +42,14 @@ class Users::QuestionBanksController < Users::BaseController end def query_params - params.permit(:type, :category, :course_list_id, :sort_by, :sort_direction) + params.permit(:type, :object_type, :course_list_id, :sort_by, :sort_direction) end def check_query_params! params[:type] = 'personal' if params[:type].blank? || !%w(personal publicly).include?(params[:type]) - if params[:category].blank? || !%w(common group exercise poll gtask gtopic).include?(params[:category]) - params[:category] = 'common' + if params[:object_type].blank? || !%w(normal group exercise poll gtask gtopic).include?(params[:object_type]) + params[:object_type] = 'normal' end if params[:sort_by].blank? || !%w(updated_at name contributor).include?(params[:sort_by]) From 87a53a5560861e373908b0cf49206b6874c04cf7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 29 Aug 2019 17:10:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/users/question_bank_service.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/users/question_bank_service.rb b/app/services/users/question_bank_service.rb index b17073a4f..7e640c6a5 100644 --- a/app/services/users/question_bank_service.rb +++ b/app/services/users/question_bank_service.rb @@ -22,8 +22,8 @@ class Users::QuestionBankService course_lists = CourseList.joins(relation_name).where.not(relation_name => { id: nil }) category_condition = - case params[:category] - when 'common' then { homework_type: 1 } + case params[:object_type] + when 'normal' then { homework_type: 1 } when 'group' then { homework_type: 3 } when 'exercise' then { container_type: 'Exercise' } when 'poll' then { container_type: 'Poll' } @@ -47,8 +47,8 @@ class Users::QuestionBankService def class_name @_class_name ||= begin - case params[:category] - when 'common', 'group' then 'HomeworkBank' + case params[:object_type] + when 'normal', 'group' then 'HomeworkBank' when 'exercise', 'poll' then 'ExerciseBank' when 'gtask' then 'GtaskBank' when 'gtopic' then 'GtopicBank' @@ -58,8 +58,8 @@ class Users::QuestionBankService end def category_filter(relations) - case params[:category] - when 'common' then + case params[:object_type] + when 'normal' then relations.where(homework_type: 1) when 'group' then relations.where(homework_type: 3)