From f263e05746c6f929f1a0c1ac46ca4ab776c8900b Mon Sep 17 00:00:00 2001
From: virusdefender <1670873886@qq.com>
Date: Sat, 7 Nov 2015 12:48:43 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?=
=?UTF-8?q?=E4=BE=8B=E4=B8=8A=E4=BC=A0=E5=92=8C=E7=AE=A1=E7=90=86=E7=9A=84?=
=?UTF-8?q?=20web=20=E7=BB=84=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
static/src/js/components/testCaseUploader.js | 83 ++++++++++++++++++++
1 file changed, 83 insertions(+)
create mode 100644 static/src/js/components/testCaseUploader.js
diff --git a/static/src/js/components/testCaseUploader.js b/static/src/js/components/testCaseUploader.js
new file mode 100644
index 0000000..8a41cc3
--- /dev/null
+++ b/static/src/js/components/testCaseUploader.js
@@ -0,0 +1,83 @@
+define("testCaseUploader", ["avalon", "uploader", "bsAlert", "jquery"], function(avalon, uploader, bsAlert, $){
+ avalon.component("ms:testcaseuploader", {
+ $template: '
' +
+ '
' +
+ '
' +
+ '
' +
+ '请将所有测试用例打包在一个文件中上传,' +
+ '所有文件要在压缩包的根目录,' +
+ '且输入输出文件名要以从1开始连续数字标识要对应例如:' +
+ '
1.in 1.out 2.in 2.out ' +
+ '
上传进度%
' +
+ '
' +
+ ' | 编号 | 输入文件名 | 输出文件名 |
' +
+ ' ' +
+ '| {{ $index + 1 }} | ' +
+ '{{ el.input }} | ' +
+ '{{ el.output }} |
' +
+ '
' +
+ '
' +
+ '',
+ testCaseId: "",
+ testCaseList: [],
+ uploaded: false,
+ uploadProgress: 0,
+
+ setTestCaseId: function(){},
+
+ $init: function(vm, el){
+ vm.setTestCase = function(testCaseId){
+ vm.testCaseId = testCaseId;
+ $.ajax({
+ url: "/api/admin/test_case_upload/?test_case_id=" + testCaseId,
+ method: "get",
+ success: function(data){
+ if(data.code){
+ bsAlert("获取测试用例列表失败");
+ }
+ else{
+ for(var key in data.data.file_list){
+ vm.testCaseList.push({
+ input: data.data.file_list[key].input_name,
+ output: data.data.file_list[key].output_name
+ })
+ }
+ vm.uploaded = true;
+ vm.uploadProgress = 100;
+ }
+ }
+ });
+
+ }
+ },
+
+ $ready: function(vm, el){
+ el.msRetain = true;
+ var testCaseUploader = uploader("#testCaseFileSelector", "/api/admin/test_case_upload/",
+ function (file, response) {
+ if (response.code) {
+ bsAlert(response.data);
+ }
+ else {
+ vm.testCaseId = response.data.test_case_id;
+ vm.uploaded = true;
+ vm.testCaseList = [];
+ for(var key in response.data.file_list){
+ vm.testCaseList.push({
+ input: response.data.file_list[key].input_name,
+ output: response.data.file_list[key].output_name
+ })
+ }
+ bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
+ }
+ },
+ function (file, percentage) {
+ vm.uploadProgress = parseInt(percentage * 100);
+ });
+ }
+ })
+});
\ No newline at end of file