Merge remote-tracking branch 'origin/dev_jupyter' into dev_jupyter

chromesetting
杨树明 5 years ago
commit c28cecc3c9

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

@ -469,37 +469,43 @@ class ShixunsController < ApplicationController
# 实训测试集附件 # 实训测试集附件
def upload_data_sets def upload_data_sets
upload_file = params["file"] begin
raise "未上传文件" unless upload_file
folder = edu_setting('shixun_folder') upload_file = params["file"]
raise "存储目录未定义" unless folder.present? raise "未上传文件" unless upload_file
rep_name = @shixun.data_sets.pluck(:filename).include?(upload_file.original_filename) folder = edu_setting('shixun_folder')
raise "文件名已经存在\"#{upload_file.original_filename}\", 请删除后再上传" if rep_name raise "存储目录未定义" unless folder.present?
tpm_folder = params[:identifier] # 这个是实训的identifier rep_name = @shixun.data_sets.pluck(:filename).include?(upload_file.original_filename)
save_path = File.join(folder, tpm_folder) raise "文件名已经存在\"#{upload_file.original_filename}\", 请删除后再上传" if rep_name
ext = file_ext(upload_file.original_filename) tpm_folder = params[:identifier] # 这个是实训的identifier
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) save_path = File.join(folder, tpm_folder)
content_type = upload_file.content_type.presence || 'application/octet-stream' ext = file_ext(upload_file.original_filename)
disk_filename = local_path[save_path.size + 1, local_path.size] local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
@attachment = Attachment.where(disk_filename: disk_filename, content_type = upload_file.content_type.presence || 'application/octet-stream'
author_id: current_user.id).first disk_filename = local_path[save_path.size + 1, local_path.size]
if @attachment.blank? @attachment = Attachment.where(disk_filename: disk_filename,
@attachment = Attachment.new author_id: current_user.id).first
@attachment.filename = upload_file.original_filename if @attachment.blank?
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size] @attachment = Attachment.new
@attachment.filesize = upload_file.tempfile.size @attachment.filename = upload_file.original_filename
@attachment.content_type = content_type @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
@attachment.digest = digest @attachment.filesize = upload_file.tempfile.size
@attachment.author_id = current_user.id @attachment.content_type = content_type
@attachment.disk_directory = tpm_folder @attachment.digest = digest
@attachment.container_id = @shixun.id @attachment.author_id = current_user.id
@attachment.container_type = @shixun.class.name @attachment.disk_directory = tpm_folder
@attachment.attachtype = 2 @attachment.container_id = @shixun.id
@attachment.save! @attachment.container_type = @shixun.class.name
else @attachment.attachtype = 2
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}" @attachment.save!
else
logger.info "文件已存在id = #{@attachment.id}, filename = #{@attachment.filename}"
end
render_ok
rescue => e
uid_logger_error(e.message)
tip_exception(e.message)
end end
render_ok
end end
# 多文件删除 # 多文件删除

@ -84,6 +84,7 @@ class TPMDataset extends Component {
loadingstate:false, loadingstate:false,
checked: false, checked: false,
showmodel:false, showmodel:false,
itemtypebool:false,
} }
} }
@ -304,10 +305,18 @@ class TPMDataset extends Component {
if(info.file.response){ if(info.file.response){
if(info.file.response.status===-1||info.file.response.status==="-1"){ if(info.file.response.status===-1||info.file.response.status==="-1"){
// console.log("准备显示弹框了"); // console.log("准备显示弹框了");
// console.log(info); // console.log(info);false
let itemtype=-1;
try {
itemtype=info.file.response.message.indexOf('文件名已经存在'.toLowerCase());
}catch (e) {
}
this.setState({ this.setState({
showmodel:true, showmodel:true,
tittest:info.file.response.message, tittest:info.file.response.message,
itemtypebool:itemtype>-1?true:itemtype<=-1?false:false,
}) })
} }
} }
@ -466,7 +475,7 @@ class TPMDataset extends Component {
<div className="with65 fl edu-back-white commentsDelegateParent"> <div className="with65 fl edu-back-white commentsDelegateParent">
{ {
this.state.showmodel===true? this.state.showmodel===true?
<Tpmdatasetmodel modalCancel={()=>this.ModalSave()} tittest={this.state.tittest} modalsType={this.state.showmodel}></Tpmdatasetmodel> <Tpmdatasetmodel itemtypebool={this.state.itemtypebool} modalCancel={()=>this.ModalSave()} tittest={this.state.tittest} modalsType={this.state.showmodel}></Tpmdatasetmodel>
:"" :""
} }
<TPMNav <TPMNav

@ -214,7 +214,7 @@ class Challengesjupyter extends Component {
this.state.jupyter_url === null? this.state.jupyter_url === null?
<div className="mt50 intermediatecenter juplbool"> <div className="mt50 intermediatecenter juplbool">
<span className="icon iconfontysl icon-jiazaishibai1"></span> <span className="icon iconfontysl icon-jiazaishibai1"></span>
<p className="intermediatecenter sortinxdirection mt5 juplboolp"><p className="colorbluetest">加载实训出错是否</p><p className="colorbluetwo" onClick={()=>this.updatamakedowns()}></p></p> <p className="intermediatecenter sortinxdirection mt5 juplboolp"><p className="colorbluetest">加载实训失败</p><p className="colorbluetwo" onClick={()=>this.updatamakedowns()}></p></p>
</div> </div>

@ -34,7 +34,13 @@ class Tpmdatasetmodel extends Component {
width="530px" width="530px"
> >
<div className="educouddiv intermediatecenter"> <div className="educouddiv intermediatecenter">
<div className={"tabeltext-alignleftysl mt10"}><p>文件名重复</p></div> {
this.props.itemtypebool===true?
<div className={"tabeltext-alignleftysl mt10"}><p>文件名重复</p></div>
:""
}
<div className={"tabeltext-alignleftysltwo mt10"}><p>{this.props.tittest}</p></div> <div className={"tabeltext-alignleftysltwo mt10"}><p>{this.props.tittest}</p></div>
<div className="clearfix mt30 edu-txt-center task-btn-blues"> <div className="clearfix mt30 edu-txt-center task-btn-blues">
{/*<a className="task-btn mr30" onClick={()=>this.modalCancel()}>先试试看</a>*/} {/*<a className="task-btn mr30" onClick={()=>this.modalCancel()}>先试试看</a>*/}

Loading…
Cancel
Save