From 331f3bdea1ba1a3b5f910ec656396d353f797a88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com>
Date: Fri, 13 Dec 2019 15:42:22 +0800
Subject: [PATCH 1/6] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=91=E5=B8=83?=
=?UTF-8?q?=E6=97=B6=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../modules/courses/busyWork/CommonWorkItem.js | 15 ++++++++-------
.../courses/shixunHomework/ShixunhomeWorkItem.js | 8 --------
2 files changed, 8 insertions(+), 15 deletions(-)
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/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}
}
From 75634252cea448b34efb1efa376b3a95dfdcd3ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com>
Date: Fri, 13 Dec 2019 15:48:17 +0800
Subject: [PATCH 2/6] =?UTF-8?q?=E5=BC=80=E6=94=BE=E5=AE=9E=E8=AE=AD?=
=?UTF-8?q?=E6=8A=A5=E5=91=8A=E5=AF=BC=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/modules/courses/shixunHomework/ShixunWorkReport.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
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)}*/}
From 0f5b4941b221b5d58bc4ee637187dcf3563e0e54 Mon Sep 17 00:00:00 2001
From: cxt <853663049@qq.com>
Date: Fri, 13 Dec 2019 15:50:23 +0800
Subject: [PATCH 3/6] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/services/shixun_search_service.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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
From 26d4ea7d1d077923996d9b31d7bbac9a04ef2aa9 Mon Sep 17 00:00:00 2001
From: daiao <358551898@qq.com>
Date: Fri, 13 Dec 2019 15:53:28 +0800
Subject: [PATCH 4/6] 1
---
app/controllers/attachments_controller.rb | 28 +------
app/controllers/shixuns_controller.rb | 80 ++++++++++++++++++-
app/models/attachment.rb | 4 +
app/models/shixun.rb | 2 +-
...n.jbuilder => get_data_sets.json.jbuilder} | 1 +
config/routes.rb | 4 +-
6 files changed, 88 insertions(+), 31 deletions(-)
rename app/views/shixuns/{jupyter_data_sets.json.jbuilder => get_data_sets.json.jbuilder} (69%)
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 9733bbd9f..b11c6938e 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/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 4203df43a..0014b42c3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -281,8 +281,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
From f27a36307b3ac6c050e82fdac176375817091675 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com>
Date: Fri, 13 Dec 2019 15:57:34 +0800
Subject: [PATCH 5/6] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/react/src/modules/tpm/TPMDataset.js | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/public/react/src/modules/tpm/TPMDataset.js b/public/react/src/modules/tpm/TPMDataset.js
index ed58211f8..b5d7340c2 100644
--- a/public/react/src/modules/tpm/TPMDataset.js
+++ b/public/react/src/modules/tpm/TPMDataset.js
@@ -299,21 +299,6 @@ class TPMDataset extends Component {
console.log(info);
//done 成功就会调用这个方法
this.getdatas();
- try {
- // let datas=this.state.fileListimgs;
- // for(var i=0;i
Date: Fri, 13 Dec 2019 15:58:05 +0800
Subject: [PATCH 6/6] =?UTF-8?q?=E8=B0=83=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
public/react/src/modules/tpm/TPMDataset.js | 4 ----
1 file changed, 4 deletions(-)
diff --git a/public/react/src/modules/tpm/TPMDataset.js b/public/react/src/modules/tpm/TPMDataset.js
index b5d7340c2..3b034a315 100644
--- a/public/react/src/modules/tpm/TPMDataset.js
+++ b/public/react/src/modules/tpm/TPMDataset.js
@@ -289,14 +289,10 @@ 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();
}