Merge branch 'dev_item_bank' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_item_bank

dev_jupyter
杨树林 5 years ago
commit 74217fffc4

@ -30,10 +30,10 @@ class HacksController < ApplicationController
# 筛选过滤与排序
params_filter_or_order
# 我解决的编程题数
user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed
user_codes = HackUserLastestCode.joins(:hack).mine_hack(current_user).passed
@simple_count = user_codes.where(hacks: {difficult: 1}).count
@medium_count = user_codes.where(hacks: {difficult: 2}).count
@diff_count = user_codes.where(hacks: {difficult: 3}).count
@diff_count = user_codes.where(hacks: {difficult: 3}).count
@pass_count = @simple_count + @medium_count + @diff_count
@hacks_count = @hacks.count("hacks.id")
@ -43,14 +43,21 @@ class HacksController < ApplicationController
def create
begin
logger.info("##########{hack_params}")
tip_exception("一次只能增加50个测试集") if hack_sets_params.size > 50
tip_exception("一次只能增加50个知识点") if params[:tags].size > 50
hack = Hack.new(hack_params)
hack.user_id = current_user.id
hack.identifier = generate_identifier Hack, 8
tag_params =
params[:tags].each do |tag|
{tag_discipline_id: tag}
end
ActiveRecord::Base.transaction do
hack.save!
# 创建测试集与代码
hack.hack_sets.create!(hack_sets_params)
# 新建知识点
hack.tag_discipline_containers.create!(tag_params) if tag_params
hack_codes = hack.hack_codes.new(hack_code_params)
hack_codes.modify_time = Time.now
hack_codes.save!
@ -64,6 +71,13 @@ class HacksController < ApplicationController
def update
begin
# 知识点
tag_discipline_ids = @hack.tag_discipline_containers.pluck(:tag_discipline_id)
new_tag_ids = params[:tags].to_a - tag_discipline_ids
tag_params =
new_tag_ids.each do |tag|
{tag_discipline_id: tag}
end
ActiveRecord::Base.transaction do
@hack.update_attributes!(hack_params)
set_ids = @hack.hack_sets.pluck(:id)
@ -74,6 +88,8 @@ class HacksController < ApplicationController
# 更新代码
code_params = params[:hack_codes][:code] != @hack.code ? hack_code_params.merge(modify_time: Time.now) : hack_code_params
@hack.hack_codes.first.update_attributes!(code_params)
@hack.tag_discipline_containers.create!(tag_params) if tag_params
@hack.tag_discipline_containers.where.not(tag_discipline_id: params[:tags]).destroy_all
end
render_ok
rescue Exception => e
@ -127,9 +143,11 @@ class HacksController < ApplicationController
@hacks = hacks.includes(:hack_sets).page(page).per(limit)
end
def edit;end
def edit;
end
def new;end
def new;
end
def destroy
begin
@ -148,6 +166,7 @@ class HacksController < ApplicationController
end
private
# 实名认证老师,管理员与运营人员权限
def require_teacher_identity
unless current_user.certification_teacher? || admin_or_business?
@ -167,7 +186,7 @@ class HacksController < ApplicationController
end
def hack_params
params.require(:hack).permit(:name, :description, :difficult, :category, :open_or_not, :time_limit, :score)
params.require(:hack).permit(:name, :description, :difficult, :category, :open_or_not, :time_limit, :score, :sub_discipline_id)
end
def hack_sets_params
@ -187,7 +206,7 @@ class HacksController < ApplicationController
end
def param_update_sets sets, all_sets_id
delete_set_ids = all_sets_id - sets.map{|set|set[:id]}
delete_set_ids = all_sets_id - sets.map {|set| set[:id]}
@hack.hack_sets.where(id: delete_set_ids).destroy_all
logger.info("#######sets:#{sets}")
sets.each do |set|
@ -215,7 +234,7 @@ class HacksController < ApplicationController
end
# 难度
if params[:difficult]
hacks = hacks.where(difficult: params[:difficult])
hacks = hacks.where(difficult: params[:difficult])
end
# 状态
if params[:status]

@ -15,8 +15,11 @@ class Hack < ApplicationRecord
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
# 消息
has_many :tidings, as: :container
# 知识点
has_many :tag_discipline_containers, dependent: :destroy
belongs_to :user
belongs_to :sub_discipline
scope :published, -> { where(status: 1) }
scope :unpublish, -> { where(status: 0) }

@ -1,6 +1,7 @@
class SubDiscipline < ApplicationRecord
belongs_to :discipline
has_many :tag_disciplines, dependent: :destroy
has_one :hack
has_many :shixun_tag_disciplines, -> { where("shixun = 1") }, class_name: "TagDiscipline"
has_many :subject_tag_disciplines, -> { where("subject = 1") }, class_name: "TagDiscipline"

@ -1,5 +1,6 @@
class TagDiscipline < ApplicationRecord
belongs_to :sub_discipline
has_many :tag_discipline_containers, dependent: :destroy
def discipline
sub_discipline&.discipline

@ -1,4 +1,4 @@
json.(item, :id, :name, :item_type, :difficulty, :public, :quotes)
json.(item, :name, :item_type, :difficulty, :public, :quotes)
json.analysis item.analysis
json.choices item.item_choices do |choice|
json.choice_text choice.choice_text

@ -1,4 +1,5 @@
json.items @items.each do |item|
json.id item.id
json.partial! "item_banks/item", locals: {item: item}
json.update_time item.updated_at&.strftime("%Y-%m-%d %H:%M")
json.choosed @item_basket_ids.include?(item.id)

@ -0,0 +1,5 @@
class AddSubDisciplineIdForHacks < ActiveRecord::Migration[5.2]
def change
add_column :hacks, :sub_discipline_id, :integer
end
end
Loading…
Cancel
Save