Merge branch 'dev' into virusdefender-dev
* 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
This commit is contained in:
5
static/src/css/contest/add_contest.css
Normal file
5
static/src/css/contest/add_contest.css
Normal file
@@ -0,0 +1,5 @@
|
||||
.group-tag {
|
||||
padding-left: 5px; color: #46799b; background: #e0eaf1; white-space: nowrap;
|
||||
overflow: hidden; cursor: pointer; border-radius: 2px 0 0 2px;
|
||||
float: left; padding: 0 4px;box-sizing: border-box;list-style-type: none; margin: 5px;
|
||||
}
|
||||
@@ -75,6 +75,9 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
||||
groupId: -1,
|
||||
problemId: -1,
|
||||
adminNavList: [],
|
||||
$contestMode: -1,
|
||||
$problemId: -1,
|
||||
$contestId: -1,
|
||||
hide_loading: function () {
|
||||
$("#loading-gif").hide();
|
||||
},
|
||||
@@ -123,6 +126,18 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
|
||||
vm.template_url = "template/problem/submission_list.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 (problemId) {
|
||||
vm.problemId = problemId;
|
||||
vm.template_url = "template/contest/contest_list.html";
|
||||
});
|
||||
|
||||
avalon.scan();
|
||||
|
||||
window.onhashchange = function () {
|
||||
|
||||
166
static/src/js/app/admin/contest/addContest.js
Normal file
166
static/src/js/app/admin/contest/addContest.js
Normal file
@@ -0,0 +1,166 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
|
||||
"validator"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
|
||||
//avalon.vmodels.add_contest = null;
|
||||
$("#add-contest-form").validator().on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()){
|
||||
e.preventDefault();
|
||||
var ajaxData = {
|
||||
title: vm.title,
|
||||
description: vm.description,
|
||||
mode: vm.mode,
|
||||
contest_type: 0,
|
||||
show_rank: vm.showRank,
|
||||
show_user_submission: vm.showSubmission,
|
||||
start_time: vm.startTime,
|
||||
end_time: vm.endTime,
|
||||
visible: false
|
||||
};
|
||||
if (vm.choseGroupList.length == 0) {
|
||||
bsAlert("你没有选择参赛用户!");
|
||||
return false;
|
||||
}
|
||||
if (vm.choseGroupList[0].id == 0) { //everyone | public contest
|
||||
if (vm.password) {
|
||||
ajaxData.password = vm.password;
|
||||
ajaxData.contest_type = 2;
|
||||
}
|
||||
else{
|
||||
ajaxData.contest_type = 1;
|
||||
}
|
||||
}
|
||||
else { // Add groups info
|
||||
ajaxData.groups = [];
|
||||
for (var i = 0; vm.choseGroupList[i]; i++)
|
||||
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
|
||||
}
|
||||
|
||||
$.ajax({ // Add contest
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/contest/",
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "post",
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
|
||||
vm.title = "";
|
||||
vm.description = "";
|
||||
vm.startTime = "";
|
||||
vm.endTime = "";
|
||||
vm.password = "";
|
||||
vm.mode = "";
|
||||
vm.showRank = false;
|
||||
vm.showSubmission = false;
|
||||
vm.group = "-1";
|
||||
vm.groupList = [];
|
||||
vm.choseGroupList = [];
|
||||
vm.passwordUsable = false;
|
||||
location.hash = "#contest/contest_list";
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
editor("#editor");
|
||||
if (avalon.vmodels.add_contest)
|
||||
var vm = avalon.vmodels.add_contest;
|
||||
else
|
||||
var vm = avalon.define({
|
||||
$id: "add_contest",
|
||||
title: "",
|
||||
description: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
password: "",
|
||||
mode: "",
|
||||
showRank: false,
|
||||
showSubmission: false,
|
||||
group: "-1",
|
||||
groupList: [],
|
||||
choseGroupList: [],
|
||||
passwordUsable: false,
|
||||
addGroup: function() {
|
||||
if (vm.group == -1) return;
|
||||
if (vm.groupList[vm.group].id == 0){
|
||||
vm.passwordUsable = true;
|
||||
vm.choseGroupList = [];
|
||||
for (var key in vm.groupList){
|
||||
vm.groupList[key].chose = true;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.group]. chose = true;
|
||||
vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
|
||||
vm.group = -1;
|
||||
},
|
||||
removeGroup: function(groupIndex){
|
||||
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
|
||||
vm.passwordUsable = false;
|
||||
for (key in vm.groupList){
|
||||
vm.groupList[key].chose = false;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
|
||||
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({ // Get current user type
|
||||
url: "/api/user/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (data.data.admin_type == 2) { // Is super user
|
||||
vm.isGlobal = true;
|
||||
vm.groupList.push({id:0,name:"所有人",chose:false});
|
||||
}
|
||||
$.ajax({ // Get the group list of current user
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/group/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (!data.data.length) {
|
||||
bsAlert("您的用户权限只能创建组内比赛,但是您还没有创建过小组");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
var item = data.data[i];
|
||||
item["chose"] = false;
|
||||
vm.groupList.push(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
avalon.scan();
|
||||
|
||||
$("#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"
|
||||
});
|
||||
});
|
||||
@@ -1,231 +0,0 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
|
||||
"validator"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
avalon.vmodels.add_contest = null;
|
||||
$("#add-contest-form").validator().on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()){
|
||||
e.preventDefault();
|
||||
var ajaxData = {
|
||||
title: vm.title,
|
||||
description: vm.description,
|
||||
mode: vm.mode,
|
||||
contest_type: 0,
|
||||
show_rank: vm.showRank,
|
||||
show_user_submission: vm.showSubmission,
|
||||
//password: vm.password,
|
||||
start_time: vm.startTime,
|
||||
end_time: vm.endTime,
|
||||
visible: true
|
||||
};
|
||||
if (vm.choseGroupList[0].id == 0) //everyone | public contest
|
||||
if (vm.password == "")
|
||||
ajaxData.contest_type = 1;
|
||||
else{
|
||||
ajaxData.password = vm.password;
|
||||
}
|
||||
else { // Add groups info
|
||||
ajaxData.groups = [];
|
||||
for (var i = 0; vm.choseGroupList[i]; i++)
|
||||
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
|
||||
}
|
||||
|
||||
|
||||
console.log(ajaxData);
|
||||
$.ajax({
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/contest/",
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "post",
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("添加成功!");
|
||||
console.log(data);
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
console.log(JSON.stringify(ajaxData));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
editor("#editor");
|
||||
editor("#problemDescriptionEditor");
|
||||
editor("#problemHintEditor");
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "add_contest",
|
||||
title: "",
|
||||
description: "",
|
||||
startTime: "",
|
||||
endTime: "",
|
||||
password: "",
|
||||
mode: "",
|
||||
showRank: false,
|
||||
showSubmission: false,
|
||||
problems: [],
|
||||
editingProblemId: 0,
|
||||
editSamples: [],
|
||||
editTestCaseList: [],
|
||||
group: "-1",
|
||||
groupList: [],
|
||||
choseGroupList: [],
|
||||
showProblemEditArea: function (problemIndex) {
|
||||
if (vm.editingProblemId == problemIndex){
|
||||
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
|
||||
vm.editingProblemId = 0;
|
||||
}
|
||||
else {
|
||||
if (vm.editingProblemId)
|
||||
{
|
||||
vm.problems[vm.editingProblemId-1].samples = vm.editSamples;
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
|
||||
}
|
||||
vm.editingProblemId = problemIndex;
|
||||
vm.editSamples = [];
|
||||
vm.editSamples = vm.problems[vm.editingProblemId-1].samples;
|
||||
vm.editTestCaseList = [];
|
||||
vm.editTestCaseList = vm.problems[vm.editingProblemId-1].testCaseList;
|
||||
}
|
||||
},
|
||||
passwordUsable: false,
|
||||
add_problem: function () {
|
||||
var problem = {
|
||||
title: "",
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 256,
|
||||
description: "",
|
||||
samples: [],
|
||||
visible: true,
|
||||
test_case_id: "",
|
||||
testCaseList: [],
|
||||
hint: "",
|
||||
score: 0,
|
||||
uploadSuccess: false,
|
||||
};
|
||||
vm.problems.push(problem);
|
||||
vm.showProblemEditArea(vm.problems.length);
|
||||
},
|
||||
del_problem: function (problemIndex) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
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 () {
|
||||
vm.editSamples.push({visible: true, input: "", output: ""});
|
||||
},
|
||||
del_sample: function (sample) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
editSamples.remove(sample);
|
||||
}
|
||||
},
|
||||
getBtnContent: function (item) {
|
||||
if (item.visible)
|
||||
return "折叠";
|
||||
return "展开";
|
||||
},
|
||||
addGroup: function() {
|
||||
if (vm.group == -1) return;
|
||||
if (vm.groupList[vm.group].id == 0){
|
||||
vm.passwordUsable = true;
|
||||
vm.choseGroupList = [];
|
||||
for (var key in vm.groupList){
|
||||
vm.groupList[key].chose = true;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.group]. chose = true;
|
||||
vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
|
||||
},
|
||||
unchose: function(groupIndex){
|
||||
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
|
||||
vm.passwordUsable = false;
|
||||
for (key in vm.groupList){
|
||||
vm.groupList[key].chose = false;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
|
||||
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
|
||||
}
|
||||
});
|
||||
|
||||
var isSuperAdmin = true;
|
||||
$.ajax({ //用于获取该用户创建的所有小组的ajax请求
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/group/?my_group=true",
|
||||
dataType: "json",
|
||||
method: "get",
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (isSuperAdmin)
|
||||
vm.groupList.push({id:0, name:"所有人", chose: false});
|
||||
for (var key in data.data) {
|
||||
data.data[key].chose = false;
|
||||
vm.groupList.push(data.data[key]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
console.log(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) {
|
||||
if (respond.code)
|
||||
bsAlert(respond.data);
|
||||
else {
|
||||
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.editTestCaseList.push({
|
||||
input: respond.data.file_list.input[i],
|
||||
output: respond.data.file_list.output[i]
|
||||
});
|
||||
}
|
||||
vm.problems[vm.editingProblemId-1].testCaseList = vm.editTestCaseList;
|
||||
bsAlert("测试数据添加成功!共添加"+vm.editTestCaseList.length +"组测试数据");
|
||||
}
|
||||
},
|
||||
function(){
|
||||
if (vm.editingProblemId == 0)
|
||||
{
|
||||
bsAlert("你还未指定一道题目!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
avalon.scan();
|
||||
|
||||
$("#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"
|
||||
});
|
||||
});
|
||||
331
static/src/js/app/admin/contest/contestList.js
Normal file
331
static/src/js/app/admin/contest/contestList.js
Normal file
@@ -0,0 +1,331 @@
|
||||
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,
|
||||
show_rank: vm.editShowRank,
|
||||
show_user_submission: vm.editShowSubmission,
|
||||
start_time: vm.editStartTime,
|
||||
end_time: vm.editEndTime,
|
||||
visible: vm.editVisible
|
||||
};
|
||||
if (vm.choseGroupList.length == 0) {
|
||||
bsAlert("你没有选择参赛用户!");
|
||||
return false;
|
||||
}
|
||||
if (vm.editDescription == "") {
|
||||
bsAlert("比赛描述不能为空!");
|
||||
return false;
|
||||
}
|
||||
if (vm.choseGroupList[0].id == 0) { //everyone | public contest
|
||||
if (vm.editPassword) {
|
||||
ajaxData.password = vm.editPassword;
|
||||
ajaxData.contest_type = 2;
|
||||
}
|
||||
else{
|
||||
ajaxData.contest_type = 1;
|
||||
}
|
||||
}
|
||||
else { // Add groups info
|
||||
ajaxData.groups = [];
|
||||
for (var i = 0; vm.choseGroupList[i]; i++)
|
||||
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id))
|
||||
}
|
||||
|
||||
$.ajax({ // Add contest
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/contest/",
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(ajaxData),
|
||||
method: "put",
|
||||
contentType: "application/json",
|
||||
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= [];
|
||||
vm.previousPage= 0;
|
||||
vm.nextPage= 0;
|
||||
vm.page= 1;
|
||||
vm.totalPage= 1;
|
||||
vm.group= "-1";
|
||||
vm.groupList= [];
|
||||
vm.choseGroupList= [];
|
||||
vm.passwordUsable= false;
|
||||
vm.keyword= "";
|
||||
vm.editingContestId= 0;
|
||||
vm.editTitle= "";
|
||||
vm.editDescription= "";
|
||||
vm.editProblemList= [];
|
||||
vm.editPassword= "";
|
||||
vm.editStartTime= "";
|
||||
vm.editEndTime= "";
|
||||
vm.editMode= "";
|
||||
vm.editShowRank= false;
|
||||
vm.editShowSubmission= false;
|
||||
vm.editProblemList= [];
|
||||
vm.editVisible= false;
|
||||
vm.editChoseGroupList= [];
|
||||
vm.editingProblemContestIndex= 0;
|
||||
}
|
||||
else {
|
||||
var vm = avalon.define({
|
||||
$id: "contestList",
|
||||
contestList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
totalPage: 1,
|
||||
showVisibleOnly: false,
|
||||
group: "-1",
|
||||
groupList: [],
|
||||
choseGroupList: [],
|
||||
passwordUsable: false,
|
||||
keyword: "",
|
||||
editingContestId: 0,
|
||||
editTitle: "",
|
||||
editDescription: "",
|
||||
editProblemList: [],
|
||||
editPassword: "",
|
||||
editStartTime: "",
|
||||
editEndTime: "",
|
||||
editMode: "",
|
||||
editShowRank: false,
|
||||
editShowSubmission: false,
|
||||
editProblemList: [],
|
||||
editVisible: false,
|
||||
editChoseGroupList: [],
|
||||
editingProblemContestIndex: 0,
|
||||
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;
|
||||
if (vm.contestList[contestId-1].contest_type == 0) { //contest type == 0, contest in group
|
||||
//Clear the choseGroupList
|
||||
while (vm.choseGroupList.length) {
|
||||
vm.removeGroup(0);
|
||||
}
|
||||
|
||||
for (var i = 0; i < vm.contestList[contestId-1].groups.length; i++){
|
||||
var id = parseInt(vm.contestList[contestId-1].groups[i]);
|
||||
var index = 0;
|
||||
for (; vm.groupList[index]; index++) {
|
||||
if (vm.groupList[index].id == id)
|
||||
break;
|
||||
}
|
||||
vm.groupList[index].chose = true;
|
||||
vm.choseGroupList.push({
|
||||
name:vm.groupList[index].name,
|
||||
index:index,
|
||||
id:id
|
||||
});
|
||||
}
|
||||
}
|
||||
else{
|
||||
vm.group = "0";
|
||||
vm.addGroup()//vm.editChoseGroupList = [0]; id 0 is for the group of everyone~
|
||||
}
|
||||
vm.editShowRank = vm.contestList[contestId-1].show_rank;
|
||||
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;
|
||||
},
|
||||
addGroup: function() {
|
||||
if (vm.group == -1) return;
|
||||
if (vm.groupList[vm.group].id == 0){
|
||||
vm.passwordUsable = true;
|
||||
vm.choseGroupList = [];
|
||||
for (var i = 0; i < vm.groupList.length; i++) {
|
||||
vm.groupList[i].chose = true;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.group]. chose = true;
|
||||
// index of the group is relative. It is related to user
|
||||
vm.choseGroupList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
|
||||
vm.group = -1;
|
||||
},
|
||||
removeGroup: function(groupIndex){
|
||||
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){
|
||||
vm.passwordUsable = false;
|
||||
for (var i = 0; i < vm.groupList.length; i++) {
|
||||
vm.groupList[i].chose = false;
|
||||
}
|
||||
}
|
||||
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false;
|
||||
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]);
|
||||
},
|
||||
add_problem: function () {
|
||||
vm.$fire("up!showContestProblemPage", 0, vm.contestList[vm.editingProblemContestIndex-1].id, vm.editMode);
|
||||
},
|
||||
showProblemEditor: function(el) {
|
||||
vm.$fire("up!showContestProblemPage", el.id, vm.contestList[vm.editingProblemContestIndex-1].id, vm.editMode);
|
||||
},
|
||||
getYesOrNo: function(yORn) {
|
||||
if (yORn) return "是";
|
||||
return "否";
|
||||
}
|
||||
});
|
||||
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({ // Get current user type
|
||||
url: "/api/user/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (data.data.admin_type == 2) { // Is super user
|
||||
vm.isGlobal = true;
|
||||
vm.groupList.push({id:0,name:"所有人",chose:false});
|
||||
}
|
||||
$.ajax({ // Get the group list of current user
|
||||
beforeSend: csrfTokenHeader,
|
||||
url: "/api/admin/group/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (!data.data.length) {
|
||||
//this user have no group can use
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
var item = data.data[i];
|
||||
item["chose"] = false;
|
||||
vm.groupList.push(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
avalon.scan();
|
||||
});
|
||||
@@ -1,139 +0,0 @@
|
||||
require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "datetimePicker"], function ($, avalon, csrfTokenHeader, bsAlert, editor) {
|
||||
|
||||
avalon.ready(function () {
|
||||
if (avalon.vmodels.contestList) {
|
||||
vm = avalon.vmodels.contestList;
|
||||
vm.editingContest = 0;
|
||||
}
|
||||
else {
|
||||
var vm = avalon.define({
|
||||
$id: "contestList",
|
||||
contestList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
totalPage: 1,
|
||||
group: "-1",
|
||||
groupList: [],
|
||||
keyword: "",
|
||||
editingContestId: 0,
|
||||
editTitle: "",
|
||||
editProblemList: [],
|
||||
editPassword: "",
|
||||
editStartTime: "",
|
||||
editEndTime: "",
|
||||
editMode: "",
|
||||
editShowRank: false,
|
||||
editShowSubmission: false,
|
||||
editProblemList: [],
|
||||
editingProblemId: 0,
|
||||
editSamples: [],
|
||||
editTestCaseList: [],
|
||||
editChoseGroupList: [],
|
||||
modelNameList: ["ACM", "AC总数", "分数"],
|
||||
contestTypeNameList: ["小组赛", "公开赛", "有密码保护的公开赛"],
|
||||
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 (contestId == vm.editingContestId)
|
||||
vm.editingContestId = 0;
|
||||
else {
|
||||
vm.editingContestId = contestId;
|
||||
vm.editTitle = vm.contestList[contestId - 1].title;
|
||||
vm.editEndTime = vm.contestList[contestId - 1].end_time;
|
||||
vm.editPassword = vm.contestList[contestId - 1].password;
|
||||
vm.editStartTime = vm.contestList[contestId - 1].start_time;
|
||||
vm.editMode = vm.contestList[contestId - 1].mode;
|
||||
vm.editChoseGroupList = [];
|
||||
//= vm.contestList[contestId-1].group;//
|
||||
/*for (var key in vm.contestList[contestId-1].groups){
|
||||
var id = parseInt(vm.contestList[contestId-1].groups);
|
||||
for ()
|
||||
vm.editChoseGroupList.push({
|
||||
name:vm.groupList[vm.group].name,
|
||||
index:index,
|
||||
id:parseInt(vm.contestList[contestId-1].groups)
|
||||
});
|
||||
}*/
|
||||
vm.editShowRank = vm.contestList[contestId - 1].show_rank;
|
||||
vm.editShowSubmission = vm.contestList[contestId - 1].show_user_submission;
|
||||
//vm.editProblemList = vm.contestList[contestId-1].problems
|
||||
editor("#editor").setValue(vm.contestList[contestId - 1].description);
|
||||
vm.editingProblemList = vm.contestList[contestId - 1].problemList;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
getPageData(1);
|
||||
}
|
||||
|
||||
function getPageData(page) {
|
||||
|
||||
var url = "/api/admin/contest/?paging=true&page=" + page + "&page_size=10";
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var isSuperAdmin = true;
|
||||
|
||||
$.ajax({ //用于获取该用户创建的所有小组的ajax请求
|
||||
|
||||
url: "/api/admin/group/",
|
||||
method: "get",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
if (!data.data.length) {
|
||||
bsAlert("您的用户权限只能创建组内比赛,但是您还没有创建过小组");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < data.data.length; i++) {
|
||||
var item = data.data[i];
|
||||
item["chose"] = false;
|
||||
vm.groupList.push(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
avalon.scan();
|
||||
});
|
||||
203
static/src/js/app/admin/contest/editProblem.js
Normal file
203
static/src/js/app/admin/contest/editProblem.js
Normal file
@@ -0,0 +1,203 @@
|
||||
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()){
|
||||
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,
|
||||
};
|
||||
if (vm.contestMode == '2') {
|
||||
if (!vm.score) {
|
||||
bsAlert("请输入有效的分值!")
|
||||
return false;
|
||||
}
|
||||
ajaxData.score = vm.score;
|
||||
}
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
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 + "组测试数据");
|
||||
}
|
||||
});
|
||||
|
||||
vm.contestMode = avalon.vmodels.admin.$contestMode;
|
||||
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 { // Edit mode load the problem data
|
||||
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.outputDescription = problem.output_description;
|
||||
vm.score = problem.score;
|
||||
vm.samples = [];
|
||||
vm.testCaseId = problem.test_case_id;
|
||||
for (var i = 0; i < problem.samples.length; i++) {
|
||||
vm.samples.push({
|
||||
input: problem.samples[i].input,
|
||||
output: problem.samples[i].output,
|
||||
visible: false
|
||||
})
|
||||
}
|
||||
hintEditor.setValue(vm.hint);
|
||||
descriptionEditor.setValue(vm.description);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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,7 +1,7 @@
|
||||
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagEditor", "validator", "jqueryUI"],
|
||||
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
|
||||
avalon.ready(function () {
|
||||
avalon.vmodels.addProblem = null;
|
||||
|
||||
$("#add-problem-form").validator()
|
||||
.on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()){
|
||||
@@ -63,6 +63,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("题目添加成功!");
|
||||
location.hash = "problem/problem_list";
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
@@ -92,41 +93,61 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
|
||||
var hintEditor = editor("#hint");
|
||||
var problemDescription = editor("#problemDescription");
|
||||
|
||||
var vm = avalon.define({
|
||||
$id: "addProblem",
|
||||
title: "",
|
||||
description: "",
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 256,
|
||||
samples: [{input: "", output: "", "visible": true}],
|
||||
hint: "",
|
||||
visible: true,
|
||||
difficulty: 0,
|
||||
tags: [],
|
||||
inputDescription: "",
|
||||
outputDescription: "",
|
||||
testCaseId: "",
|
||||
testCaseList: [],
|
||||
uploadSuccess: false,
|
||||
source: "",
|
||||
addSample: function () {
|
||||
vm.samples.push({input: "", output: "", "visible": true});
|
||||
},
|
||||
delSample: function (sample) {
|
||||
if (confirm("你确定要删除么?")) {
|
||||
vm.samples.remove(sample);
|
||||
if (avalon.vmodels.addProblem) {
|
||||
var vm = avalon.vmodels.addProblem;
|
||||
vm.title = "";
|
||||
vm.description = "";
|
||||
vm.timeLimit = 1000;
|
||||
vm.memoryLimit = 256;
|
||||
vm.samples = [{input: "", output: "", "visible": true}];
|
||||
vm.hint = "";
|
||||
vm.visible = true;
|
||||
vm.difficulty = 0;
|
||||
vm.tags = [];
|
||||
vm.inputDescription = "";
|
||||
vm.outputDescription = "";
|
||||
vm.testCaseId = "";
|
||||
vm.testCaseList = [];
|
||||
vm.uploadSuccess = false;
|
||||
vm.source = "";
|
||||
hintEditor.setValue("");
|
||||
problemDescription.setValue("");
|
||||
}
|
||||
else
|
||||
var vm = avalon.define({
|
||||
$id: "addProblem",
|
||||
title: "",
|
||||
description: "",
|
||||
timeLimit: 1000,
|
||||
memoryLimit: 256,
|
||||
samples: [{input: "", output: "", "visible": true}],
|
||||
hint: "",
|
||||
visible: true,
|
||||
difficulty: 0,
|
||||
tags: [],
|
||||
inputDescription: "",
|
||||
outputDescription: "",
|
||||
testCaseId: "",
|
||||
testCaseList: [],
|
||||
uploadSuccess: false,
|
||||
source: "",
|
||||
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 "展开";
|
||||
}
|
||||
},
|
||||
toggleSample: function (sample) {
|
||||
sample.visible = !sample.visible;
|
||||
},
|
||||
getBtnContent: function (item) {
|
||||
if (item.visible)
|
||||
return "折叠";
|
||||
return "展开";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var tagAutoCompleteList = [];
|
||||
|
||||
@@ -3,8 +3,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
|
||||
avalon.ready(function () {
|
||||
|
||||
|
||||
|
||||
$("#edit-problem-form").validator()
|
||||
.on('submit', function (e) {
|
||||
if (!e.isDefaultPrevented()){
|
||||
@@ -66,6 +64,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
success: function (data) {
|
||||
if (!data.code) {
|
||||
bsAlert("题目编辑成功!");
|
||||
vm.showProblemListPage();
|
||||
}
|
||||
else {
|
||||
bsAlert(data.data);
|
||||
@@ -76,49 +75,60 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if(avalon.vmodels.editProblem){
|
||||
var vm = avalon.vmodels.editProblem;
|
||||
}
|
||||
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");
|
||||
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) {
|
||||
@@ -148,7 +158,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
}
|
||||
else {
|
||||
var problem = data.data;
|
||||
console.log(problem);
|
||||
vm.title = problem.title;
|
||||
vm.description = problem.description;
|
||||
vm.timeLimit = problem.time_limit;
|
||||
@@ -204,4 +213,4 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
|
||||
});
|
||||
avalon.scan();
|
||||
|
||||
});
|
||||
});
|
||||
@@ -41,10 +41,8 @@ require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfT
|
||||
vm.$fire("up!showProblemSubmissionPage", problemId);
|
||||
}
|
||||
});
|
||||
|
||||
getPageData(1);
|
||||
}
|
||||
|
||||
getPageData(1);
|
||||
function getPageData(page) {
|
||||
var url = "/api/admin/problem/?paging=true&page=" + page + "&page_size=10";
|
||||
if (vm.keyword != "")
|
||||
|
||||
@@ -40,6 +40,12 @@ require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfT
|
||||
},
|
||||
getPage: function (page_index) {
|
||||
getPageData(page_index);
|
||||
},
|
||||
showSubmissionDetailPage: function (submissionId) {
|
||||
|
||||
},
|
||||
showProblemListPage: function(){
|
||||
vm.$fire("up!showProblemListPage");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -66,9 +72,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfT
|
||||
});
|
||||
}
|
||||
|
||||
avalon.scan();
|
||||
|
||||
|
||||
});
|
||||
|
||||
avalon.scan();
|
||||
});
|
||||
@@ -3,58 +3,68 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "validator"], function ($,
|
||||
|
||||
// avalon:定义模式 userList
|
||||
avalon.ready(function () {
|
||||
avalon.vmodels.userList = null;
|
||||
var vm = avalon.define({
|
||||
$id: "userList",
|
||||
//通用变量
|
||||
userList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
editingUserId: 0,
|
||||
totalPage: 1,
|
||||
userType: ["一般用户", "管理员", "超级管理员"],
|
||||
keyword: "",
|
||||
showAdminOnly: false,
|
||||
//编辑区域同步变量
|
||||
username: "",
|
||||
realName: "",
|
||||
email: "",
|
||||
adminType: 0,
|
||||
id: 0,
|
||||
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) {
|
||||
return vm.nextPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
//avalon.vmodels.userList = null;
|
||||
if (avalon.vmodels.userList) {
|
||||
var vm = avalon.vmodels.userList;
|
||||
// initialize avalon object
|
||||
userList = []; previousPage= 0; nextPage= 0; page = 1;
|
||||
editingUserId= 0; totalPage = 1; keyword= ""; showAdminOnly= false;
|
||||
//user editor fields
|
||||
username= ""; realName= ""; email= ""; adminType= 0; id= 0;
|
||||
}
|
||||
else {
|
||||
var vm = avalon.define({
|
||||
$id: "userList",
|
||||
//通用变量
|
||||
userList: [],
|
||||
previousPage: 0,
|
||||
nextPage: 0,
|
||||
page: 1,
|
||||
editingUserId: 0,
|
||||
totalPage: 1,
|
||||
userType: ["一般用户", "管理员", "超级管理员"],
|
||||
keyword: "",
|
||||
showAdminOnly: false,
|
||||
//编辑区域同步变量
|
||||
username: "",
|
||||
realName: "",
|
||||
email: "",
|
||||
adminType: 0,
|
||||
id: 0,
|
||||
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";
|
||||
}
|
||||
},
|
||||
editUser: function (user) { //点击编辑按钮的事件,显示/隐藏编辑区
|
||||
vm.username = user.username;
|
||||
vm.realName = user.real_name;
|
||||
vm.adminType = user.admin_type;
|
||||
vm.email = user.email;
|
||||
vm.id = user.id;
|
||||
if (vm.editingUserId == user.id)
|
||||
vm.editingUserId = 0;
|
||||
else
|
||||
vm.editingUserId = user.id;
|
||||
},
|
||||
search: function () {
|
||||
getPageData(1);
|
||||
}
|
||||
else {
|
||||
return vm.previousPage ? "btn btn-primary" : "btn btn-primary disabled";
|
||||
}
|
||||
},
|
||||
editUser: function (user) { //点击编辑按钮的事件,显示/隐藏编辑区
|
||||
vm.username = user.username;
|
||||
vm.realName = user.real_name;
|
||||
vm.adminType = user.admin_type;
|
||||
vm.email = user.email;
|
||||
vm.id = user.id;
|
||||
if (vm.editingUserId == user.id)
|
||||
vm.editingUserId = 0;
|
||||
else
|
||||
vm.editingUserId = user.id;
|
||||
},
|
||||
search: function () {
|
||||
getPageData(1);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
vm.$watch("showAdminOnly", function () {
|
||||
getPageData(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user