modify code style

dev_course
p31729568 6 years ago
parent f40f8ae042
commit 07e3cf3c86

@ -25,51 +25,49 @@ class AttachmentsController < ApplicationController
# 2. 上传到云 # 2. 上传到云
upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称
uid_logger("#########################file_params####{params["#{params[: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?
month_folder = current_month_folder folder = edu_setting('attachment_folder')
save_path = File.join(folder, month_folder) raise "存储目录未定义" unless folder.present?
ext = file_ext(upload_file.original_filename) month_folder = current_month_folder
save_path = File.join(folder, month_folder)
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) ext = file_ext(upload_file.original_filename)
content_type = upload_file.content_type.presence || 'application/octet-stream' local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) content_type = upload_file.content_type.presence || 'application/octet-stream'
logger.info "local_path: #{local_path}" remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
logger.info "remote_path: #{remote_path}"
logger.info "local_path: #{local_path}"
logger.info "remote_path: #{remote_path}"
disk_filename = local_path[save_path.size + 1, local_path.size]
#存数据库
#
@attachment = Attachment.where(disk_filename: disk_filename,
author_id: current_user.id,
cloud_url: remote_path).first
unless @attachment.present? disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment = Attachment.new #存数据库
@attachment.filename = upload_file.original_filename #
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size] @attachment = Attachment.where(disk_filename: disk_filename,
@attachment.filesize = upload_file.tempfile.size author_id: current_user.id,
@attachment.content_type = content_type cloud_url: remote_path).first
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
render_json if @attachment.blank?
@attachment = Attachment.new
@attachment.filename = upload_file.original_filename
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.filesize = upload_file.tempfile.size
@attachment.content_type = content_type
@attachment.digest = digest
@attachment.author_id = current_user.id
@attachment.disk_directory = month_folder
@attachment.cloud_url = remote_path
@attachment.save!
else else
raise "未上传文件" logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end end
render_json
end end
def destroy def destroy

@ -9,46 +9,39 @@ class BoardsController < ApplicationController
end end
def show def show
end
def new
end end
def create def create
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin board = @course.course_board
board = @course.course_board new_board = Board.new(board_params)
new_board = Board.new(board_params) new_board.course_id = @course.id
new_board.course_id = @course.id new_board.project_id = -1
new_board.project_id = -1 new_board.parent_id = board.try(:id)
new_board.parent_id = board.try(:id) new_board.position = board.children.count + 1
new_board.position = board.children.count + 1 new_board.save!
new_board.save!
normal_status(0, "添加成功")
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end end
normal_status(0, "添加成功")
end end
# 子目录的拖动 # 子目录的拖动
def move_category def move_category
tip_exception("移动失败") if params[:position].blank? 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
course_board = @course.course_board
ActiveRecord::Base.transaction do
if params[:position].to_i < @board.position 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 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 end
@board.update_attributes(position: params[:position]) @board.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
end end
normal_status(0, "移动成功")
end end
def destroy def destroy

Loading…
Cancel
Save