diff --git a/static/src/js/app/admin/admin.js b/static/src/js/app/admin/admin.js
index 705edf74..6ef30f62 100644
--- a/static/src/js/app/admin/admin.js
+++ b/static/src/js/app/admin/admin.js
@@ -109,24 +109,10 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "bootstrap"], function ($,
vm.template_url = "template/group/group_detail.html";
});
- vm.$watch("showEditProblemPage", function (problemId) {
- vm.problemId = problemId;
- vm.template_url = "template/problem/edit_problem.html";
- });
-
- vm.$watch("showProblemListPage", function () {
- vm.template_url = "template/problem/problem_list.html";
- });
-
vm.$watch("showGroupListPage", function () {
vm.template_url = "template/group/group.html";
});
- vm.$watch("showProblemSubmissionPage", function (problemId) {
- vm.problemId = problemId;
- vm.template_url = "template/problem/submission_list.html";
- });
-
vm.$watch("showContestProblemPage", function (problemId, contestId, contestMode) {
vm.$problemId = problemId;
vm.$contestId = contestId;
diff --git a/static/src/js/app/admin/problem/addProblem.js b/static/src/js/app/admin/problem/addProblem.js
index e67e9a71..391f70fa 100644
--- a/static/src/js/app/admin/problem/addProblem.js
+++ b/static/src/js/app/admin/problem/addProblem.js
@@ -4,7 +4,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
$("#add-problem-form").validator()
.on('submit', function (e) {
- if (!e.isDefaultPrevented()){
+ if (!e.isDefaultPrevented()) {
if (vm.testCaseId == "") {
bsAlert("你还没有上传测试数据!");
return false;
@@ -13,8 +13,8 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
bsAlert("题目描述不能为空!");
return false;
}
- if (vm.timeLimit < 100 || vm.timeLimit > 5000) {
- bsAlert("保证时间限制是一个100-5000的合法整数");
+ if (vm.timeLimit < 30 || vm.timeLimit > 5000) {
+ bsAlert("保证时间限制是一个30-5000的合法整数");
return false;
}
if (vm.samples.length == 0) {
@@ -50,7 +50,10 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
};
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({
@@ -74,44 +77,11 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
}
});
- 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 + "组测试数据");
- }
- });
var hintEditor = editor("#hint");
var problemDescription = editor("#problemDescription");
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({
@@ -119,7 +89,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
title: "",
description: "",
timeLimit: 1000,
- memoryLimit: 256,
+ memoryLimit: 128,
samples: [{input: "", output: "", "visible": true}],
hint: "",
visible: true,
@@ -131,6 +101,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
testCaseList: [],
uploadSuccess: false,
source: "",
+ uploadProgress: 0,
addSample: function () {
vm.samples.push({input: "", output: "", "visible": true});
},
@@ -149,6 +120,27 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
}
});
+ 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 + "组测试数据");
+ }
+ },
+ function (file, percentage) {
+ vm.uploadProgress = percentage;
+ });
+
var tagAutoCompleteList = [];
$.ajax({
diff --git a/static/src/js/app/admin/problem/editProblem.js b/static/src/js/app/admin/problem/editProblem.js
index 90361788..8784f76d 100644
--- a/static/src/js/app/admin/problem/editProblem.js
+++ b/static/src/js/app/admin/problem/editProblem.js
@@ -5,7 +5,7 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
$("#edit-problem-form").validator()
.on('submit', function (e) {
- if (!e.isDefaultPrevented()){
+ if (!e.isDefaultPrevented()) {
if (vm.testCaseId == "") {
bsAlert("你还没有上传测试数据!");
return false;
@@ -51,7 +51,10 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
};
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({
@@ -75,78 +78,70 @@ require(["jquery", "avalon", "editor", "uploader", "bsAlert", "csrfToken", "tagE
return false;
}
});
- if (avalon.vmodels.editProblem) {
- var vm = avalon.vmodels.editProblem;
- vm.title= "",
- vm.description= "";
- vm.timeLimit= -1;
- vm.memoryLimit= -1;
- vm.samples= [];
- vm.hint= "";
- vm.visible= true;
- vm.difficulty= 0;
- vm.inputDescription= "";
- vm.outputDescription= "";
- vm.testCaseIdd= "";
- vm.uploadSuccess= false;
- vm.source= "";
- vm.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);
+ 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: [],
+ uploadProgress: 0,
+ 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 () {
+ avalon.vmodels.admin.template_url = "template/problem/problem_list.html";
}
- },
- 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) {
- 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]
- });
+ 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 + "组测试数据");
}
- bsAlert("测试数据添加成功!共添加" + vm.testCaseList.length + "组测试数据");
+ },
+ function (file, percentage) {
+ vm.uploadProgress = percentage;
}
- });
+ );
$.ajax({
url: "/api/admin/problem/?problem_id=" + avalon.vmodels.admin.problemId,
diff --git a/static/src/js/app/admin/problem/problem.js b/static/src/js/app/admin/problem/problem.js
index 9fe56df5..53d8a763 100644
--- a/static/src/js/app/admin/problem/problem.js
+++ b/static/src/js/app/admin/problem/problem.js
@@ -1,54 +1,44 @@
-require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfTokenHeader, bsAlert) {
+require(["jquery", "avalon", "csrfToken", "bsAlert", "pager"], function ($, avalon, csrfTokenHeader, bsAlert) {
avalon.ready(function () {
if(avalon.vmodels.problemList){
vm = avalon.vmodels.problemList;
- problemList = [];
}
else {
var vm = avalon.define({
$id: "problemList",
problemList: [],
- previousPage: 0,
- nextPage: 0,
- page: 1,
- totalPage: 1,
+
keyword: "",
showVisibleOnly: false,
- 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";
+
+ pager: {
+ getPage: function (page) {
+ getPage(page);
}
},
- getPage: function (page_index) {
- getPageData(page_index);
- },
+
showEditProblemPage: function (problemId) {
- vm.$fire("up!showEditProblemPage", problemId);
+ avalon.vmodels.admin.problemId = problemId;
+ avalon.vmodels.admin.template_url = "template/problem/edit_problem.html";
},
showProblemSubmissionPage: function(problemId){
- vm.$fire("up!showProblemSubmissionPage", problemId);
+ avalon.vmodels.admin.problemId = problemId;
+ avalon.vmodels.admin.template_url = "template/problem/submission_list.html";
+ },
+
+ search: function(){
+ getPage(1);
+ avalon.vmodels.problemPager.currentPage = 1;
}
});
vm.$watch("showVisibleOnly", function () {
- getPageData(1);
+ getPage(1);
+ avalon.vmodels.problemPager.currentPage = 1;
});
}
- getPageData(1);
- function getPageData(page) {
+
+ function getPage(page) {
var url = "/api/admin/problem/?paging=true&page=" + page + "&page_size=10";
if (vm.keyword != "")
url += "&keyword=" + vm.keyword;
@@ -61,10 +51,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert"], function ($, avalon, csrfT
success: function (data) {
if (!data.code) {
vm.problemList = data.data.results;
- vm.totalPage = data.data.total_page;
- vm.previousPage = data.data.previous_page;
- vm.nextPage = data.data.next_page;
- vm.page = page;
+ avalon.vmodels.problemPager.totalPage = data.data.total_page;
}
else {
bsAlert(data.data);
diff --git a/static/src/js/utils/uploader.js b/static/src/js/utils/uploader.js
index a4ce0387..e6d3817a 100644
--- a/static/src/js/utils/uploader.js
+++ b/static/src/js/utils/uploader.js
@@ -1,6 +1,6 @@
-define("uploader", ["webUploader", "csrfToken"], function(webuploader,csrfTokenHeader){
- function uploader(selector, server, onSuccess, beforeUpload) {
- var Webuploader= webuploader.create({
+define("uploader", ["webUploader", "csrfToken"], function (webuploader, csrfTokenHeader) {
+ function uploader(selector, server, onSuccess, uploadProgress) {
+ var Webuploader = webuploader.create({
auto: true,
// swf文件路径
swf: "/static/img/Uploader.swf",
@@ -11,11 +11,16 @@ define("uploader", ["webUploader", "csrfToken"], function(webuploader,csrfTokenH
pick: selector,
// 不压缩image, 默认如果是jpeg,文件上传前会压缩一把再上传!
resize: false,
- uploadBeforeSend : csrfTokenHeader
+ uploadBeforeSend: csrfTokenHeader,
+ accept: {
+ title: 'testcase zip',
+ extensions: 'zip',
+ mimeTypes: 'application/zip'
+ }
});
- Webuploader.on("uploadBeforeSend",csrfTokenHeader);
+ Webuploader.on("uploadBeforeSend", csrfTokenHeader);
Webuploader.on("uploadSuccess", onSuccess);
- Webuploader.on("beforeFileQueued", beforeUpload);
+ Webuploader.on("uploadProgress", uploadProgress);
return Webuploader;
}
diff --git a/template/src/admin/problem/add_problem.html b/template/src/admin/problem/add_problem.html
index 37c48bb9..f6016e06 100644
--- a/template/src/admin/problem/add_problem.html
+++ b/template/src/admin/problem/add_problem.html
@@ -105,6 +105,7 @@
请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:
1.in 1.out 2.in 2.out
+
上传进度%
编号 | diff --git a/template/src/admin/problem/edit_problem.html b/template/src/admin/problem/edit_problem.html index d7c97438..d15f58f0 100644 --- a/template/src/admin/problem/edit_problem.html +++ b/template/src/admin/problem/edit_problem.html @@ -111,6 +111,7 @@ 请将所有测试用例打包在一个文件中上传,所有文件要在压缩包的根目录,且输入输出文件名要以从1开始连续数字标识要对应例如:
编号 | diff --git a/template/src/admin/problem/problem_list.html b/template/src/admin/problem/problem_list.html index 284d2dad..3fa5ac54 100644 --- a/template/src/admin/problem/problem_list.html +++ b/template/src/admin/problem/problem_list.html @@ -6,7 +6,7 @@