Merge branch 'dev_daiao' into dev_aliyun

chromesetting
daiao 5 years ago
commit 102004101c

@ -0,0 +1,2 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

@ -0,0 +1,3 @@
// Place all the styles related to the comments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@ -0,0 +1,59 @@
class CommentsController < ApplicationController
before_action :find_hack
before_action :require_login
# 评论
def create
begin
@discuss = @hack.discusses.new(comment_params) # 管理员回复的能够显示
@discuss.hidden = false
@discuss.user_id = current_user.id
@discuss.save!
rescue Exception => e
uid_logger_error("create discuss failed : #{e.message}")
render_error("评论异常")
end
end
# 回复
def reply
begin
@discuss = @hack.discusses.new(reply_params)
@discuss.hidden = false
@discuss.user_id = current_user.id
@discuss.root_id = params[:parent_id]
@discuss.save!
rescue Exception => e
uid_logger_error("reply discuss failed : #{e.message}")
render_error("回复评论异常")
end
end
# 列表
def index
disscusses = @hack.disscusses.where(:root_id => nil)
@disscuss_count = disscusses.count
@disscusses= paginate disscusses
end
# 删除
def destroy
@hack.discusses.find_by(id: params[:id]).destroy
render_ok
end
private
def find_hack
@hack = Hack.find_by_identifier params[:identifier]
end
def comment_params
params.require(:comments).permit(:content)
end
def reply_params
params.require(:comments).permit(:content, :parent_id)
end
end

@ -1,12 +1,13 @@
class HackUserLastestCodesController < ApplicationController
before_action :require_login, except: [:listen_result]
before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code, :listen_result, :result]
before_action :find_my_hack, only: [:show, :code_debug, :code_submit, :update_code,
:listen_result, :result, :submit_records]
before_action :update_user_hack_status, only: [:code_debug, :code_submit]
before_action :require_auth_identity, only: [:update_code]
before_action :require_manager_identity, only: [:update_code]
def show
@my_hack.update_attribute(:status, 0) if @my_hack.status == 1
@my_hack.update_attribute(:submit_status, 0) if @my_hack.submit_status == 1
end
def update_code
@ -33,8 +34,26 @@ class HackUserLastestCodesController < ApplicationController
# 提交结果显示
def result
return if @my_hack.status == 1
if @my_hack.submit_status == 1
render json: {status:0, message: "正在评测中"}
else
@mode = params[:mode]
@result =
if @mode == "submit"
@my_hack.hack_user_codes.last
elsif @mode == "debug"
@my_hack.hack_user_debug
end
end
end
# 提交记录
def submit_records;end
# 提交记录详情
def record_detail
@hack_user = HackUserCode.find params[:id]
end
# 接收中间件返回结果接口
@ -60,7 +79,7 @@ class HackUserLastestCodesController < ApplicationController
if ojEvaResult['execMode'] == "debug"
save_debug_data ds_params
elsif ojEvaResult['execMode'] == "submit"
save_submit_data ds_params
save_submit_data ds_params.merge(expected_output: testCase['expectedOutput'])
end
# 评测完成后,还原评测中的状态
@my_hack.update_attribute(:submit_status, 0)
@ -132,7 +151,7 @@ class HackUserLastestCodesController < ApplicationController
RewardExperienceService.call(@my_hack.user, reward_attrs)
# 评测完成更新通过数
@hack.increment!(:pass_num)
@my_hack.update_attribute(:passed, true)
@my_hack.update_attributes(passed: true, passed_time: Time.now)
end
end
# 创建用户评测记录

@ -0,0 +1,2 @@
module CommentsHelper
end

@ -8,6 +8,7 @@ class Hack < ApplicationRecord
# 代码
has_many :hack_codes, :dependent => :destroy
has_many :hack_user_lastest_codes, :dependent => :destroy
has_many :discusses, as: :dis, dependent: :destroy
belongs_to :user
scope :published, -> { where(status: 1) }

@ -2,6 +2,7 @@ class HackUserLastestCode < ApplicationRecord
# passed 用户之前评测是否通过
# status: 最新评测状态: -1测试用例结果不匹配; 0: 评测通过; ;2 评测超时;3 创建pod失败; 4 编译失败;5 执行失败
# submit_status: 0: 可以评测, 1评测中
# passed_time:第一次通关的时间
# 编程题最新代码
belongs_to :hack, counter_cache: true
belongs_to :user

@ -0,0 +1,12 @@
json.id discuss.id
json.content content_safe(discuss.content)
json.time time_from_now(discuss.created_at)
json.position discuss.position
json.hack_id discuss.dis_id
# 主贴和回复有一些不同点
if discuss.parent_id
json.can_delete discuss.can_deleted?(current_user)
else
json.praise_count discuss.praises_count
json.user_praise discuss.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0
end

@ -0,0 +1,4 @@
json.discuss @discuss
json.author do
json.partial! 'users/user', user: @discuss.user
end

@ -0,0 +1,7 @@
json.disscuss_count @disscuss_count
json.comments @discusses do |discuss|
json.partial! 'comments/discuss', locals: { discuss: discuss}
json.children discuss.child_discuss(current_user) do |c_d|
json.partial! 'comments/discuss', locals: { discuss: c_d }
end
end

@ -0,0 +1,2 @@
json.(@hack_user, :id, :status, :error_line, :error_msg, :expected_output,
:input, :output, :execute_time, :execute_memory)

@ -0,0 +1,7 @@
json.(@result, :id, :status, :error_line, :error_msg,
:input, :output, :execute_time, :execute_memory)
# 提交模式多了一个预计输出
if @mode == "submit"
json.expected_output @result.expected_output
end

@ -0,0 +1,3 @@
json.array! @my_hack.hack_user_codes do |hack_user|
json.(hack_user, :id, :created_at, :status, :execute_time, :execute_memory)
end

@ -44,6 +44,7 @@ Rails.application.routes.draw do
get :start
get :result
end
resources :comments
end
resources :hack_user_lastest_codes, path: :myproblems, param: :identifier do

@ -0,0 +1,6 @@
class RemovePassTimeForHackUserLastestCodes < ActiveRecord::Migration[5.2]
def change
remove_column :hack_user_lastest_codes, :pass_time
add_column :hack_user_codes, :expected_output, :text
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe CommentsController, type: :controller do
end

@ -0,0 +1,15 @@
require 'rails_helper'
# Specs in this file have access to a helper object that includes
# the CommentsHelper. For example:
#
# describe CommentsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
RSpec.describe CommentsHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save