[前端]把添加比赛和添加比赛问题分开了,就是把添加问题模块从添加比赛页面删除了

This commit is contained in:
esp
2015-08-23 17:41:33 +08:00
parent b5313ce908
commit 018727ffbc
2 changed files with 79 additions and 283 deletions

View File

@@ -1,6 +1,8 @@
require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker", require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "datetimePicker",
"validator"], "validator"],
function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) { function ($, avalon, editor, uploader, bsAlert, csrfTokenHeader) {
avalon.vmodels.add_contest = null; avalon.vmodels.add_contest = null;
$("#add-contest-form").validator().on('submit', function (e) { $("#add-contest-form").validator().on('submit', function (e) {
if (!e.isDefaultPrevented()){ if (!e.isDefaultPrevented()){
@@ -12,12 +14,15 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
contest_type: 0, contest_type: 0,
show_rank: vm.showRank, show_rank: vm.showRank,
show_user_submission: vm.showSubmission, show_user_submission: vm.showSubmission,
//password: vm.password,
start_time: vm.startTime, start_time: vm.startTime,
end_time: vm.endTime, end_time: vm.endTime,
visible: true visible: false
}; };
if (vm.choseGroupList[0].id == 0) //everyone | public contest if (vm.choseGroupsList.length == 0) {
bsAlert("你没有选择参赛用户!");
return false;
}
if (vm.choseGroupsList[0].id == 0) //everyone | public contest
if (vm.password == "") if (vm.password == "")
ajaxData.contest_type = 1; ajaxData.contest_type = 1;
else{ else{
@@ -25,13 +30,12 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
} }
else { // Add groups info else { // Add groups info
ajaxData.groups = []; ajaxData.groups = [];
for (var i = 0; vm.choseGroupList[i]; i++) for (var i = 0; vm.choseGroupsList[i]; i++)
ajaxData.groups.push(parseInt(vm.choseGroupList[i].id)) ajaxData.groups.push(parseInt(vm.choseGroupsList[i].id))
} }
console.log(ajaxData); console.log(ajaxData);
$.ajax({ $.ajax({ // Add contest
beforeSend: csrfTokenHeader, beforeSend: csrfTokenHeader,
url: "/api/admin/contest/", url: "/api/admin/contest/",
dataType: "json", dataType: "json",
@@ -41,7 +45,8 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
contentType: "application/json", contentType: "application/json",
success: function (data) { success: function (data) {
if (!data.code) { if (!data.code) {
bsAlert("添加成功!"); bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)");
location.hash = "#contest/contest_list";
console.log(data); console.log(data);
} }
else { else {
@@ -56,8 +61,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
}); });
editor("#editor"); editor("#editor");
editor("#problemDescriptionEditor");
editor("#problemHintEditor");
var vm = avalon.define({ var vm = avalon.define({
$id: "add_contest", $id: "add_contest",
@@ -69,150 +72,70 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date
mode: "", mode: "",
showRank: false, showRank: false,
showSubmission: false, showSubmission: false,
problems: [],
editingProblemId: 0,
editSamples: [],
editTestCaseList: [],
group: "-1", group: "-1",
groupList: [], groupList: [],
choseGroupList: [], choseGroupsList: [],
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, 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() { addGroup: function() {
if (vm.group == -1) return; if (vm.group == -1) return;
if (vm.groupList[vm.group].id == 0){ if (vm.groupList[vm.group].id == 0){
vm.passwordUsable = true; vm.passwordUsable = true;
vm.choseGroupList = []; vm.choseGroupsList = [];
for (var key in vm.groupList){ for (var key in vm.groupList){
vm.groupList[key].chose = true; vm.groupList[key].chose = true;
} }
} }
vm.groupList[vm.group]. 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.choseGroupsList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id});
vm.group = -1;
}, },
unchose: function(groupIndex){ removeGroup: function(groupIndex){
if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){ if (vm.groupList[vm.choseGroupsList[groupIndex].index].id == 0){
vm.passwordUsable = false; vm.passwordUsable = false;
for (key in vm.groupList){ for (key in vm.groupList){
vm.groupList[key].chose = false; vm.groupList[key].chose = false;
} }
} }
vm.groupList[vm.choseGroupList[groupIndex].index].chose = false; vm.groupList[vm.choseGroupsList[groupIndex].index].chose = false;
vm.choseGroupList.remove(vm.choseGroupList[groupIndex]); vm.choseGroupsList.remove(vm.choseGroupsList[groupIndex]);
} }
}); });
var isSuperAdmin = true; $.ajax({ // Get current user type
$.ajax({ //用于获取该用户创建的所有小组的ajax请求 url: "/api/user/",
beforeSend: csrfTokenHeader, method: "get",
url: "/api/admin/group/?my_group=true", dataType: "json",
dataType: "json", success: function (data) {
method: "get", if (!data.code) {
contentType: "application/json", if (data.data.admin_type == 2) { // Is super user
success: function (data) { vm.isGlobal = true;
if (!data.code) { vm.groupList.push({id:0,name:"所有人",chose:false});
if (isSuperAdmin) }
vm.groupList.push({id:0, name:"所有人", chose: false}); $.ajax({ // Get the group list of current user
for (var key in data.data) { beforeSend: csrfTokenHeader,
data.data[key].chose = false; url: "/api/admin/group/",
vm.groupList.push(data.data[key]); method: "get",
} dataType: "json",
} success: function (data) {
else { if (!data.code) {
bsAlert(data.data); if (!data.data.length) {
console.log(data); bsAlert("您的用户权限只能创建组内比赛,但是您还没有创建过小组");
} return;
} }
}); for (var i = 0; i < data.data.length; i++) {
var item = data.data[i];
item["chose"] = false;
vm.groupList.push(item);
uploader("#uploader", "/api/admin/test_case_upload/", function (file, respond) { }
if (respond.code) }
bsAlert(respond.data); else {
else { bsAlert(data.data);
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(); avalon.scan();

View File

@@ -7,7 +7,8 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<input type="text" name="name" class="form-control" ms-duplex="title" <input type="text" name="name" class="form-control" ms-duplex="title"
data-error="请填写比赛名称(名称不能超过50个字)" required> data-error="请填写比赛名称(名称不能超过50个字)" ms-attr-readonly="contestCreated" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
</div> </div>
@@ -17,51 +18,46 @@
<div class="col-md-12"> <div class="col-md-12">
<div class="form-group"> <div class="form-group">
<textarea id="editor" placeholder="这里输入内容" autofocus ms-duplex="description"></textarea> <textarea id="editor" placeholder="这里输入内容" autofocus ms-duplex="description"></textarea>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
<small ms-visible="description==''" style="color:red">请填写比赛描述</small> <small ms-visible="description==''" style="color:red">请填写比赛描述</small>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>开始时间</label> <label>开始时间</label>
</div>
<div class="col-md-6">
<label>结束时间</label>
</div>
<div class="col-md-6">
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="start_time" id="contest_start_time" <input type="text" class="form-control" name="start_time" id="contest_start_time"
ms-duplex="startTime" data-error="请填写比赛开始时间" required> ms-duplex="startTime" data-error="请填写比赛开始时间" required>
<div class="help-block with-errors"></div> <div class="help-block with-errors"></div>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>结束时间</label>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="end_time" id="contest_end_time" <input type="text" class="form-control" name="end_time" id="contest_end_time"
ms-duplex="endTime" data-error="请填写比赛结束时间" required> ms-duplex="endTime" data-error="请填写比赛结束时间" required>
<div class="help-block with-errors"></div>
</div> <div class="help-block with-errors"></div>
</div>
<div class="col-md-6">
<label>允许参加的用户</label>
</div>
<div class="col-md-6" >
<label>密码保护</label>
</div>
<div class="col-md-6">
<div class="form-group">
<select class="form-control" name="password" ms-duplex="group" ms-change="addGroup" value="-1">
<option value="-1">请选择</option>
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option>
</select>
</div> </div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>允许参加的用户</label>
<div class="form-group"> <div class="form-group">
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password" ms-attr-readonly="!passwordUsable"> <select class="form-control" name="password" ms-duplex="group" ms-change="addGroup" value="-1">
<option value="-1">请选择</option>
<option ms-repeat="groupList" ms-attr-value="$index" ms-visible="!el.chose">{{el.name}}</option>
</select>
</div>
</div>
<div class="col-md-6" ms-visible="passwordUsable">
<label>密码保护</label>
<div class="form-group">
<input type="text" class="form-control" name="password" placeholder="留空就是公开赛" ms-duplex="password">
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div ms-repeat="choseGroupList" class="group-tag" ms-click="unchose($index)">{{el.name}}</div> <div ms-repeat="choseGroupsList" class="group-tag" ms-click="removeGroup($index)">{{el.name}}</div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label>排名方式</label> <label>排名方式</label>
@@ -94,135 +90,12 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="form-group"> <div class="form-group">
<label class="text"><input type="checkbox" ms-duplex-checked="showSbumission"> <label class="text"><input type="checkbox" ms-duplex-checked="showSubmission">
<small>允许查看提交记录</small> <small>允许查看提交记录</small>
</label> </label>
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<label>添加题目</label>
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="add_problem()">添加</a>
<table class="table table-striped">
<tr>
<th>编号</th>
<th>题目</th>
<th>测试数据</th>
<td></td>
</tr>
<tr ms-repeat="problems">
<td>题目{{ $index+1 }}</td>
<td>{{ el.title }}</td>
<td>{{ el.testCaseList.length }}组</td>
<td>
<a href="javascript:void(0)"class="btn-sm btn-info" ms-click="showProblemEditArea($index+1)">编辑</a>
<a href="javascript:void(0)"class="btn-sm btn-danger" ms-click="del_problem($index+1)">删除</a>
</td>
</tr>
</table>
</div>
<div class="col-md-12">
<div class="problem" ms-visible="editingProblemId">
<div class="panel panel-default problem-panel">
<div class="panel-heading">
<span class="panel-title">题目{{editingProblemId}} </span>
<a href="javascript:void(0)" class="btn btn-primary btn-sm" ms-click="hidden()">隐藏</a>
<a href="javascript:void(0)" class="btn btn-danger btn-sm" ms-click="del_problem(editingProblemId)">删除</a>
</div>
<div class="panel-body" >
<div class="form-group col-md-12">
<label>题目标题</label>
<input type="text" name="problemName" class="form-control" ms-duplex="problems[editingProblemId-1].title"data-error="请填写题目标题" required>
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-md-12">
<label>题目描述</label>
<textarea id="problemDescriptionEditor" placeholder="这里输入内容"
ms-duplex="problems[editingProblemId-1].description"></textarea>
<small ms-visible="editDescription==''" style="color:red">请填写题目描述</small>
</div>
<div class="form-group col-md-12">
<label>提示</label>
<textarea id="problemHintEditor" placeholder="这里输入内容"
ms-duplex="problems[editingProblemId-1].hint"></textarea>
</div>
<div class="col-md-3 form-group">
<label>cpu</label>
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].timeLimit" data-error="请填写时间限制" required>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-3 form-group">
<label>内存</label>
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].memoryLimit" data-error="请填写内存限制" required>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-3 form-group" ms-visible="mode==2">
<label>分值</label>
<input type="number" class="form-control" ms-duplex="problems[editingProblemId-1].score" data-error="请填写题目分值" required>
<div class="help-block with-errors"></div>
</div>
<div class="col-md-12">
<label>样例</label>
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
ms-click="add_sample()">添加</a>
<div>
<div class="panel panel-default sample-panel" ms-repeat-sample="editSamples">
<div class="panel-heading">
<span class="panel-title">样例{{$index + 1}}</span>
<a href="javascript:void(0)" class="btn btn-primary btn-sm"
ms-click="toggle(sample)">{{ getBtnContent(sample)}}</a>
<a href="javascript:void(0)" class="btn btn-danger btn-sm"
ms-click="del_sample(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">
<label>测试数据</label>
<table class="table table-striped">
<tr>
<td>编号</td>
<td>输入文件名</td>
<td>输出文件名</td>
</tr>
<tr ms-repeat="editTestCaseList">
<td>{{$index}}</td>
<td>{{ el.input }}</td>
<td>{{ el.output }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<label>上传测试测试数据</label>
<div id="uploader">
<div>选择文件</div>
</div>
<small class="text-info">请将所有测试用例打包在一个文件中上传所有文件要在压缩包的根目录且输入输出文件名要以从1开始连续数字标识要对应例如<br>
1.in 1.out 2.in 2.out
</small><br>
<input type="submit" class="btn btn-success btn-lg" value="发布比赛"> <input type="submit" class="btn btn-success btn-lg" value="发布比赛">
</div> </div>
</div> </div>