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