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

dev_course
SylorHuang 5 years ago
commit 0dd5716cbd

@ -25,7 +25,8 @@ class AttachmentsController < ApplicationController
# 2. 上传到云
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
if upload_file
raise "未上传文件" unless upload_file
folder = edu_setting('attachment_folder')
raise "存储目录未定义" unless folder.present?
@ -51,7 +52,7 @@ class AttachmentsController < ApplicationController
author_id: current_user.id,
cloud_url: remote_path).first
unless @attachment.present?
if @attachment.blank?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@ -67,9 +68,6 @@ class AttachmentsController < ApplicationController
end
render_json
else
raise "未上传文件"
end
end
def destroy

@ -9,15 +9,10 @@ class BoardsController < ApplicationController
end
def show
end
def new
end
def create
ActiveRecord::Base.transaction do
begin
board = @course.course_board
new_board = Board.new(board_params)
new_board.course_id = @course.id
@ -25,30 +20,28 @@ class BoardsController < ApplicationController
new_board.parent_id = board.try(:id)
new_board.position = board.children.count + 1
new_board.save!
normal_status(0, "添加成功")
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
normal_status(0, "添加成功")
end
# 子目录的拖动
def move_category
tip_exception("移动失败") if params[:position].blank?
unless params[:position].to_i == @board.position
return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position
course_board = @course.course_board
ActiveRecord::Base.transaction do
if params[:position].to_i < @board.position
course_board.children.where("position < #{@board.position} and position >= ?", params[:position]).update_all("position = position + 1")
course_board.children.where("position < ? and position >= ?", @board.position, params[:position])
.update_all("position = position + 1")
else
course_board.children.where("position > #{@board.position} and position <= ?", params[:position]).update_all("position = position - 1")
course_board.children.where("position > ? and position <= ?", @board.position, params[:position])
.update_all("position = position - 1")
end
@board.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
end
normal_status(0, "移动成功")
end
def destroy

@ -43,9 +43,15 @@ class MessagesController < ApplicationController
@page_size = params[:page_size] || 10
@current_user = current_user || nil
@messages = @message.children.preload_messages
@messages = @message.children.preload_messages.includes(:message_detail, :praise_treads)
@messages = @messages.ordered(sort: 1) unless @message.parent_id.nil?
@user_course_identity = current_user.course_identity(@message.board.course)
case @user_course_identity
when 5 || 6 || 7
@messages = @messages.visible
end
@messages = @messages.page(@page).per(@page_size)
end

@ -18,7 +18,7 @@ class Message < ApplicationRecord
scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子
scope :reply_nodes, -> { where("parent_id IS NOT NULL") }
scope :visible, -> { where(is_hidden: false)}
scope :visible, -> { where(is_hidden: false) }
scope :by_user, ->(user) { visible if user.nil? || !user.admin? }
scope :preload_messages, -> { includes(:author, :message_detail) }
scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) }

@ -1,6 +1,6 @@
json.partial! "commons/success"
json.data do
json.user_course_identity @current_user.course_identity(@message.board.course)
json.user_course_identity @user_course_identity
json.id @message.id
json.total_count @messages.total_count
json.total_replies_count @message.total_replies_count

Loading…
Cancel
Save