[前端]添加了后台比赛列表对问题的添加修改页面[CI SKIP]
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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();
|
||||
|
||||
});
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
<div ms-controller="editProblem" class="col-md-9">
|
||||
<form id="edit-problem-form">
|
||||
<nav>
|
||||
<ul class="pager">
|
||||
<li class="previous" ms-click="goBack()"><a href="javascript:void(0)"><span
|
||||
aria-hidden="true">←</span> 返回</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="form-group col-md-3">
|
||||
<label>题目编号</label>
|
||||
<input type="text" name="title" autofocus class="form-control" ms-duplex="sortIndex"
|
||||
data-error="请填写题目编号" maxlength="30" required>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
<div class="form-group col-md-9">
|
||||
<label>题目标题</label>
|
||||
<input type="text" name="title" autofocus class="form-control" ms-duplex="title"
|
||||
data-error="请填写题目名称" maxlength="30" required>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-md-12">
|
||||
<label>题目描述</label>
|
||||
<textarea id="problemDescription" placeholder="这里输入内容(此内容不能为空)" ms-duplex="description"></textarea>
|
||||
<small ms-visible="description==''" style="color:red">请填写题目描述</small>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group"><label>时间限制(ms)</label>
|
||||
<input type="number" name="timeLimit" class="form-control" ms-duplex="timeLimit"
|
||||
data-error="请输入时间限制(保证是一个1000-5000的合法整数)" required>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group"><label>内存限制(MB)</label>
|
||||
<input type="number" name="memory" class="form-control" ms-duplex="memoryLimit"
|
||||
data-error="请输入内存限制(保证是一个合法整数)" required>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3 form-group">
|
||||
<label>是否可见</label><br>
|
||||
<label><input type="checkbox" ms-duplex-checked="visible">
|
||||
<small> 可见</small>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-md-12 form-group">
|
||||
<label>输入描述</label><br>
|
||||
<textarea class="form-control" rows="5" name="input_description"
|
||||
ms-duplex="inputDescription" data-error="请填写输入描述"
|
||||
maxlength="10000" required>
|
||||
</textarea>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
<div class="col-md-12 form-group">
|
||||
<label>输出描述</label><br>
|
||||
<textarea class="form-control" rows="5" name="output_escription"
|
||||
ms-duplex="outputDescription" data-error="请填写输出描述"
|
||||
maxlength="10000" required>
|
||||
</textarea>
|
||||
<div class="help-block with-errors"></div>
|
||||
</div>
|
||||
<div class="col-md-12"><br>
|
||||
<label>样例</label>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="addSample()">添加</a>
|
||||
|
||||
<div class="sample">
|
||||
<div class="panel panel-default sample-panel" ms-repeat-sample="samples">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">样例{{$index + 1}}</span>
|
||||
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
|
||||
ms-click="toggleSample(sample)">
|
||||
{{ getBtnContent(sample)}}
|
||||
</a>
|
||||
<a href="javascript:void(0)" class="btn btn-danger btn-sm"
|
||||
ms-click="delSample(sample)">
|
||||
删除
|
||||
</a>
|
||||
</div>
|
||||
<div class="panel-body row" ms-visible="sample.visible">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>样例输入</label>
|
||||
<textarea class="form-control" rows="5" ms-duplex="sample.input"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label>样例输出</label>
|
||||
<textarea class="form-control" rows="5" ms-duplex="sample.output"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12"><br>
|
||||
<label>测试数据(多次上传将覆盖原有测试用例)</label><br>
|
||||
<small class="text-info">请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:<br>
|
||||
1.in 1.out 2.in 2.out
|
||||
</small>
|
||||
<table class="table table-striped" ms-visible="uploadSuccess">
|
||||
<tr>
|
||||
<td>编号</td>
|
||||
<td>输入文件名</td>
|
||||
<td>输出文件名</td>
|
||||
</tr>
|
||||
<tr ms-repeat="testCaseList">
|
||||
<td>{{ $index + 1 }}</td>
|
||||
<td>{{ el.input }}</td>
|
||||
<td>{{ el.output }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<div id="testCaseFile">选择文件</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-12">
|
||||
<label>提示</label>
|
||||
<textarea id="hint" placeholder="这里输入内容" ms-duplex="hint"></textarea>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<input type="submit" class="btn btn-success btn-lg" value="发布题目" id="submitBtn">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script src="/static/js/app/admin/contest/edit_problem.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user