[前端]修改了添加比赛页的形式结构,仍有bug[CI SKIP]
This commit is contained in:
@@ -1,103 +1,8 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
|
||||
"formValidation",],
|
||||
"validator"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
avalon.vmodels.add_contest = null;
|
||||
$("#add-contest-form")
|
||||
.formValidation({
|
||||
framework: "bootstrap",
|
||||
fields: {
|
||||
name: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写比赛名称"
|
||||
},
|
||||
stringLength: {
|
||||
min: 1,
|
||||
max: 30,
|
||||
message: "名称不能超过30个字"
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入描述"
|
||||
}
|
||||
}
|
||||
},
|
||||
start_time: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写开始时间"
|
||||
|
||||
},
|
||||
date: {
|
||||
format: "YYYY-MM-DD h:m",
|
||||
message: "请输入一个正确的日期格式"
|
||||
}
|
||||
}
|
||||
},
|
||||
end_time: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请填写结束时间"
|
||||
},
|
||||
date: {
|
||||
format: "YYYY-MM-DD h:m",
|
||||
message: "请输入一个正确的日期格式"
|
||||
}
|
||||
}
|
||||
},
|
||||
password: {
|
||||
validators: {
|
||||
stringLength: {
|
||||
min: 0,
|
||||
max: 30,
|
||||
message: "密码不能超过10个字符"
|
||||
}
|
||||
}
|
||||
},
|
||||
"problem_name[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入题目名称"
|
||||
},
|
||||
stringLength: {
|
||||
min: 1,
|
||||
max: 30,
|
||||
message: "题目不能超过30个字符"
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入时间限制"
|
||||
},
|
||||
integer: {
|
||||
message: "时间限制用整数表示"
|
||||
},
|
||||
between: {
|
||||
inclusive: true,
|
||||
min: 1,
|
||||
max: 5000,
|
||||
message: "只能在1-5000之间"
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory[]": {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入内存"
|
||||
},
|
||||
integer: {
|
||||
message: "请输入一个合法的数字"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.on("success.form.fv", function (e) {
|
||||
$("#add-contest-form").validator().on('submit', function (e) {
|
||||
e.preventDefault();
|
||||
var data = {
|
||||
title: vm.title,
|
||||
@@ -127,7 +32,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
}
|
||||
});
|
||||
console.log(data);
|
||||
});
|
||||
})
|
||||
function make_id() {
|
||||
var text = "";
|
||||
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
@@ -135,13 +40,11 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
||||
return text;
|
||||
}
|
||||
var upLoaderInited = false;
|
||||
editor("#editor");
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "add_contest",
|
||||
title: "",
|
||||
problemCount: 0,
|
||||
description: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
@@ -149,45 +52,61 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
model: "",
|
||||
openRank: false,
|
||||
problems: [],
|
||||
problemNo: "-1",
|
||||
editingProblemId: 0,
|
||||
editSamples: [],
|
||||
editTestCaseList: [],
|
||||
showProblemEditArea: function (problemIndex) {
|
||||
if (vm.editingProblemId == problemIndex){
|
||||
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
|
||||
vm.editingProblemId = 0;
|
||||
}
|
||||
else {
|
||||
vm.problems[problemIndex-1].samples = vm.editSamples;
|
||||
vm.problems[problemIndex-1].testCaseList = vm.editTestCaseList;
|
||||
vm.editingProblemId = problemIndex;
|
||||
editSamples = vm.problems[vm.editingProblemId-1].samples;
|
||||
editTestCaseList = vm.problems[vm.editingProblemId-1].testCaseList;
|
||||
}
|
||||
},
|
||||
add_problem: function () {
|
||||
var problem_id = make_id();
|
||||
var problem = {
|
||||
id: problem_id,
|
||||
title: "",
|
||||
cpu: 1000,
|
||||
memory: 256,
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 256,
|
||||
description: "",
|
||||
samples: [],
|
||||
visible: true,
|
||||
test_case_id: "",
|
||||
testCaseList: [],
|
||||
hint: "",
|
||||
difficulty: 0,
|
||||
uploadSuccess: false
|
||||
score: 0,
|
||||
uploadSuccess: false,
|
||||
};
|
||||
vm.problems.push(problem);
|
||||
var id = vm.problems.length - 1;
|
||||
editor("#problem-" + problem_id + "-description");
|
||||
var hinteditor = editor("#problem-" + problem_id +"-hint");
|
||||
$("#add-contest-form").formValidation('addField', $('[name="problem_name[]"]'));
|
||||
$("#add-contest-form").formValidation('addField', $('[name="cpu[]"]'));
|
||||
$("#add-contest-form").formValidation('addField', $('[name="memory[]"]'));
|
||||
vm.showProblemEditArea(vm.problems.length);
|
||||
},
|
||||
del_problem: function (problem) {
|
||||
del_problem: function (problemIndex) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
vm.problems.remove(problem);
|
||||
vm.editingProblemId = 0;
|
||||
vm.problems.remove(vm.problems[problemIndex-1]);
|
||||
}
|
||||
},
|
||||
hidden: function () {
|
||||
vm.problems[vm.editingProblemId-1].samples = editSamples;
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = editTestCaseList;
|
||||
vm.editingProblemId = 0;
|
||||
},
|
||||
toggle: function (item) {
|
||||
item.visible = !item.visible;
|
||||
},
|
||||
add_sample: function (problem) {
|
||||
problem.samples.push({id: make_id(), visible: true, input: "", output: ""});
|
||||
add_sample: function () {
|
||||
//vm.problems[vm.editingProblemId-1].samples.push({visible: true, input: "", output: ""});
|
||||
vm.editSamples.push({visible: true, input: "", output: ""});
|
||||
},
|
||||
del_sample: function (problem, sample) {
|
||||
del_sample: function (sample) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
problem.samples.remove(sample);
|
||||
editSamples.remove(sample);
|
||||
}
|
||||
},
|
||||
getBtnContent: function (item) {
|
||||
@@ -201,29 +120,28 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
if (respond.code)
|
||||
bsAlert(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 = [];
|
||||
vm.problems[vm.editingProblemId-1].test_case_id = respond.data.test_case_id;
|
||||
vm.problems[vm.editingProblemId-1].uploadSuccess = true;
|
||||
vm.editTestCaseList = [];
|
||||
for (var i = 0; i < respond.data.file_list.input.length; i++) {
|
||||
vm.problems[index].testCaseList.push({
|
||||
vm.editTestCaseList.push({
|
||||
input: respond.data.file_list.input[i],
|
||||
output: respond.data.file_list.output[i]
|
||||
});
|
||||
}
|
||||
bsAlert("测试数据添加成功!共添加"+vm.problems[index].testCaseList.length +"组测试数据");
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
|
||||
bsAlert("测试数据添加成功!共添加"+editTestCaseList.length +"组测试数据");
|
||||
}
|
||||
},
|
||||
function(){
|
||||
console.log(vm.problemNo);
|
||||
if (vm.problemNo == "-1")
|
||||
if (vm.editingProblemId == 0)
|
||||
{
|
||||
bsAlert("你还未指定一道题目!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
isUploaderInited = true;
|
||||
|
||||
avalon.scan();
|
||||
|
||||
@@ -249,4 +167,4 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
$("#add-contest-form")
|
||||
.formValidation("revalidateField", "end_time");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -75,77 +75,78 @@
|
||||
<div class="col-md-12">
|
||||
<label>添加题目</label>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="add_problem()">添加</a>
|
||||
|
||||
<div class="col-md-12">
|
||||
<label>上传测试用例</label>
|
||||
<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">
|
||||
<div>选择文件</div>
|
||||
</div>
|
||||
</div>
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>编号</th>
|
||||
<th>题目</th>
|
||||
<th>测试数据</th>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr ms-repeat="problems">
|
||||
<td>题目{{ $index+1 }}</td>
|
||||
<td>{{ el.title }}</td>
|
||||
<td>{{ el.testCaseList.length }}组</td>
|
||||
<td>
|
||||
<a href="javascript:void(0)"class="btn-sm btn-info" ms-click="showProblemEditArea($index+1)">编辑</a>
|
||||
<a href="javascript:void(0)"class="btn-sm btn-danger" ms-click="del_problem($index+1)">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="problem" ms-repeat-problem="problems">
|
||||
|
||||
<div class="problem" ms-visible="editingProblemId">
|
||||
<div class="panel panel-default problem-panel">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">题目{{$index + 1}} </span>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="toggle(problem)">
|
||||
{{ getBtnContent(problem)}}
|
||||
<span class="panel-title">题目{{editingProblemId}} </span>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="hidden()">
|
||||
隐藏
|
||||
</a>
|
||||
<a href="javascript:void(0)" class="btn btn-danger btn-sm" ms-click="del_problem(problem)">
|
||||
<a href="javascript:void(0)" class="btn btn-danger btn-sm" ms-click="del_problem(editingProblemId)">
|
||||
删除
|
||||
</a>
|
||||
</div>
|
||||
<div class="panel-body" ms-visible="problem.visible">
|
||||
<div class="panel-body" >
|
||||
<div class="form-group col-md-12">
|
||||
<label>题目标题</label>
|
||||
<input type="text" name="problem_name[]" class="form-control" ms-duplex="problem.title">
|
||||
<input type="text" name="problemName" class="form-control" ms-duplex="problems[editingProblemId-1].title">
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>题目描述</label>
|
||||
<textarea ms-attr-id="problem-{{ problem.id }}-description" placeholder="这里输入内容"
|
||||
ms-duplex="problem.description"></textarea>
|
||||
<small ms-visible="problem.description==''" style="color:red">请填写题目描述</small>
|
||||
<textarea id="problemDescriptionEditor" placeholder="这里输入内容"
|
||||
ms-duplex="problems[editingProblemId-1].description"></textarea>
|
||||
<small ms-visible="editDescription==''" style="color:red">请填写题目描述</small>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>提示</label>
|
||||
<textarea ms-attr-id="problem-{{ problem.id }}-hint" placeholder="这里输入内容"
|
||||
ms-duplex="problem.hint"></textarea>
|
||||
<textarea id="problemHintEditor" placeholder="这里输入内容"
|
||||
ms-duplex="problems[editingProblemId-1].hint"></textarea>
|
||||
</div>
|
||||
<div class="col-md-3 form-group">
|
||||
<label>cpu</label>
|
||||
<input type="number" name="cpu[]" class="form-control" ms-duplex="problem.cpu">
|
||||
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].timeLimit">
|
||||
</div>
|
||||
<div class="col-md-3 form-group">
|
||||
<label>内存</label>
|
||||
<input type="number" name="memory[]" class="form-control" ms-duplex="problem.memory">
|
||||
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].memoryLimit">
|
||||
</div>
|
||||
<div class="col-md-3 form-group">
|
||||
<label>难度</label>
|
||||
<input type="number" name="difficulty[]" class="form-control"
|
||||
ms-duplex="problem.difficulty">
|
||||
<label>分值</label>
|
||||
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].score">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label>样例</label>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
|
||||
ms-click="add_sample(problem)">添加</a>
|
||||
|
||||
<div class="sample">
|
||||
<div class="panel panel-default sample-panel" ms-repeat-sample="problem.samples">
|
||||
<div class="panel-heading">
|
||||
ms-click="add_sample()">添加</a>
|
||||
<div>
|
||||
<div class="panel panel-default sample-panel" ms-repeat-sample="editSamples">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">样例{{$index + 1}}</span>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
|
||||
ms-click="toggle(sample)">
|
||||
{{ getBtnContent(sample)}}
|
||||
</a>
|
||||
ms-click="toggle(sample)">{{ getBtnContent(sample)}}</a>
|
||||
<a href="javascript:void(0)" class="btn btn-danger btn-sm"
|
||||
ms-click="del_sample(problem, sample)">
|
||||
删除
|
||||
</a>
|
||||
ms-click="del_sample(sample)">删除</a>
|
||||
</div>
|
||||
<div class="panel-body row" ms-visible="sample.visible">
|
||||
<div class="col-md-6">
|
||||
@@ -167,17 +168,20 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<label>测试数据</label><br>
|
||||
<label>上传测试测试数据</label>
|
||||
<div id="uploader">
|
||||
<div>选择文件</div>
|
||||
</div>
|
||||
<small class="text-info">请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:<br>
|
||||
1.in 1.out 2.in 2.out
|
||||
</small>
|
||||
<table class="table table-striped" ms-visible="problem.uploadSuccess">
|
||||
<table class="table table-striped" ms-visible="problems[editingProblemId-1].uploadSuccess">
|
||||
<tr>
|
||||
<td>编号</td>
|
||||
<td>输入文件名</td>
|
||||
<td>输出文件名</td>
|
||||
</tr>
|
||||
<tr ms-repeat="problem.testCaseList">
|
||||
<tr ms-repeat="editTestCaseList">
|
||||
<td>{{$index}}</td>
|
||||
<td>{{ el.input }}</td>
|
||||
<td>{{ el.output }}</td>
|
||||
@@ -197,4 +201,3 @@
|
||||
</div>
|
||||
|
||||
<script src="/static/js/app/admin/contest/add_contest.js"></script>
|
||||
<link href="/static/css/tagEditor/jquery.tag-editor.css" rel="stylesheet">
|
||||
|
||||
Reference in New Issue
Block a user