mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
[前端] 完成了添加题目的页面[CI SKIP]
This commit is contained in:
parent
b1b996271f
commit
9f7206d114
@ -1,5 +1,5 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "validation"],
|
||||
function ($, avalon, editor, uploader, bs_alert) {
|
||||
require(["jquery", "avalon", "editor", "uploader", "bs_alert", "csrf", "tagEditor", "validation", "jqueryUI"],
|
||||
function ($, avalon, editor, uploader, bs_alert, csrfHeader) {
|
||||
avalon.vmodels.add_problem = null;
|
||||
$("#add-problem-form")
|
||||
.formValidation({
|
||||
@ -17,17 +17,10 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val
|
||||
}
|
||||
}
|
||||
},
|
||||
description:{
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入描述"
|
||||
}
|
||||
}
|
||||
},
|
||||
cpu: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入cpu时间"
|
||||
message: "请输入时间限制"
|
||||
},
|
||||
integer: {
|
||||
message: "请输入一个合法的数字"
|
||||
@ -43,29 +36,96 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val
|
||||
memory: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入内存"
|
||||
message: "请输入内存限制"
|
||||
},
|
||||
integer: {
|
||||
message: "请输入一个合法的数字"
|
||||
}
|
||||
}
|
||||
},
|
||||
difficulty: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入难度"
|
||||
},
|
||||
integer: {
|
||||
message: "难度用一个整数表示"
|
||||
}
|
||||
}
|
||||
},
|
||||
source: {
|
||||
validators: {
|
||||
notEmpty: {
|
||||
message: "请输入题目来源"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.on("success.form.fv", function (e) {
|
||||
e.preventDefault();
|
||||
if (vm.test_case_id == '')
|
||||
{
|
||||
bs_alert("你还没有上传测试数据!");
|
||||
return;
|
||||
}
|
||||
if (vm.description == '')
|
||||
{
|
||||
bs_alert("题目描述不能为空!");
|
||||
return;
|
||||
}
|
||||
if (vm.hint == '')
|
||||
{
|
||||
bs_alert("提示不能为空!");
|
||||
return;
|
||||
}
|
||||
var ajaxData = {
|
||||
title: vm.title,
|
||||
description: vm.description,
|
||||
cpu: vm.cpu,
|
||||
memory: vm.memory,
|
||||
samples: []
|
||||
time_limit: vm.cpu,
|
||||
memory_limit: vm.memory,
|
||||
samples: [],
|
||||
test_case_id: vm.test_case_id,
|
||||
hint: vm.hint,
|
||||
source: vm.source,
|
||||
tags: [],
|
||||
difficulty: vm.difficulty
|
||||
};
|
||||
|
||||
for (var i = 0; i < vm.samples.length; i++) {
|
||||
ajaxData.samples.push({input: vm.samples[i].input, output: vm.samples[i].output});
|
||||
if (vm.samples.length == 0)
|
||||
{
|
||||
bs_alert("请至少添加一组样例!");
|
||||
return;
|
||||
}
|
||||
var tags = $("#tags").tagEditor("getTags")[0].tags;
|
||||
if (tags.length == 0)
|
||||
{
|
||||
bs_alert("请至少添加一个标签,这将有利于用户发现你的题目!");
|
||||
return;
|
||||
}
|
||||
for (key in vm.samples.length) {
|
||||
ajaxData.samples.push({input: vm.samples[key].input, output: vm.samples[key].output});
|
||||
}
|
||||
for (key in tags) {
|
||||
ajaxData.tags.push(tags[key].tag);
|
||||
}
|
||||
console.log(ajaxData);
|
||||
$.ajax({
|
||||
beforeSend: csrfHeader,
|
||||
url: "/api/admin/problem/",
|
||||
dataType: "json",
|
||||
data:ajaxData,
|
||||
method: "post",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bs_alert("successful!");
|
||||
console.log(data);
|
||||
}
|
||||
else {
|
||||
bs_alert(data.data);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
});
|
||||
var problemDiscription = editor("#problemDescription");
|
||||
var testCaseUploader = uploader("#testCaseFile", "/api/admin/test_case_upload/", function (file, respond) {
|
||||
@ -75,20 +135,22 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val
|
||||
vm.test_case_id = respond.data.test_case_id;
|
||||
vm.uploadSuccess = true;
|
||||
vm.testCaseList = [];
|
||||
for (var i = 0; i < respond.data.file_list.input.length; i++)
|
||||
{
|
||||
vm.testCaseList.push({input: respond.data.file_list.input[i], output: respond.data.file_list.output[i]});
|
||||
for (var i = 0; i < respond.data.file_list.input.length; i++) {
|
||||
vm.testCaseList.push({
|
||||
input: respond.data.file_list.input[i],
|
||||
output: respond.data.file_list.output[i]
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
var hinteditor = editor("#hint");
|
||||
$("#tags").tagEditor();
|
||||
var tagList = [], completeList = [];
|
||||
var vm = avalon.define({
|
||||
$id: "add_problem",
|
||||
title: "",
|
||||
description: "",
|
||||
cpu: 0,
|
||||
memory: 0,
|
||||
cpu: 1000,
|
||||
memory: 256,
|
||||
samples: [],
|
||||
hint: "",
|
||||
visible: false,
|
||||
@ -99,14 +161,6 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val
|
||||
testCaseList: [],
|
||||
uploadSuccess: false,
|
||||
source: "",
|
||||
checkTag: function () {
|
||||
alert("11");
|
||||
if (event.keyCode == 13)
|
||||
{
|
||||
alert("You press the enter key!");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
add_sample: function () {
|
||||
vm.samples.push({input: "", output: "", "visible": true});
|
||||
},
|
||||
@ -125,5 +179,31 @@ require(["jquery", "avalon", "editor", "uploader", "bs_alert", "tagEditor", "val
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
beforeSend: csrfHeader,
|
||||
url: "/api/admin/tag/",
|
||||
dataType: "json",
|
||||
method: "get",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
tagList = data.data;
|
||||
completeList = [];
|
||||
for (key in tagList) {
|
||||
completeList.push(tagList[key].name);
|
||||
}
|
||||
$("#tags").tagEditor({
|
||||
autocomplete: {
|
||||
delay: 0, // show suggestions immediately
|
||||
position: {collision: 'flip'}, // automatic menu position up/down
|
||||
source: completeList
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
bs_alert(data.data);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
avalon.scan();
|
||||
});
|
@ -20,12 +20,12 @@
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group"><label>cpu</label>
|
||||
<div class="form-group"><label>时间限制(ms)</label>
|
||||
<input type="number" name="cpu" class="form-control" ms-duplex="cpu">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group"><label>内存</label>
|
||||
<div class="form-group"><label>内存限制(MB)</label>
|
||||
<input type="number" name="memory" class="form-control" ms-duplex="memory">
|
||||
</div>
|
||||
</div>
|
||||
@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<div id="tag" class="col-md-12">
|
||||
<label>标签</label><br>
|
||||
<input type="text" id="tags" onchange="console.log(a)">
|
||||
<input type="text" id="tags">
|
||||
</div>
|
||||
<div class="col-md-12"><br>
|
||||
<label>样例</label>
|
||||
|
Loading…
Reference in New Issue
Block a user