修复 vm 中数据清除错误的问题;替换测试用例上传组件

This commit is contained in:
virusdefender 2015-11-07 13:05:40 +08:00
parent e0bb9eed2b
commit 9e4342f649

View File

@ -8,7 +8,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
.on('submit', function (e) { .on('submit', function (e) {
if (!e.isDefaultPrevented()) { if (!e.isDefaultPrevented()) {
e.preventDefault(); e.preventDefault();
if (vm.testCaseId == "") { if (!avalon.vmodels.testCaseUploader.uploaded) {
bsAlert("你还没有上传测试数据!"); bsAlert("你还没有上传测试数据!");
return false; return false;
} }
@ -36,7 +36,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
time_limit: vm.timeLimit, time_limit: vm.timeLimit,
memory_limit: vm.memoryLimit, memory_limit: vm.memoryLimit,
samples: [], samples: [],
test_case_id: vm.testCaseId, test_case_id: avalon.vmodels.testCaseUploader.testCaseId,
hint: avalon.vmodels.contestProblemHintEditor.content, hint: avalon.vmodels.contestProblemHintEditor.content,
visible: vm.visible, visible: vm.visible,
contest_id: avalon.vmodels.admin.contestId, contest_id: avalon.vmodels.admin.contestId,
@ -72,6 +72,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
bsAlert(alertContent); bsAlert(alertContent);
avalon.vmodels.admin.template_url = "template/contest/problem_list.html";
} }
else { else {
bsAlert(data.data); bsAlert(data.data);
@ -98,7 +99,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
outputDescription: "", outputDescription: "",
testCaseId: "", testCaseId: "",
testCaseList: [], testCaseList: [],
uploadSuccess: false,
contestProblemDescriptionEditor: { contestProblemDescriptionEditor: {
editorId: "contest-problem-description-editor", editorId: "contest-problem-description-editor",
@ -135,38 +135,20 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
}); });
else { else {
var vm = avalon.vmodels.editProblem; var vm = avalon.vmodels.editProblem;
title = ""; vm.title = "";
description = ""; vm.description = "";
timeLimit = 1000; vm.timeLimit = 1000;
memoryLimit = 128; vm.memoryLimit = 128;
samples = []; vm.samples = [];
hint = ""; vm.hint = "";
sortIndex = ""; vm.sortIndex = "";
visible = true; vm.visible = true;
inputDescription = ""; vm.inputDescription = "";
outputDescription = ""; vm.outputDescription = "";
testCaseId = ""; vm.testCaseId = "";
testCaseList = []; vm.testCaseList = [];
uploadSuccess = false;
} }
var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/", function (file, response) {
if (response.code)
bsAlert(response.data);
else {
vm.testCaseId = response.data.test_case_id;
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
})
}
vm.uploadSuccess = true;
bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
}
});
if (avalon.vmodels.admin.contestProblemStatus == "edit") { if (avalon.vmodels.admin.contestProblemStatus == "edit") {
$.ajax({ $.ajax({
url: "/api/admin/contest_problem/?contest_problem_id=" + avalon.vmodels.admin.problemId, url: "/api/admin/contest_problem/?contest_problem_id=" + avalon.vmodels.admin.problemId,
@ -189,7 +171,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
vm.inputDescription = problem.input_description; vm.inputDescription = problem.input_description;
vm.outputDescription = problem.output_description; vm.outputDescription = problem.output_description;
vm.score = problem.score; vm.score = problem.score;
vm.testCaseId = problem.test_case_id; avalon.vmodels.testCaseUploader.setTestCase(problem.test_case_id);
vm.samples = []; vm.samples = [];
for (var i = 0; i < problem.samples.length; i++) { for (var i = 0; i < problem.samples.length; i++) {
vm.samples.push({ vm.samples.push({
@ -199,26 +181,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert",
}) })
} }
avalon.vmodels.contestProblemHintEditor.content = problem.hint; avalon.vmodels.contestProblemHintEditor.content = problem.hint;
$.ajax({
url: "/api/admin/test_case_upload/?test_case_id=" + vm.testCaseId,
method: "get",
dataType: "json",
success: function (response) {
if (response.code) {
bsAlert(response.data);
}
else {
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
})
}
vm.uploadSuccess = true;
}
}
})
} }
} }
}); });