From 018727ffbc8acd6f0feb8feb7c77494f397f1e78 Mon Sep 17 00:00:00 2001 From: esp Date: Sun, 23 Aug 2015 17:41:33 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=89=8D=E7=AB=AF]=E6=8A=8A=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=AF=94=E8=B5=9B=E5=92=8C=E6=B7=BB=E5=8A=A0=E6=AF=94=E8=B5=9B?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E5=88=86=E5=BC=80=E4=BA=86,=E5=B0=B1?= =?UTF-8?q?=E6=98=AF=E6=8A=8A=E6=B7=BB=E5=8A=A0=E9=97=AE=E9=A2=98=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BB=8E=E6=B7=BB=E5=8A=A0=E6=AF=94=E8=B5=9B=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=88=A0=E9=99=A4=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/js/app/admin/contest/add_contest.js | 189 ++++++------------ template/admin/contest/add_contest.html | 173 +++------------- 2 files changed, 79 insertions(+), 283 deletions(-) diff --git a/static/src/js/app/admin/contest/add_contest.js b/static/src/js/app/admin/contest/add_contest.js index dfa8d603..f15d50aa 100644 --- a/static/src/js/app/admin/contest/add_contest.js +++ b/static/src/js/app/admin/contest/add_contest.js @@ -1,6 +1,8 @@ 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()){ @@ -12,12 +14,15 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date 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 + 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 == "") ajaxData.contest_type = 1; else{ @@ -25,13 +30,12 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date } else { // Add groups info ajaxData.groups = []; - for (var i = 0; vm.choseGroupList[i]; i++) - ajaxData.groups.push(parseInt(vm.choseGroupList[i].id)) + for (var i = 0; vm.choseGroupsList[i]; i++) + ajaxData.groups.push(parseInt(vm.choseGroupsList[i].id)) } - console.log(ajaxData); - $.ajax({ + $.ajax({ // Add contest beforeSend: csrfTokenHeader, url: "/api/admin/contest/", dataType: "json", @@ -41,7 +45,8 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date contentType: "application/json", success: function (data) { if (!data.code) { - bsAlert("添加成功!"); + bsAlert("添加成功!将转到比赛列表页以便为比赛添加问题(注意比赛当前状态为:隐藏)"); + location.hash = "#contest/contest_list"; console.log(data); } else { @@ -56,8 +61,6 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date }); editor("#editor"); - editor("#problemDescriptionEditor"); - editor("#problemHintEditor"); var vm = avalon.define({ $id: "add_contest", @@ -69,151 +72,71 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "date 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; - } - }, + choseGroupsList: [], 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 = []; + vm.choseGroupsList = []; 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.choseGroupsList.push({name:vm.groupList[vm.group].name, index:vm.group, id:vm.groupList[vm.group].id}); + vm.group = -1; }, - unchose: function(groupIndex){ - if (vm.groupList[vm.choseGroupList[groupIndex].index].id == 0){ + removeGroup: function(groupIndex){ + if (vm.groupList[vm.choseGroupsList[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]); + vm.groupList[vm.choseGroupsList[groupIndex].index].chose = false; + vm.choseGroupsList.remove(vm.choseGroupsList[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); - } - } - }); + $.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); + } + } + }); + } + } + }); - - - 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({ diff --git a/template/admin/contest/add_contest.html b/template/admin/contest/add_contest.html index 44ae98ac..de33f23a 100644 --- a/template/admin/contest/add_contest.html +++ b/template/admin/contest/add_contest.html @@ -6,8 +6,9 @@
- + +
@@ -17,51 +18,46 @@
+
请填写比赛描述
-
-
- -
-
+ ms-duplex="startTime" data-error="请填写比赛开始时间" required> +
+
-
-
-
-
- -
-
- -
-
-
- + ms-duplex="endTime" data-error="请填写比赛结束时间" required> + +
+
- + +
+
+
+ +
+
-
{{el.name}}
+
{{el.name}}
@@ -94,135 +90,12 @@
-
- - 添加 - - - - - - - - - - - - - -
编号题目测试数据
题目{{ $index+1 }}{{ el.title }}{{ el.testCaseList.length }}组 - 编辑 - 删除 -
- -
-
- -
-
-
- 题目{{editingProblemId}} - 隐藏 - 删除 -
-
-
- - -
-
-
- - - 请填写题目描述 -
-
- - -
-
- - -
-
-
- - -
-
-
- - -
-
-
- - 添加 -
-
-
- 样例{{$index + 1}} - {{ getBtnContent(sample)}} - 删除 -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
-
- - - - - - - - - - - - - -
编号输入文件名输出文件名
{{$index}}{{ el.input }}{{ el.output }}
-
-
-
-
-
-
- -
-
选择文件
-
- 请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:
- 1.in 1.out 2.in 2.out -

-