[前端]添加了后台比赛列表对问题的添加修改页面[CI SKIP]

This commit is contained in:
esp
2015-08-23 17:36:35 +08:00
parent cca4bb3852
commit b5313ce908
3 changed files with 320 additions and 0 deletions

View File

@@ -123,6 +123,17 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
vm.template_url = "template/problem/submission_list.html";
});
vm.$watch("showContestProblemPage", function (problemId, contestId) {
vm.problemId = problemId;
vm.contestId = contestId;
vm.template_url = "template/contest/edit_problem.html";
});
vm.$watch("showContestListPage", function (problemId) {
vm.problemId = problemId;
vm.template_url = "template/contest/contest_list.html";
});
avalon.scan();
window.onhashchange = function () {

View File

@@ -0,0 +1,176 @@
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
avalon.ready(function () {
avalon.vmodels.editProblem = null;
$("#edit-problem-form").validator()
.on('submit', function (e) {
if (!e.isDefaultPrevented()){
e.preventDefault();
if (vm.testCaseId == "") {
bsAlert("你还没有上传测试数据!");
return false;
}
if (vm.description == "") {
bsAlert("题目描述不能为空!");
return false;
}
if (vm.timeLimit < 1000 || vm.timeLimit > 5000) {
bsAlert("保证时间限制是一个1000-5000的合法整数");
return false;
}
if (vm.samples.length == 0) {
bsAlert("请至少添加一组样例!");
return false;
}
for (var i = 0; i < vm.samples.length; i++) {
if (vm.samples[i].input == "" || vm.samples[i].output == "") {
bsAlert("样例输入与样例输出不能为空!");
return false;
}
}
var ajaxData = {
title: vm.title,
description: vm.description,
time_limit: vm.timeLimit,
memory_limit: vm.memoryLimit,
samples: [],
test_case_id: vm.testCaseId,
hint: vm.hint,
visible: vm.visible,
contest_id: avalon.vmodels.admin.contestId,
input_description: vm.inputDescription,
output_description: vm.outputDescription,
sort_index: vm.sortIndex,
};
var method = "post";
if (avalon.vmodels.admin.problemId) {
method = "put";
ajaxData.id = avalon.vmodels.admin.problemId;
}
for (var i = 0; i < vm.samples.$model.length; i++) {
ajaxData.samples.push({input: vm.samples.$model[i].input, output: vm.samples.$model[i].output});
}
$.ajax({
beforeSend: csrfTokenHeader,
url: "/api/admin/contest_problem/",
dataType: "json",
data: JSON.stringify(ajaxData),
method: method,
contentType: "application/json",
success: function (data) {
if (!data.code) {
bsAlert("题目编辑成功!");
vm.goBack(true);
}
else {
bsAlert(data.data);
}
}
});
return false;
}
});
var vm = avalon.define({
$id: "editProblem",
title: "",
description: "",
timeLimit: 0,
memoryLimit: 0,
samples: [],
hint: "",
sortIndex: "",
visible: true,
//difficulty: 0,
inputDescription: "",
outputDescription: "",
testCaseIdd: "",
uploadSuccess: false,
//source: "",
testCaseList: [],
addSample: function () {
vm.samples.push({input: "", output: "", "visible": true});
},
delSample: function (sample) {
if (confirm("你确定要删除么?")) {
vm.samples.remove(sample);
}
},
toggleSample: function (sample) {
sample.visible = !sample.visible;
},
getBtnContent: function (item) {
if (item.visible)
return "折叠";
return "展开";
},
goBack: function(check){
if (check||confirm("这将丢失所有的改动,确定要继续么?")) {
vm.$fire("up!showContestListPage");
}
}
});
var hintEditor = editor("#hint");
var descriptionEditor = editor("#problemDescription");
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.uploadSuccess = true;
vm.testCaseList = [];
for (var i = 0; i < response.data.file_list.input.length; i++) {
vm.testCaseList.push({
input: response.data.file_list.input[i],
output: response.data.file_list.output[i]
});
}
bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
}
});
if (avalon.vmodels.admin.problemId){
$.ajax({
url: "/api/admin/contest_problem/?contest_problem_id=" + avalon.vmodels.admin.problemId,
method: "get",
dataType: "json",
success: function (data) {
if (data.code) {
bsAlert(data.data);
}
else {
var problem = data.data;
console.log(problem);
vm.sortIndex = problem.sort_index;
vm.title = problem.title;
vm.description = problem.description;
vm.timeLimit = problem.time_limit;
vm.memoryLimit = problem.memory_limit;
for (var i = 0; i < problem.samples.length; i++) {
vm.samples.push({
input: problem.samples[i].input,
output: problem.samples[i].output,
visible: false
})
}
vm.hint = problem.hint;
vm.visible = problem.visible;
vm.inputDescription = problem.input_description;
vm.outputDescription = problem.output_description;
vm.testCaseId = problem.test_case_id;
vm.source = problem.source;
hintEditor.setValue(vm.hint);
descriptionEditor.setValue(vm.description);
}
}
});
}
});
avalon.scan();
});