Merge branch 'virusdefender-dev' of git.coding.net:virusdefender/qduoj into dev-s
This commit is contained in:
@@ -52,10 +52,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "bootstrap"], function ($,
|
||||
{ name: "首页",
|
||||
children: [{name: "主页", hash: "#index/index"}]
|
||||
},
|
||||
{
|
||||
name: "通用",
|
||||
children: [{name: "公告管理", hash: "#announcement/announcement"}]
|
||||
},
|
||||
{
|
||||
name: "比赛管理",
|
||||
children: [{name: "比赛列表", hash: "#contest/contest_list"},
|
||||
@@ -72,12 +68,14 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "bootstrap"], function ($,
|
||||
$id: "admin",
|
||||
template_url: "template/" + hash + ".html",
|
||||
username: "",
|
||||
adminType: 1,
|
||||
groupId: -1,
|
||||
problemId: -1,
|
||||
adminNavList: [],
|
||||
$contestMode: -1,
|
||||
$problemId: -1,
|
||||
$contestId: -1,
|
||||
|
||||
contestId: -1,
|
||||
contestProblemStatus: "edit",
|
||||
|
||||
hide_loading: function () {
|
||||
$("#loading-gif").hide();
|
||||
},
|
||||
@@ -94,6 +92,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "bootstrap"], function ($,
|
||||
success: function(data){
|
||||
if(!data.code){
|
||||
vm.username = data.data.username;
|
||||
vm.adminType = data.data.admin_type;
|
||||
if (data.data.admin_type == 2){
|
||||
vm.adminNavList = superAdminNav;
|
||||
}
|
||||
@@ -113,24 +112,6 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "bootstrap"], function ($,
|
||||
vm.template_url = "template/group/group.html";
|
||||
});
|
||||
|
||||
vm.$watch("showContestProblemPage", function (problemId, contestId, contestMode) {
|
||||
vm.$problemId = problemId;
|
||||
vm.$contestId = contestId;
|
||||
vm.$contestMode = contestMode
|
||||
vm.template_url = "template/contest/edit_problem.html";
|
||||
});
|
||||
|
||||
vm.$watch("showContestListPage", function () {
|
||||
vm.template_url = "template/contest/contest_list.html";
|
||||
});
|
||||
|
||||
vm.$watch("showContestSubmissionPage", function (problemId, contestId, contestMode) {
|
||||
vm.$problemId = problemId;
|
||||
vm.$contestId = contestId;
|
||||
vm.$contestMode = contestMode
|
||||
vm.template_url = "template/contest/submission_list.html";
|
||||
});
|
||||
|
||||
avalon.scan();
|
||||
|
||||
window.onhashchange = function () {
|
||||
|
||||
@@ -48,7 +48,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
method: "post",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
|
||||
bsAlert("添加成功!接下来下需要为比赛添加问题(注意比赛当前状态为:隐藏)");
|
||||
location.hash = "#contest/contest_list";
|
||||
}
|
||||
else {
|
||||
@@ -61,8 +61,19 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
});
|
||||
|
||||
//editor("#editor");
|
||||
if (avalon.vmodels.add_contest)
|
||||
if (avalon.vmodels.add_contest) {
|
||||
var vm = avalon.vmodels.add_contest;
|
||||
vm.title = "";
|
||||
vm.startTime = "";
|
||||
vm.endTime = "";
|
||||
vm.password = "";
|
||||
vm.isGlobal = true;
|
||||
vm.allGroups = [];
|
||||
vm.showGlobalViewRadio = true;
|
||||
vm.realTimeRank = true;
|
||||
avalon.vmodels.contestDescriptionEditor.content = "";
|
||||
|
||||
}
|
||||
else
|
||||
var vm = avalon.define({
|
||||
$id: "add_contest",
|
||||
|
||||
@@ -27,7 +27,8 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker",
|
||||
avalon.vmodels.admin.template_url = "template/contest/edit_contest.html";
|
||||
},
|
||||
showContestProblems: function(contestId){
|
||||
// todo
|
||||
avalon.vmodels.admin.contestId = contestId;
|
||||
avalon.vmodels.admin.template_url = "template/contest/problem_list.html";
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,321 +0,0 @@
|
||||
require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker", "validator"], function ($, avalon, csrfTokenHeader, bsAlert, editor) {
|
||||
|
||||
avalon.ready(function () {
|
||||
|
||||
$("#edit-contest-form").validator().on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()) {
|
||||
e.preventDefault();
|
||||
var ajaxData = {
|
||||
id: vm.contestList[vm.editingContestId - 1].id,
|
||||
title: vm.editTitle,
|
||||
description: vm.editDescription,
|
||||
mode: vm.editMode,
|
||||
contest_type: 0,
|
||||
real_time_rank: vm.editRealTimeRank,
|
||||
show_user_submission: vm.editShowSubmission,
|
||||
start_time: vm.editStartTime,
|
||||
end_time: vm.editEndTime,
|
||||
visible: vm.editVisible
|
||||
};
|
||||
|
||||
var selectedGroups = [];
|
||||
if (!vm.isGlobal) {
|
||||
for (var i = 0; i < vm.allGroups.length; i++) {
|
||||
if (vm.allGroups[i].isSelected) {
|
||||
selectedGroups.push(vm.allGroups[i].id);
|
||||
}
|
||||
}
|
||||
ajaxData.groups = selectedGroups;
|
||||
}
|
||||
else {
|
||||
if (vm.editPassword) {
|
||||
ajaxData.password = vm.editPassword;
|
||||
ajaxData.contest_type = 2;
|
||||
}
|
||||
else
|
||||
ajaxData.contest_type = 1;
|
||||
}
|
||||
if (!vm.isGlobal && !selectedGroups.length) {
|
||||
bsAlert("你没有选择参赛用户!");
|
||||
return false;
|
||||
}
|
||||
if (vm.editDescription == "") {
|
||||
bsAlert("比赛描述不能为空!");
|
||||
return false;
|
||||
}
|
||||
|
||||
$.ajax({ // modify contest info
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/contest/",
|
||||
dataType: "json",
|
||||
contentType: "application/json;charset=UTF-8",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "put",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("修改成功!");
|
||||
vm.editingContestId = 0; // Hide the editor
|
||||
vm.getPage(1); // Refresh the contest list
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (avalon.vmodels.contestList) {
|
||||
// this page has been loaded before, so set the default value
|
||||
var vm = avalon.vmodels.contestList;
|
||||
vm.contestList = [];
|
||||
}
|
||||
else {
|
||||
var vm = avalon.define({
|
||||
$id: "contestList",
|
||||
contestList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
totalPage: 1,
|
||||
showVisibleOnly: false,
|
||||
keyword: "",
|
||||
editingContestId: 0,
|
||||
editTitle: "",
|
||||
editDescription: "",
|
||||
editProblemList: [],
|
||||
editPassword: "",
|
||||
editStartTime: "",
|
||||
editEndTime: "",
|
||||
editMode: "",
|
||||
editShowSubmission: false,
|
||||
editVisible: false,
|
||||
editRealTimeRank: true,
|
||||
editingProblemContestIndex: 0,
|
||||
isGlobal: true,
|
||||
allGroups: [],
|
||||
showGlobalViewRadio: true,
|
||||
admin_type: 1,
|
||||
getNext: function () {
|
||||
if (!vm.nextPage)
|
||||
return;
|
||||
getPageData(vm.page + 1);
|
||||
},
|
||||
getPrevious: function () {
|
||||
if (!vm.previousPage)
|
||||
return;
|
||||
getPageData(vm.page - 1);
|
||||
},
|
||||
getBtnClass: function (btn) {
|
||||
if (btn == "next") {
|
||||
return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
}
|
||||
else {
|
||||
return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
}
|
||||
},
|
||||
getPage: function (page_index) {
|
||||
getPageData(page_index);
|
||||
},
|
||||
showEditContestArea: function (contestId) {
|
||||
if (vm.editingContestId && !confirm("如果继续将丢失未保存的信息,是否继续?"))
|
||||
return;
|
||||
if (contestId == vm.editingContestId)
|
||||
vm.editingContestId = 0;
|
||||
else {
|
||||
vm.editingContestId = contestId;
|
||||
vm.editTitle = vm.contestList[contestId - 1].title;
|
||||
vm.editPassword = vm.contestList[contestId - 1].password;
|
||||
vm.editStartTime = vm.contestList[contestId - 1].start_time.substring(0, 16).replace("T", " ");
|
||||
vm.editEndTime = vm.contestList[contestId - 1].end_time.substring(0, 16).replace("T", " ");
|
||||
vm.editMode = vm.contestList[contestId - 1].mode;
|
||||
vm.editVisible = vm.contestList[contestId - 1].visible;
|
||||
vm.editRealTimeRank = vm.contestList[contestId - 1].real_time_rank;
|
||||
if (vm.contestList[contestId - 1].contest_type == 0) { //contest type == 0, contest in group
|
||||
vm.isGlobal = false;
|
||||
for (var i = 0; i < vm.allGroups.length; i++) {
|
||||
vm.allGroups[i].isSelected = false;
|
||||
}
|
||||
for (var i = 0; i < vm.contestList[contestId - 1].groups.length; i++) {
|
||||
var id = parseInt(vm.contestList[contestId - 1].groups[i]);
|
||||
|
||||
for (var index = 0; vm.allGroups[index]; index++) {
|
||||
if (vm.allGroups[index].id == id) {
|
||||
vm.allGroups[index].isSelected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
vm.isGlobal = true;
|
||||
}
|
||||
vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission;
|
||||
editor("#editor").setValue(vm.contestList[contestId - 1].description);
|
||||
vm.editingProblemContestIndex = 0;
|
||||
}
|
||||
},
|
||||
showEditProblemArea: function (contestId) {
|
||||
if (vm.editingProblemContestIndex == contestId) {
|
||||
vm.editingProblemContestIndex = 0;
|
||||
return;
|
||||
}
|
||||
if (vm.editingContestId && !confirm("如果继续将丢失未保存的信息,是否继续?")) {
|
||||
return;
|
||||
}
|
||||
$.ajax({ // Get the problem list of current contest
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/contest_problem/?contest_id=" + vm.contestList[contestId - 1].id,
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
vm.editProblemList = data.data;
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
vm.editingContestId = 0;
|
||||
vm.editingProblemContestIndex = contestId;
|
||||
vm.editMode = vm.contestList[contestId - 1].mode;
|
||||
},
|
||||
addProblem: function () {
|
||||
vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode);
|
||||
},
|
||||
showProblemEditPage: function (el) {
|
||||
vm.$fire("up!showContestProblemPage", el.id, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode);
|
||||
},
|
||||
showSubmissionPage: function (el) {
|
||||
var problemId = 0
|
||||
if (el)
|
||||
problemId = el.id;
|
||||
vm.$fire("up!showContestSubmissionPage", problemId, vm.contestList[vm.editingProblemContestIndex - 1].id, vm.editMode);
|
||||
},
|
||||
addToProblemList: function (problem) {
|
||||
var ajaxData = {
|
||||
title: problem.title,
|
||||
description: problem.description,
|
||||
time_limit: problem.time_limit,
|
||||
memory_limit: problem.memory_limit,
|
||||
samples: [],
|
||||
test_case_id: problem.test_case_id,
|
||||
hint: problem.hint,
|
||||
source: problem.contest.title,
|
||||
visible: false,
|
||||
tags: [],
|
||||
input_description: problem.input_description,
|
||||
output_description: problem.output_description,
|
||||
difficulty: 0
|
||||
};
|
||||
for (var i = 0; i < problem.samples.length; i++) {
|
||||
ajaxData.samples.push({input: problem.samples[i].input, output: problem.samples[i].output})
|
||||
}
|
||||
$.ajax({
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/problem/",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "post",
|
||||
contentType: "application/json;charset=UTF-8",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("题目添加成功!题目现在处于隐藏状态,请到题目列表手动修改,并添加分类和难度信息!");
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
vm.$watch("showVisibleOnly", function () {
|
||||
getPageData(1);
|
||||
})
|
||||
}
|
||||
getPageData(1);
|
||||
|
||||
//init time picker
|
||||
$("#contest_start_time").datetimepicker({
|
||||
format: "yyyy-mm-dd hh:ii",
|
||||
minuteStep: 5,
|
||||
weekStart: 1,
|
||||
language: "zh-CN"
|
||||
});
|
||||
$("#contest_end_time").datetimepicker({
|
||||
format: "yyyy-mm-dd hh:ii",
|
||||
minuteStep: 5,
|
||||
weekStart: 1,
|
||||
language: "zh-CN"
|
||||
});
|
||||
|
||||
function getPageData(page) {
|
||||
var url = "/api/admin/contest/?paging=true&page=" + page + "&page_size=10";
|
||||
if (vm.showVisibleOnly)
|
||||
url += "&visible=true"
|
||||
if (vm.keyword != "")
|
||||
url += "&keyword=" + vm.keyword;
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: "json",
|
||||
method: "get",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
vm.contestList = data.data.results;
|
||||
vm.totalPage = data.data.total_page;
|
||||
vm.previousPage = data.data.previous_page;
|
||||
vm.nextPage = data.data.next_page;
|
||||
vm.page = page;
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Get group list
|
||||
$.ajax({
|
||||
url: "/api/user/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
var admin_type = data.data.admin_type;
|
||||
vm.admin_type = admin_type;
|
||||
if (data.data.admin_type == 1) {
|
||||
vm.isGlobal = false;
|
||||
vm.showGlobalViewRadio = false;
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url: "/api/admin/group/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (!data.data.length) {
|
||||
|
||||
if (admin_type != 2)
|
||||
bsAlert("您的用户权限只能创建小组内比赛,但是您还没有创建过小组");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
var item = data.data[i];
|
||||
item["isSelected"] = false;
|
||||
vm.allGroups.push(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
avalon.scan();
|
||||
});
|
||||
64
static/src/js/app/admin/contest/contestProblemList.js
Normal file
64
static/src/js/app/admin/contest/contestProblemList.js
Normal file
@@ -0,0 +1,64 @@
|
||||
require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfTokenHeader, bsAlert) {
|
||||
|
||||
avalon.ready(function () {
|
||||
if (avalon.vmodels.contestProblemList) {
|
||||
vm = avalon.vmodels.contestProblemList;
|
||||
}
|
||||
else {
|
||||
var vm = avalon.define({
|
||||
$id: "contestProblemList",
|
||||
problemList: [],
|
||||
|
||||
adminType: avalon.vmodels.admin.adminType,
|
||||
|
||||
showEditProblemPage: function (problemId) {
|
||||
avalon.vmodels.admin.contestProblemStatus = "edit";
|
||||
avalon.vmodels.admin.problemId = problemId;
|
||||
avalon.vmodels.admin.template_url = "template/contest/edit_problem.html";
|
||||
},
|
||||
addProblem: function(){
|
||||
avalon.vmodels.admin.contestProblemStatus = "add";
|
||||
avalon.vmodels.admin.template_url = "template/contest/edit_problem.html";
|
||||
},
|
||||
goBack: function(){
|
||||
avalon.vmodels.admin.template_url = "template/contest/contest_list.html"
|
||||
},
|
||||
|
||||
makeProblemPublic: function(problem){
|
||||
$.ajax({
|
||||
url: "/api/admin/contest_problem/public/",
|
||||
method: "post",
|
||||
dataType: "json",
|
||||
data: {"problem_id": problem.id},
|
||||
success: function(response){
|
||||
if(response.code){
|
||||
bsAlert(response.data);
|
||||
}
|
||||
else{
|
||||
problem.is_public = true;
|
||||
alert("公开题目成功,现在处于隐藏状态,请添加标签难度等信息。");
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: "/api/admin/contest_problem/?contest_id=" + avalon.vmodels.admin.contestId,
|
||||
dataType: "json",
|
||||
method: "get",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
vm.problemList = data.data;
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
avalon.scan();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -130,6 +130,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
|
||||
vm.realTimeRank = contest.real_time_rank;
|
||||
vm.startTime = contest.start_time.substring(0, 16).replace("T", " ");
|
||||
vm.endTime = contest.end_time.substring(0, 16).replace("T", " ");
|
||||
vm.password = contest.password;
|
||||
if (contest.contest_type == 0) { //contest_type == 0, 小组内比赛
|
||||
vm.isGlobal = false;
|
||||
for (var i = 0; i < vm.allGroups.length; i++) {
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"],
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "editorComponent"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
|
||||
avalon.ready(function () {
|
||||
|
||||
$("#edit-problem-form").validator()
|
||||
.on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()){
|
||||
if (!e.isDefaultPrevented()) {
|
||||
e.preventDefault();
|
||||
if (vm.testCaseId == "") {
|
||||
bsAlert("你还没有上传测试数据!");
|
||||
return false;
|
||||
}
|
||||
if (vm.description == "") {
|
||||
if (avalon.vmodels.contestProblemDescriptionEditor.content == "") {
|
||||
bsAlert("题目描述不能为空!");
|
||||
return false;
|
||||
}
|
||||
if (vm.timeLimit < 1000 || vm.timeLimit > 5000) {
|
||||
bsAlert("保证时间限制是一个1000-5000的合法整数");
|
||||
if (vm.timeLimit < 30 || vm.timeLimit > 5000) {
|
||||
bsAlert("保证时间限制是一个30-5000的合法整数");
|
||||
return false;
|
||||
}
|
||||
if (vm.samples.length == 0) {
|
||||
@@ -31,33 +31,34 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
}
|
||||
var ajaxData = {
|
||||
title: vm.title,
|
||||
description: vm.description,
|
||||
description: avalon.vmodels.contestProblemDescriptionEditor.content,
|
||||
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,
|
||||
hint: avalon.vmodels.contestProblemHintEditor.content,
|
||||
visible: vm.visible,
|
||||
contest_id: avalon.vmodels.admin.contestId,
|
||||
input_description: vm.inputDescription,
|
||||
output_description: vm.outputDescription,
|
||||
sort_index: vm.sortIndex,
|
||||
sort_index: vm.sortIndex
|
||||
};
|
||||
if (vm.contestMode == '2') {
|
||||
if (!vm.score) {
|
||||
bsAlert("请输入有效的分值!")
|
||||
return false;
|
||||
}
|
||||
ajaxData.score = vm.score;
|
||||
|
||||
if (avalon.vmodels.admin.contestProblemStatus == "edit") {
|
||||
var method = "put";
|
||||
ajaxData["id"] = avalon.vmodels.admin.problemId;
|
||||
var alertContent = "题目编辑成功";
|
||||
}
|
||||
var method = "post";
|
||||
if (avalon.vmodels.admin.$problemId) {
|
||||
method = "put";
|
||||
ajaxData.id = avalon.vmodels.admin.$problemId;
|
||||
else {
|
||||
var method = "post";
|
||||
var alertContent = "题目创建成功";
|
||||
}
|
||||
|
||||
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});
|
||||
ajaxData.samples.push({
|
||||
input: vm.samples.$model[i].input,
|
||||
output: vm.samples.$model[i].output
|
||||
});
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
@@ -69,8 +70,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
contentType: "application/json;charset=UTF-8",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("题目编辑成功!");
|
||||
vm.goBack(true);
|
||||
bsAlert(alertContent);
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
@@ -82,93 +82,114 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
}
|
||||
});
|
||||
|
||||
if (!avalon.vmodels.editProblem)
|
||||
var vm = avalon.define({
|
||||
$id: "editProblem",
|
||||
title: "",
|
||||
description: "",
|
||||
timeLimit: 0,
|
||||
memoryLimit: 0,
|
||||
samples: [],
|
||||
hint: "",
|
||||
sortIndex: "",
|
||||
visible: true,
|
||||
inputDescription: "",
|
||||
outputDescription: "",
|
||||
testCaseIdd: "",
|
||||
contestMode: 0,
|
||||
score: 1,
|
||||
uploadSuccess: false,
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
else
|
||||
vm = avalon.vmodels.editProblem;
|
||||
if (!avalon.vmodels.editProblem)
|
||||
var vm = avalon.define({
|
||||
$id: "editProblem",
|
||||
title: "",
|
||||
description: "",
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 128,
|
||||
samples: [],
|
||||
hint: "",
|
||||
sortIndex: "",
|
||||
visible: true,
|
||||
inputDescription: "",
|
||||
outputDescription: "",
|
||||
testCaseId: "",
|
||||
testCaseList: [],
|
||||
uploadSuccess: false,
|
||||
|
||||
contestProblemDescriptionEditor: {
|
||||
editorId: "contest-problem-description-editor",
|
||||
placeholder: "题目描述"
|
||||
},
|
||||
contestProblemHintEditor: {
|
||||
editorId: "contest-problem-hint-editor",
|
||||
placeholder: "提示"
|
||||
},
|
||||
|
||||
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) {
|
||||
avalon.vmodels.admin.template_url = "template/contest/problem_list.html";
|
||||
}
|
||||
});
|
||||
else {
|
||||
var vm = avalon.vmodels.editProblem;
|
||||
title = "";
|
||||
description = "";
|
||||
timeLimit = 1000;
|
||||
memoryLimit = 128;
|
||||
samples = [];
|
||||
hint = "";
|
||||
sortIndex = "";
|
||||
visible = true;
|
||||
inputDescription = "";
|
||||
outputDescription = "";
|
||||
testCaseId = "";
|
||||
testCaseList = [];
|
||||
uploadSuccess = false;
|
||||
}
|
||||
|
||||
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++) {
|
||||
for (var key in response.data.file_list) {
|
||||
vm.testCaseList.push({
|
||||
input: response.data.file_list.input[i],
|
||||
output: response.data.file_list.output[i]
|
||||
});
|
||||
input: response.data.file_list[key].input_name,
|
||||
output: response.data.file_list[key].output_name
|
||||
})
|
||||
}
|
||||
vm.uploadSuccess = true;
|
||||
bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
|
||||
}
|
||||
});
|
||||
|
||||
vm.contestMode = avalon.vmodels.admin.$contestMode;
|
||||
if (avalon.vmodels.admin.$problemId){
|
||||
if (avalon.vmodels.admin.contestProblemStatus == "edit") {
|
||||
$.ajax({
|
||||
url: "/api/admin/contest_problem/?contest_problem_id=" + avalon.vmodels.admin.$problemId,
|
||||
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 { // Edit mode load the problem data
|
||||
else {
|
||||
var problem = data.data;
|
||||
vm.testCaseList = [];
|
||||
vm.sortIndex = problem.sort_index;
|
||||
vm.title = problem.title;
|
||||
vm.description = problem.description;
|
||||
vm.timeLimit = problem.time_limit;
|
||||
vm.memoryLimit = problem.memory_limit;
|
||||
vm.hint = problem.hint;
|
||||
vm.visible = problem.visible;
|
||||
vm.inputDescription = problem.input_description;
|
||||
vm.testCaseList = [];
|
||||
vm.sortIndex = problem.sort_index;
|
||||
vm.title = problem.title;
|
||||
avalon.vmodels.contestProblemDescriptionEditor.content = problem.description;
|
||||
vm.timeLimit = problem.time_limit;
|
||||
vm.memoryLimit = problem.memory_limit;
|
||||
vm.hint = problem.hint;
|
||||
vm.visible = problem.visible;
|
||||
vm.inputDescription = problem.input_description;
|
||||
vm.outputDescription = problem.output_description;
|
||||
vm.score = problem.score;
|
||||
vm.samples = [];
|
||||
vm.testCaseId = problem.test_case_id;
|
||||
vm.score = problem.score;
|
||||
vm.testCaseId = problem.test_case_id;
|
||||
vm.samples = [];
|
||||
for (var i = 0; i < problem.samples.length; i++) {
|
||||
vm.samples.push({
|
||||
input: problem.samples[i].input,
|
||||
@@ -176,26 +197,32 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
visible: false
|
||||
})
|
||||
}
|
||||
hintEditor.setValue(vm.hint);
|
||||
descriptionEditor.setValue(vm.description);
|
||||
avalon.vmodels.contestProblemHintEditor.content = problem.hint;
|
||||
$.ajax({
|
||||
url: "/api/admin/test_case_upload/?test_case_id=" + vm.testCaseId,
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
if (response.code) {
|
||||
bsAlert(response.data);
|
||||
}
|
||||
else {
|
||||
vm.testCaseList = [];
|
||||
for (var key in response.data.file_list) {
|
||||
vm.testCaseList.push({
|
||||
input: response.data.file_list[key].input_name,
|
||||
output: response.data.file_list[key].output_name
|
||||
})
|
||||
}
|
||||
vm.uploadSuccess = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else { //Create new problem Set default values
|
||||
vm.testCaseList = [];
|
||||
vm.title = "";
|
||||
vm.timeLimit = 1000;
|
||||
vm.memoryLimit = 256;
|
||||
vm.samples = [];
|
||||
vm.visible = true;
|
||||
vm.inputDescription = "";
|
||||
vm.outputDescription = "";
|
||||
vm.testCaseId = "";
|
||||
vm.sortIndex = "";
|
||||
vm.score = 0;
|
||||
hintEditor.setValue("");
|
||||
descriptionEditor.setValue("");
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
avalon.scan();
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfTokenHeader, bsAlert) {
|
||||
|
||||
avalon.ready(function () {
|
||||
|
||||
if (avalon.vmodels.contestSubmissionList){
|
||||
var vm = avalon.vmodels.contestSubmissionList;
|
||||
}
|
||||
else {
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "contestSubmissionList",
|
||||
submissionList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
totalPage: 1,
|
||||
results : {
|
||||
0: "Accepted",
|
||||
1: "Runtime Error",
|
||||
2: "Time Limit Exceeded",
|
||||
3: "Memory Limit Exceeded",
|
||||
4: "Compile Error",
|
||||
5: "Format Error",
|
||||
6: "Wrong Answer",
|
||||
7: "System Error",
|
||||
8: "Waiting"
|
||||
},
|
||||
getNext: function () {
|
||||
if (!vm.nextPage)
|
||||
return;
|
||||
getPageData(vm.page + 1);
|
||||
},
|
||||
getPrevious: function () {
|
||||
if (!vm.previousPage)
|
||||
return;
|
||||
getPageData(vm.page - 1);
|
||||
},
|
||||
getBtnClass: function (btn) {
|
||||
if (btn == "next") {
|
||||
return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
}
|
||||
else {
|
||||
return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
}
|
||||
},
|
||||
getPage: function (page_index) {
|
||||
if (!page_index)
|
||||
var page_index = vm.page;
|
||||
getPageData(page_index);
|
||||
},
|
||||
showSubmissionDetailPage: function (submissionId) {
|
||||
|
||||
},
|
||||
goBack: function(check){
|
||||
vm.$fire("up!showContestListPage");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getPageData(1);
|
||||
|
||||
function getPageData(page) {
|
||||
var url = "/api/admin/contest_submission/?paging=true&page=" + page + "&page_size=10&contest_id=" + avalon.vmodels.admin.$contestId;
|
||||
if (avalon.vmodels.admin.$problemId)
|
||||
url += "&problem_id=" + avalon.vmodels.admin.$problemId
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: "json",
|
||||
method: "get",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
vm.submissionList = data.data.results;
|
||||
vm.totalPage = data.data.total_page;
|
||||
vm.previousPage = data.data.previous_page;
|
||||
vm.nextPage = data.data.next_page;
|
||||
vm.page = page;
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
avalon.scan();
|
||||
});
|
||||
@@ -79,6 +79,20 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
|
||||
if (avalon.vmodels.addProblem) {
|
||||
var vm = avalon.vmodels.addProblem;
|
||||
vm.title = "";
|
||||
vm.timeLimit = 1000;
|
||||
vm.memoryLimit = 128;
|
||||
vm.samples = [{input: "", output: "", "visible": true}];
|
||||
vm.visible = true;
|
||||
vm.difficulty = "1";
|
||||
vm.tags = [];
|
||||
vm.inputDescription = "";
|
||||
vm.outputDescription = "";
|
||||
vm.testCaseId = "";
|
||||
vm.testCaseList = [];
|
||||
vm.uploadSuccess = false;
|
||||
vm.source = "";
|
||||
vm.uploadProgress = 0;
|
||||
}
|
||||
else
|
||||
var vm = avalon.define({
|
||||
@@ -135,17 +149,17 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
vm.testCaseId = response.data.test_case_id;
|
||||
vm.uploadSuccess = true;
|
||||
vm.testCaseList = [];
|
||||
for (var i = 0; i < response.data.file_list.input.length; i++) {
|
||||
for (var key in response.data.file_list) {
|
||||
vm.testCaseList.push({
|
||||
input: response.data.file_list.input[i],
|
||||
output: response.data.file_list.output[i]
|
||||
});
|
||||
input: response.data.file_list[key].input_name,
|
||||
output: response.data.file_list[key].output_name
|
||||
})
|
||||
}
|
||||
bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
|
||||
}
|
||||
},
|
||||
function (file, percentage) {
|
||||
vm.uploadProgress = percentage;
|
||||
vm.uploadProgress = parseInt(percentage * 100);
|
||||
});
|
||||
|
||||
var tagAutoCompleteList = [];
|
||||
|
||||
@@ -137,11 +137,11 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
vm.testCaseId = response.data.test_case_id;
|
||||
vm.uploadSuccess = true;
|
||||
vm.testCaseList = [];
|
||||
for (var i = 0; i < response.data.file_list.input.length; i++) {
|
||||
for(var key in response.data.file_list){
|
||||
vm.testCaseList.push({
|
||||
input: response.data.file_list.input[i],
|
||||
output: response.data.file_list.output[i]
|
||||
});
|
||||
input: response.data.file_list[key].input_name,
|
||||
output: response.data.file_list[key].output_name
|
||||
})
|
||||
}
|
||||
bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user