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]) 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) 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