yslnewtiku
parent
cab3a68719
commit
02b6646bd2
@ -1,14 +1,21 @@
|
|||||||
class LibrariesController < ApplicationController
|
class ItemBanksController < ApplicationController
|
||||||
include PaginateHelper
|
include PaginateHelper
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
def index
|
def index
|
||||||
default_sort('updated_at', 'desc')
|
items = ItemBankQuery.call(params)
|
||||||
|
@items_count = items.size
|
||||||
@items = ItemBankQuery.call(params)
|
@items = paginate items.includes(:item_analysis, :user)
|
||||||
@items = paginate courses.includes(:school, :students, :attachments, :homework_commons, teacher: :user_extension)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
item = ItemBank.new(user: current_user)
|
||||||
|
ItemBank::SaveItemService.call(item, form_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def form_params
|
||||||
|
params.permit(:repertoire_id, :sub_repertoire_id, :item_type, :difficulty, :name, tag_repertoire_id: [], choices: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class ItemBank::SaveItemForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :repertoire_id, :sub_repertoire_id, :item_type, :difficulty, :name, :tag_repertoire_id, :choices
|
||||||
|
|
||||||
|
validates :repertoire_id, presence: true
|
||||||
|
validates :sub_repertoire_id, presence: true
|
||||||
|
validates :item_type, presence: true
|
||||||
|
validates :difficulty, presence: true
|
||||||
|
validates :name, presence: true
|
||||||
|
|
||||||
|
|
||||||
|
end
|
@ -1,11 +1,24 @@
|
|||||||
class ItemBank < ApplicationRecord
|
class ItemBank < ApplicationRecord
|
||||||
# difficulty: 1 简单 2 适中 3 困难
|
# difficulty: 1 简单 2 适中 3 困难
|
||||||
# item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
|
# item_type: 0 单选 1 多选 2 判断 3 填空 4 简答 5 实训 6 编程
|
||||||
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
|
# 试卷的问题类型
|
||||||
|
SINGLE = 0 #单选题
|
||||||
|
MULTIPLE = 1 #多选题
|
||||||
|
JUDGMENT = 2 #判断题
|
||||||
|
COMPLETION = 3 # 填空题
|
||||||
|
SUBJECTIVE = 4 # 主观题
|
||||||
|
PRACTICAL = 5 #实训题
|
||||||
|
PROGRAM = 6 #编程题
|
||||||
|
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
belongs_to :sub_repertoire
|
||||||
|
|
||||||
has_one :item_analysis, dependent: :destroy
|
has_one :item_analysis, dependent: :destroy
|
||||||
has_many :item_choices, dependent: :destroy
|
has_many :item_choices, dependent: :destroy
|
||||||
has_many :item_baskets, dependent: :destroy
|
has_many :item_baskets, dependent: :destroy
|
||||||
|
has_many :item_bank_tag_repertoires, dependent: :destroy
|
||||||
|
|
||||||
|
def analysisi
|
||||||
|
item_analysis&.analysis
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
class ItemBankTagRepertoire < ApplicationRecord
|
||||||
|
belongs_to :item_bank
|
||||||
|
belongs_to :tag_repertoire
|
||||||
|
end
|
@ -0,0 +1,33 @@
|
|||||||
|
class ItemBankQuery < ApplicationQuery
|
||||||
|
include CustomSortable
|
||||||
|
attr_reader :params
|
||||||
|
|
||||||
|
sort_columns :updated_at, default_by: :updated_at, default_direction: :desc, default_table: 'item_banks'
|
||||||
|
|
||||||
|
def initialize(params)
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
if params[:public].to_i == 1
|
||||||
|
items = ItemBank.where(public: 1)
|
||||||
|
elsif params[:public].to_i == 0
|
||||||
|
items = ItemBank.where(user_id: User.current.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:tag_repertoire_id].present?
|
||||||
|
items = items.joins(:item_bank_tag_repertoires).where(item_bank_tag_repertoires: {tag_repertoire_id: params[:tag_repertoire_id]})
|
||||||
|
elsif params[:sub_repertoire_id].present?
|
||||||
|
items = items.where(sub_repertoire_id: params[:sub_repertoire_id])
|
||||||
|
elsif params[:repertoire_id].present?
|
||||||
|
items = items.joins(:sub_repertoire).where(sub_repertoires: {repertoire_id: params[:repertoire_id]})
|
||||||
|
end
|
||||||
|
|
||||||
|
items = items.where(item_type: params[:item_type].to_i) if params[:item_type].present?
|
||||||
|
items = items.where(difficulty: params[:difficulty].to_i) if params[:difficulty].present?
|
||||||
|
|
||||||
|
items = items.where("name like ?", "%#{params[:keyword].strip}%") if params[:keyword].present?
|
||||||
|
|
||||||
|
custom_sort(items, params[:sort_by], params[:sort_direction])
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,13 @@
|
|||||||
|
class ItemBank::SaveItemService < ApplicationService
|
||||||
|
attr_reader :item, :params
|
||||||
|
|
||||||
|
def initialize(item, params)
|
||||||
|
@item = item
|
||||||
|
@params = params
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
Competitions::SaveTeamForm.new(params).validate!
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,14 @@
|
|||||||
|
json.items @items.each do |item|
|
||||||
|
json.(item, :id, :name, :item_type, :difficulty, :public, :quotes)
|
||||||
|
json.analysisi item.analysisi
|
||||||
|
json.update_time item.updated_at&.strftime("%Y-%m-%d %H:%M")
|
||||||
|
json.author do
|
||||||
|
json.login item.user&.login
|
||||||
|
json.name item.user&.full_name
|
||||||
|
end
|
||||||
|
json.choices item.item_choices do |choice|
|
||||||
|
json.choice_text choice.choice_text
|
||||||
|
json.is_answer choice.is_answer
|
||||||
|
end
|
||||||
|
end
|
||||||
|
json.items_count @items_count
|
@ -0,0 +1,7 @@
|
|||||||
|
class MigrateItemBankColumn < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
remove_column :item_banks, :curriculum_id
|
||||||
|
remove_column :item_banks, :curriculum_direction_id
|
||||||
|
add_column :item_banks, :sub_repertoire_id, :integer, index: true
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,10 @@
|
|||||||
|
class CreateItemBankTagRepertoires < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :item_bank_tag_repertoires do |t|
|
||||||
|
t.references :item_bank, index: true
|
||||||
|
t.references :tag_repertoire, index: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,7 @@
|
|||||||
|
class ChangeItemBankPublicDefault < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
change_column_default :item_banks, :public, 0
|
||||||
|
change_column_default :item_banks, :quotes, 0
|
||||||
|
change_column_default :item_banks, :difficulty, 1
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,5 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ItemBankTagRepertoire, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in new issue