[前端]重新修改添加比赛中测试用例的上传方式,修复了bug,还没有写ajax上传比赛信息的部分,因为没有API[CI SKIP]

This commit is contained in:
esp 2015-08-11 19:43:23 +08:00
parent 381f623a9c
commit e089a550cc
4 changed files with 44 additions and 29 deletions

View File

@ -1,6 +1,6 @@
require(["jquery", "avalon", "editor", "uploader", "datetimepicker", require(["jquery", "avalon", "editor", "uploader", "bs_alert", "datetimepicker",
"validation","tagEditor"], "validation",],
function ($, avalon, editor, uploader) { function ($, avalon, editor, uploader, bs_alert) {
avalon.vmodels.add_contest = null; avalon.vmodels.add_contest = null;
$("#add-contest-form") $("#add-contest-form")
.formValidation({ .formValidation({
@ -72,10 +72,10 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
"cpu[]": { "cpu[]": {
validators: { validators: {
notEmpty: { notEmpty: {
message: "请输入cpu时间" message: "请输入时间限制"
}, },
integer: { integer: {
message: "请输入一个合法的数字" message: "时间限制用整数表示"
}, },
between: { between: {
inclusive: true, inclusive: true,
@ -125,24 +125,8 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
text += possible.charAt(Math.floor(Math.random() * possible.length)); text += possible.charAt(Math.floor(Math.random() * possible.length));
return text; return text;
} }
var upLoaderInited = false;
editor("#editor"); editor("#editor");
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
if (respond.code)
bs_alert(respond.data);
else {
vm.problems[vm.problemNo].test_case_id = respond.data.test_case_id;
vm.problems[vm.problemNo].uploadSuccess = true;
vm.problems[vm.problemNo].testCaseList = [];
for (var i = 0; i < respond.data.file_list.input.length; i++) {
vm.problems[vm.problemNo].push({
input: respond.data.file_list.input[i],
output: respond.data.file_list.output[i]
});
}
}
});
var vm = avalon.define({ var vm = avalon.define({
$id: "add_contest", $id: "add_contest",
@ -155,7 +139,7 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
model: "", model: "",
openRank: false, openRank: false,
problems: [], problems: [],
problemNo: 0, problemNo: "-1",
add_problem: function () { add_problem: function () {
var problem_id = make_id(); var problem_id = make_id();
var problem = { var problem = {
@ -202,6 +186,35 @@ require(["jquery", "avalon", "editor", "uploader", "datetimepicker",
return "展开"; return "展开";
} }
}); });
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
if (respond.code)
bs_alert(respond.data);
else {
var index = parseInt(vm.problemNo)-1;
vm.problems[index].test_case_id = respond.data.test_case_id;
vm.problems[index].uploadSuccess = true;
vm.problems[index].testCaseList = [];
for (var i = 0; i < respond.data.file_list.input.length; i++) {
vm.problems[index].testCaseList.push({
input: respond.data.file_list.input[i],
output: respond.data.file_list.output[i]
});
}
bs_alert("测试数据添加成功!共添加"+vm.problems[index].testCaseList.length +"组测试数据");
}
},
function(){
console.log(vm.problemNo);
if (vm.problemNo == "-1")
{
bs_alert("你还未指定一道题目!");
return false;
}
}
);
isUploaderInited = true;
avalon.scan(); avalon.scan();
$("#contest_start_time").datetimepicker({ $("#contest_start_time").datetimepicker({

View File

@ -134,7 +134,9 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito
input: respond.data.file_list.input[i], input: respond.data.file_list.input[i],
output: respond.data.file_list.output[i] output: respond.data.file_list.output[i]
}); });
} }
bs_alert("测试数据添加成功!共添加"+vm.testCaseList.length +"组测试数据");
} }
}); });
var hinteditor = editor("#hint"); var hinteditor = editor("#hint");
@ -147,7 +149,7 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEdito
memory: 256, memory: 256,
samples: [], samples: [],
hint: "", hint: "",
visible: false, visible: true,
difficulty: 0, difficulty: 0,
tags: [], tags: [],
tag: "", tag: "",

View File

@ -1,5 +1,5 @@
define("uploader", ["webuploader", "csrf"], function(webuploader,csrf){ define("uploader", ["webuploader", "csrf"], function(webuploader,csrf){
function uploader(selector, server, onSuccess) { function uploader(selector, server, onSuccess, beforeUpload) {
var Webuploader= webuploader.create({ var Webuploader= webuploader.create({
auto: true, auto: true,
// swf文件路径 // swf文件路径
@ -15,7 +15,7 @@ define("uploader", ["webuploader", "csrf"], function(webuploader,csrf){
}); });
Webuploader.on("uploadBeforeSend",csrf); Webuploader.on("uploadBeforeSend",csrf);
Webuploader.on("uploadSuccess", onSuccess); Webuploader.on("uploadSuccess", onSuccess);
Webuploader.on("beforeFileQueued", beforeUpload);
return Webuploader; return Webuploader;
} }

View File

@ -77,8 +77,8 @@
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="add_problem()">添加</a> <a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="add_problem()">添加</a>
<div class="col-md-12"> <div class="col-md-12">
<label>上传测试用例</label> <label>上传测试用例</label>
<label>选择题号</label><select ms-duplex="problemNo"><option value="0">未指定</option><option ms-repeat="problems" value="{{$index+1}}">{{$index+1}}</option></select> <label>选择题号</label><select ms-duplex="problemNo"><option value="-1">未指定</option><option ms-repeat="problems" ms-attr-value="$index+1">{{$index+1}}</option></select>
<div id="uploader" ms-visible="problemNo"> <div id="uploader">
<div>选择文件</div> <div>选择文件</div>
</div> </div>
</div> </div>
@ -165,7 +165,7 @@
<td>输入文件名</td> <td>输入文件名</td>
<td>输出文件名</td> <td>输出文件名</td>
</tr> </tr>
<tr ms-repeat="testCaseList"> <tr ms-repeat="problem.testCaseList">
<td>{{$index}}</td> <td>{{$index}}</td>
<td>{{el.input}}</td> <td>{{el.input}}</td>
<td>{{el.output}}</td> <td>{{el.output}}</td>