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
|
@ -0,0 +1,2 @@
|
||||
module CommentsHelper
|
||||
end
|
@ -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 @@
|
||||
json.discuss @discuss
|
@ -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
|
@ -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…
Reference in new issue