* dev: (21 commits) [前端]整理格式,去掉tab(以前用vim,它自己给加的),去掉调试用的console.log[CI SKIP] [前端]统一admin中js命名方式. 为提交列表添加返回按钮[CI SKIP] [前端]修复bug,更正了不恰当的foreach循环,(js里for(var key in array)不仅遍历了数组元素,还将遍历数组其他的属性以及成员方法),修复了显示编辑区函数对选中小组错误的清除方法.(原来的做法将导致某些情况下旧的小组无法移除编辑区域. 增添了切换编辑比赛的提示,防止用户丢失为保存的信息. 添加问题列表对可见比赛的筛选[CI SKIP] [前端-BUG]修复比赛编辑区可见状态显示错误,(忘记加vm.),增加编辑成功隐藏编辑框的行为,更加方便[CI SKIP] [前端]添加比赛题目列表可见字段的显示,方便比赛管理[CI SKIP] [BUG-fix]返回按钮提示确认,修复不能弹出的问题[CI SKIP] 修复typo in submission/views.py Swagger UI docs中的拼写错误[CI SKIP] [前端]修复userList.js中关于翻页按钮状态控制函数参数的错误. 修复刚刚提交的bug[CI SKIP] [前端]修复userList页面avalon重定义问题[CI SKIP] [前端]修复问题管理(后台)页面的avalon重复定义的问题[CI SKIP] [前端]整理js格式. 修复小bugs,关于比赛密码修改变量名称的错误,小组修改变量名称错误(以上都是在修改比赛页面内)[CI SKIP] [后台]修复contestAdmin,比赛和问题API的逻辑问题,主要针对超级管理员和普通管理员的差别.写了测试,是两个api测试覆盖率达100% [migration]改model漏了一个.....[CI SKIP] [前端-后台]比赛管理,对添加,编辑,列表页面的avalon使用方法做了统一的改变,防止出现页内模板改变但页面不刷新的情况下导致avalon功能间歇性异常的问题,但是代码量变大了一些,还算是整洁.具体是所有页面的avalon只在页面第一次加载的时候初始化,再次加载时只对vm内部变量重新初始化,而不调用avalon.define了[CI SKIP] [后端]添加修改比赛题目添加对题目分数的支持 [后端]为比赛problem model添加分数(score)字段,用于记分模式的比赛 [后端]修复typo,工作正常,没写测试还 [前端]修改比赛列表页面,添加了编辑比赛,编辑比赛题目[CI SKIP] [前端]把添加比赛和添加比赛问题分开了,就是把添加问题模块从添加比赛页面删除了 [前端]添加了后台比赛列表对问题的添加修改页面[CI SKIP] ... Conflicts: static/src/js/app/admin/problem/editProblem.js static/src/js/app/admin/problem/submissionList.js submission/views.py
216 lines
9.4 KiB
JavaScript
216 lines
9.4 KiB
JavaScript
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"],
|
|
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
|
|
|
avalon.ready(function () {
|
|
|
|
$("#edit-problem-form").validator()
|
|
.on('submit', function (e) {
|
|
if (!e.isDefaultPrevented()){
|
|
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 tags = $("#tags").tagEditor("getTags")[0].tags;
|
|
if (tags.length == 0) {
|
|
bsAlert("请至少添加一个标签,这将有利于用户发现你的题目!");
|
|
return false;
|
|
}
|
|
var ajaxData = {
|
|
id: avalon.vmodels.admin.problemId,
|
|
title: vm.title,
|
|
description: vm.description,
|
|
time_limit: vm.timeLimit,
|
|
memory_limit: vm.memoryLimit,
|
|
samples: [],
|
|
test_case_id: vm.testCaseId,
|
|
hint: vm.hint,
|
|
source: vm.source,
|
|
visible: vm.visible,
|
|
tags: tags,
|
|
input_description: vm.inputDescription,
|
|
output_description: vm.outputDescription,
|
|
difficulty: vm.difficulty
|
|
};
|
|
|
|
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/problem/",
|
|
dataType: "json",
|
|
data: JSON.stringify(ajaxData),
|
|
method: "put",
|
|
contentType: "application/json",
|
|
success: function (data) {
|
|
if (!data.code) {
|
|
bsAlert("题目编辑成功!");
|
|
vm.showProblemListPage();
|
|
}
|
|
else {
|
|
bsAlert(data.data);
|
|
}
|
|
}
|
|
|
|
});
|
|
return false;
|
|
}
|
|
});
|
|
if (avalon.vmodels.editProblem) {
|
|
var vm = avalon.vmodels.editProblem;
|
|
title: "",
|
|
description= "";
|
|
timeLimit= -1;
|
|
memoryLimit= -1;
|
|
samples= [];
|
|
hint= "";
|
|
visible= true;
|
|
difficulty= 0;
|
|
inputDescription= "";
|
|
outputDescription= "";
|
|
testCaseIdd= "";
|
|
uploadSuccess= false;
|
|
source= "";
|
|
testCaseList= [];
|
|
}
|
|
else
|
|
var vm = avalon.define({
|
|
$id: "editProblem",
|
|
title: "",
|
|
description: "",
|
|
timeLimit: -1,
|
|
memoryLimit: -1,
|
|
samples: [],
|
|
hint: "",
|
|
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 "展开";
|
|
},
|
|
showProblemListPage: function(){
|
|
vm.$fire("up!showProblemListPage");
|
|
}
|
|
});
|
|
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 + "组测试数据");
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
url: "/api/admin/problem/?problem_id=" + avalon.vmodels.admin.problemId,
|
|
method: "get",
|
|
dataType: "json",
|
|
success: function (data) {
|
|
if (data.code) {
|
|
bsAlert(data.data);
|
|
}
|
|
else {
|
|
var problem = data.data;
|
|
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.difficulty = problem.difficulty;
|
|
vm.inputDescription = problem.input_description;
|
|
vm.outputDescription = problem.output_description;
|
|
vm.testCaseId = problem.test_case_id;
|
|
vm.source = problem.source;
|
|
var problemTags = problem.tags;
|
|
hintEditor.setValue(vm.hint);
|
|
descriptionEditor.setValue(vm.description);
|
|
$.ajax({
|
|
url: "/api/admin/tag/",
|
|
dataType: "json",
|
|
method: "get",
|
|
success: function (data) {
|
|
if (!data.code) {
|
|
var tagAutoCompleteList = [], tags = [];
|
|
for (var i = 0; i < data.data.length; i++) {
|
|
tagAutoCompleteList.push(data.data[i].name);
|
|
}
|
|
for (var j = 0; j < problem.tags.length; j++) {
|
|
tags.push(problemTags[j].name);
|
|
}
|
|
$("#tags").tagEditor({
|
|
initialTags: tags,
|
|
autocomplete: {
|
|
delay: 0,
|
|
position: {collision: 'flip'},
|
|
source: tagAutoCompleteList
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
bsAlert(data.data);
|
|
}
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
avalon.scan();
|
|
|
|
}); |