@ -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,67 @@
|
||||
module Weapps::CoursesHelper
|
||||
require 'chinese_pinyin'
|
||||
|
||||
def teacher_list teachers
|
||||
data = []
|
||||
teachers.each do |teacher|
|
||||
if teacher.user.present?
|
||||
teacher_user = teacher.user
|
||||
name = teacher_user.real_name
|
||||
role = teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
item = {name: name, course_member_id: teacher.id, login: teacher_user.login, user_id: teacher.user_id, role: role,
|
||||
school: teacher_user.school_name, image_url: url_to_avatar(teacher_user)}
|
||||
pinyin = Pinyin.t(name.strip, splitter: '')
|
||||
first_char = pinyin[0]
|
||||
letter = first_letter first_char
|
||||
if data.pluck(:letter).include?(letter)
|
||||
data.select{|a|a[:letter]==letter}.first[:items] << item
|
||||
else
|
||||
data << {letter: letter, items: [item]}
|
||||
end
|
||||
end
|
||||
end
|
||||
data = data.sort do |a, b|
|
||||
[a[:letter]] <=> [b[:letter]]
|
||||
end
|
||||
data.push(data.shift) if data.select{|a|a[:letter]=='#'}.first.present? # '#'排在最后
|
||||
return data
|
||||
end
|
||||
|
||||
|
||||
def student_list students, excellent
|
||||
data = []
|
||||
students.each do |student|
|
||||
if student.user.present?
|
||||
student_user = student.user
|
||||
name = student_user.real_name
|
||||
phone = excellent ? "" : student_user.hidden_phone
|
||||
item = {name: name, course_member_id: student.id, login: student_user.login, user_id: student.user_id,
|
||||
student_id: student_user.student_id, image_url: url_to_avatar(student_user), phone: phone}
|
||||
pinyin = Pinyin.t(name.strip, splitter: '')
|
||||
first_char = pinyin[0]
|
||||
letter = first_letter first_char
|
||||
if data.pluck(:letter).include?(letter)
|
||||
data.select{|a|a[:letter]==letter}.first[:items] << item
|
||||
else
|
||||
data << {letter: letter, items: [item]}
|
||||
end
|
||||
end
|
||||
end
|
||||
data = data.sort do |a, b|
|
||||
[a[:letter]] <=> [b[:letter]]
|
||||
end
|
||||
data.push(data.shift) if data.select{|a|a[:letter]=='#'}.first.present? # '#'排在最后
|
||||
return data
|
||||
end
|
||||
|
||||
def first_letter char
|
||||
if char.ord >= 97 && char.ord <= 122
|
||||
letter = (char.ord - 32).chr.to_s
|
||||
elsif char.ord >= 65 && char.ord <= 90
|
||||
letter = char
|
||||
else
|
||||
letter = '#'
|
||||
end
|
||||
letter
|
||||
end
|
||||
end
|
@ -0,0 +1,10 @@
|
||||
class UpdateShixunWorkScoreJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(homework_id)
|
||||
homework = HomeworkCommon.find_by(id: homework_id)
|
||||
return if homework.blank?
|
||||
|
||||
homework.update_homework_work_score
|
||||
end
|
||||
end
|
@ -1,4 +1,6 @@
|
||||
class HackSet < ApplicationRecord
|
||||
validates :input, presence: { message: "测试集输入不能为空" }
|
||||
validates :output, uniqueness: { message: "测试集输出不能为空" }
|
||||
# 编程题测试集
|
||||
belongs_to :hack
|
||||
end
|
||||
|
@ -0,0 +1,11 @@
|
||||
json.id discuss.id
|
||||
json.content content_safe(discuss.content)
|
||||
json.time time_from_now(discuss.created_at)
|
||||
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
|
@ -1,12 +1,2 @@
|
||||
json.students do
|
||||
json.array! @students do |student|
|
||||
json.user_id student.user_id
|
||||
json.login student.user.try(:login)
|
||||
json.name student.user.try(:real_name)
|
||||
json.student_id student.user.try(:student_id)
|
||||
json.course_member_id student.id
|
||||
json.user_phone @course.excellent ? "" : student.user.hidden_phone
|
||||
json.image_url url_to_avatar(student.user)
|
||||
end
|
||||
end
|
||||
json.students student_list @students, @course.excellent
|
||||
json.students_count @students_count
|
@ -1,16 +1,3 @@
|
||||
json.teacher_list do
|
||||
json.array! @teacher_list do |teacher|
|
||||
json.course_member_id teacher.id
|
||||
json.name teacher.user.real_name
|
||||
json.login teacher.user.login
|
||||
json.user_id teacher.user.id
|
||||
json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教"
|
||||
json.school teacher.user&.school_name
|
||||
json.image_url url_to_avatar(teacher.user)
|
||||
# if @user_course_identity < Course::ASSISTANT_PROFESSOR
|
||||
# json.member_roles teacher.user.course_role(@course)
|
||||
# end
|
||||
end
|
||||
end
|
||||
json.teacher_list teacher_list(@teacher_list)
|
||||
json.teacher_list_size @teacher_list_size
|
||||
json.apply_size @applications_size
|
@ -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 @@
|
||||
class MigrateEffScoreDefault < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :homework_commons, :eff_score, :float, default: 0
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddCodeForhackUserDebugs < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :hack_user_debugs, :code, :text
|
||||
end
|
||||
end
|
@ -0,0 +1,6 @@
|
||||
class ModifyExecuteTimeForHackUserCode < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :hack_user_debugs, :execute_time, :float
|
||||
change_column :hack_user_codes, :execute_time, :float
|
||||
end
|
||||
end
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 674 B After Width: | Height: | Size: 675 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 985 B After Width: | Height: | Size: 987 B |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |