diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index f58fe12bf..bd322d59e 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -57,7 +57,6 @@ class AttachmentsController < ApplicationController @attachment = Attachment.where(disk_filename: disk_filename, author_id: current_user.id, cloud_url: remote_path).first - if @attachment.blank? @attachment = Attachment.new @attachment.filename = upload_file.original_filename @@ -68,9 +67,7 @@ class AttachmentsController < ApplicationController @attachment.author_id = current_user.id @attachment.disk_directory = month_folder @attachment.cloud_url = remote_path - @attachment.container_id = conversion_container_id(params[:container_id], params[:container_type]) - @attachment.container_type = params[:container_type] - @attachment.attachtype = params[:attachtype] + @attachment.disk_directory = save_path @attachment.save! else logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" @@ -94,22 +91,6 @@ class AttachmentsController < ApplicationController end end - # 多文件删除 - def destroy_files - files = Attachment.where(id: params[:id]) - begin - files.each do |file| - file_path = absolute_path(local_path(file)) - file.destroy! - delete_file(file_path) - end - render_ok - rescue => e - uid_logger_error(e.message) - tip_exception(e.message) - end - end - private def find_file @file = @@ -216,11 +197,4 @@ class AttachmentsController < ApplicationController end end - def conversion_container_id id, type - if id.is_a?(String) && type == 'Shixun' - Shixun.find_by_identifier(id).id - else - id - end - end end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 454929dcc..d4f9bd3c8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -458,12 +458,66 @@ class ShixunsController < ApplicationController end # Jupyter数据集 - def jupyter_data_sets + def get_data_sets page = params[:page] || 1 limit = params[:limit] || 10 - data_sets = @shixun.jupyter_data_sets + data_sets = @shixun.data_sets @data_count = data_sets.count @data_sets= data_sets.page(page).per(limit) + @absolute_folder = edu_setting('shixun_folder') + end + + # 实训测试集附件 + def upload_data_sets + upload_file = params["file"] + raise "未上传文件" unless upload_file + folder = edu_setting('shixun_folder') + raise "存储目录未定义" unless folder.present? + rep_name = @shixun.data_sets.pluck(:filename).include?(upload_file.original_filename) + raise "文件名已经存在\"#{upload_file.original_filename}\", 请删除后再上传" if rep_name + tpm_folder = params[:identifier] # 这个是实训的identifier + save_path = File.join(folder, tpm_folder) + ext = file_ext(upload_file.original_filename) + local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) + content_type = upload_file.content_type.presence || 'application/octet-stream' + disk_filename = local_path[save_path.size + 1, local_path.size] + @attachment = Attachment.where(disk_filename: disk_filename, + author_id: current_user.id).first + 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 = tpm_folder + @attachment.cloud_url = remote_path + @attachment.container_id = @shixun.id + @attachment.container_type = @shixun.class.name + @attachment.attachtype = 2 + @attachment.save! + else + logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" + end + render_ok + end + + # 多文件删除 + def destroy_data_sets + files = Attachment.where(id: params[:id]) + shixun_folder= edu_setting("shixun_folder") + begin + files.each do |file| + file_path = "#{shixun_folder}/#{file.relative_path_filename}" + delete_file(file_path) + end + files.destroy_all + render_ok + rescue => e + uid_logger_error(e.message) + tip_exception(e.message) + end end def apply_shixun_mirror @@ -1020,4 +1074,26 @@ private ShixunSecretRepository.create!(repo_name: repo_path.split(".")[0], shixun_id: @shixun.id) end + def file_save_to_local(save_path, temp_file, ext) + unless Dir.exists?(save_path) + FileUtils.mkdir_p(save_path) ##不成功这里会抛异常 + end + + digest = md5_file(temp_file) + digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}" + local_file_path = File.join(save_path, digest) + ext + save_temp_file(temp_file, local_file_path) + + [local_file_path, digest] + end + + def save_temp_file(temp_file, save_file_path) + File.open(save_file_path, 'wb') do |f| + temp_file.rewind + while (buffer = temp_file.read(8192)) + f.write(buffer) + end + end + end + end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f18d9cd2a..ac051428f 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -33,6 +33,10 @@ class Attachment < ApplicationRecord File.join(File.join(Rails.root, "files"), disk_directory.to_s, disk_filename.to_s) end + def relative_path_filename + File.join(disk_directory.to_s, disk_filename.to_s) + end + def title title = filename if container && container.is_a?(StudentWork) && author_id != User.current.id diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 2034c5ea0..404faff29 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -57,7 +57,7 @@ class Shixun < ApplicationRecord has_many :laboratory_shixuns, dependent: :destroy belongs_to :laboratory, optional: true # Jupyter数据集,附件 - has_many :jupyter_data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy + has_many :data_sets, ->{where(attachtype: 2)}, class_name: 'Attachment', as: :container, dependent: :destroy scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/services/shixun_search_service.rb b/app/services/shixun_search_service.rb index 649de87bf..fce8a2fd5 100644 --- a/app/services/shixun_search_service.rb +++ b/app/services/shixun_search_service.rb @@ -25,7 +25,7 @@ class ShixunSearchService < ApplicationService else none_shixun_ids = ShixunSchool.where("school_id != #{User.current.school_id}").pluck(:shixun_id) - @shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0, status: 2, public: 2).or(@shixuns.where(id: current_user.shixuns)) + @shixuns = @shixuns.where.not(id: none_shixun_ids).where(hidden: 0, status: 2, public: 2).or(@shixuns.where(id: User.current.shixuns)) end end diff --git a/app/views/shixuns/jupyter_data_sets.json.jbuilder b/app/views/shixuns/get_data_sets.json.jbuilder similarity index 69% rename from app/views/shixuns/jupyter_data_sets.json.jbuilder rename to app/views/shixuns/get_data_sets.json.jbuilder index ffe419312..20ced2acd 100644 --- a/app/views/shixuns/jupyter_data_sets.json.jbuilder +++ b/app/views/shixuns/get_data_sets.json.jbuilder @@ -5,6 +5,7 @@ json.data_sets do json.author set.author.real_name json.created_on set.created_on json.filesize number_to_human_size(set.filesize) + json.file_path "#{@absolute_folder}/#{set.relative_path_filename}" end end json.data_sets_count @data_count \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 643972b95..3549a3f5f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -284,8 +284,10 @@ Rails.application.routes.draw do get :review_newest_record post :update_permission_setting post :update_learn_setting - get :jupyter_data_sets + get :get_data_sets get :jupyter_exec + post :upload_data_sets + delete :destroy_data_sets end resources :challenges do diff --git a/public/react/src/modules/courses/busyWork/CommonWorkItem.js b/public/react/src/modules/courses/busyWork/CommonWorkItem.js index 75676557a..82e2d2d96 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkItem.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkItem.js @@ -205,15 +205,16 @@ class CommonWorkItem extends Component{ {item.uncommit_count===undefined?"":{item.uncommit_count} 未交} { item.status_time!="" && - + {item.status_time} - - } + } + {/**/} + {/**/} {isAdmin &&
{ this.props.toEditPage(this.props.match.params, item.homework_id) }}>编辑 { this.props.toWorkSettingPage(this.props.match.params, item.homework_id) }}>设置 diff --git a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js index 23f590dcd..1bf7ac181 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunWorkReport.js @@ -366,10 +366,10 @@ class ShixunWorkReport extends Component {

{data&&data.shixun_name}

{/*{this.props.isAdmin()?导出实训报告数据:""}*/} 返回 - {this.props.isAdmin() ? this.confirmysl(`/student_works/${homeworkid}/export_shixun_work_report.pdf`)} - > 导出实训报告数据 : ""} + > 导出实训报告数据 {/*{this.props.isAdmin() ?work_comment_hidden===true? "":this.showAppraiseModal(1)}*/} diff --git a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js index dc59d93ed..f5f06c037 100644 --- a/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js +++ b/public/react/src/modules/courses/shixunHomework/ShixunhomeWorkItem.js @@ -393,21 +393,13 @@ class ShixunhomeWorkItem extends Component{ { discussMessage.time_status===1? - {discussMessage.status_time} - :discussMessage.time_status===2? - {discussMessage.status_time} - :discussMessage.time_status===3? - {discussMessage.status_time} - :discussMessage.time_status===4? - {discussMessage.status_time} - : {discussMessage.status_time} } diff --git a/public/react/src/modules/tpm/TPMDataset.js b/public/react/src/modules/tpm/TPMDataset.js index ed58211f8..3b034a315 100644 --- a/public/react/src/modules/tpm/TPMDataset.js +++ b/public/react/src/modules/tpm/TPMDataset.js @@ -289,31 +289,12 @@ class TPMDataset extends Component { handleChange = (info) => { if(info.file.status == "done" || info.file.status == "uploading" || info.file.status === 'removed'){ let fileList = info.fileList; - - this.setState({ fileList: appendFileSizeToUploadFileAll(fileList), }); if(info.file.status === 'done'){ - console.log("handleChange"); - console.log(info); //done 成功就会调用这个方法 this.getdatas(); - try { - // let datas=this.state.fileListimgs; - // for(var i=0;i