[解决冲突]oj/urls.py

This commit is contained in:
esp
2015-08-21 21:03:33 +08:00
34 changed files with 4614 additions and 230 deletions

View File

@@ -21,43 +21,110 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
hash = "index/index";
}
var superAdminNav = [
{ name: "首页",
children: [{name: "主页", hash: "#index/index"},
{name: "监控", hash: "#monitor/monitor"},
{name: "统计", hash: "#statistics/statistics"}]
},
{
name: "通用",
children: [{name: "公告管理", hash: "#announcement/announcement"},
{name: "用户管理", hash: "#user/user_list"}]
},
{
name: "题目管理",
children: [{name: "题目列表", hash: "#problem/problem_list"},
{name: "创建题目", hash: "#problem/add_problem"}]
},
{
name: "比赛管理",
children: [{name: "比赛列表", hash: "#contest/contest_list"},
{name: "创建比赛", hash: "#contest/add_contest"}]
},
{
name: "小组管理",
children: [{name: "小组列表", hash: "#group/group"},
{name: "加入小组请求", hash: "#group/join_group_request_list"}]
}
];
var adminNav = [
{ name: "首页",
children: [{name: "主页", hash: "#index/index"}]
},
{
name: "通用",
children: [{name: "公告管理", hash: "#announcement/announcement"}]
},
{
name: "比赛管理",
children: [{name: "比赛列表", hash: "#contest/contest_list"},
{name: "创建比赛", hash: "#contest/add_contest"}]
},
{
name: "小组管理",
children: [{name: "小组列表", hash: "#group/group"},
{name: "加入小组请求", hash: "#group/join_group_request_list"}]
}
];
var vm = avalon.define({
$id: "admin",
template_url: "template/" + hash + ".html",
groupId: -1,
problemId: -1,
adminNavList: [],
hide_loading: function () {
$("#loading-gif").hide();
},
getLiId: function(hash){
return hash.replace("#", "li-").replace("/", "-");
}
});
vm.$watch("showGroupDetailPage", function(groupId){
$.ajax({
url: "/api/user/",
method: "get",
dataType: "json",
success: function(data){
if(!data.code){
if (data.data.admin_type == 2){
vm.adminNavList = superAdminNav;
}
else{
vm.adminNavList = adminNav;
}
}
}
});
vm.$watch("showGroupDetailPage", function (groupId) {
vm.groupId = groupId;
vm.template_url = "template/group/group_detail.html";
});
vm.$watch("showEditProblemPage", function(problemId){
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("showProblemListPage", function () {
vm.template_url = "template/problem/problem_list.html";
});
vm.$watch("showGroupListPage", function(){
vm.template_url = "template/group/group.html";
vm.$watch("showGroupListPage", function () {
vm.template_url = "template/group/group.html";
});
vm.$watch("showProblemSubmissionPage", function(problemId){
vm.$watch("showProblemSubmissionPage", function (problemId) {
vm.problemId = problemId;
vm.template_url = "template/problem/submission_list.html";
});
avalon.scan();
li_active("#li-" + hash.replace("/", "-"));
window.onhashchange = function () {
var hash = window.location.hash.substring(1);
if (hash) {
@@ -66,6 +133,7 @@ define("admin", ["jquery", "avalon"], function ($, avalon) {
show_template("template/" + hash + ".html");
}
};
setTimeout(function(){li_active("#li-" + hash.replace("/", "-"));}, 500)
});

View File

@@ -1,8 +1,5 @@
require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
function ($, avalon, csrfTokenHeader, bsAlert, editor) {
avalon.ready(function () {
avalon.vmodels.announcement = null;
@@ -20,7 +17,11 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
totalPage: 1, // 总页数
showVisibleOnly: false, //仅显示可见公告
// 编辑
newTitle: "",
announcementVisible: 0,
showGlobalViewRadio: true,
isGlobal: true,
allGroups: [],
getState: function (el) { //获取公告当前状态,显示
if (el.visible)
return "可见";
@@ -47,49 +48,75 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
},
editAnnouncement: function (announcement) {
$("#newTitle").val(announcement.title);
vm.newTitle = announcement.title;
editAnnouncementEditor.setValue(announcement.content);
vm.announcementVisible = announcement.visible;
if (vm.editingAnnouncementId == announcement.id)
vm.editingAnnouncementId = 0;
else
vm.editingAnnouncementId = announcement.id;
vm.isGlobal = announcement.is_global;
for (var i = 0; i < announcement.groups.length; i++) {
for (var j = 0; j < vm.allGroups.length; j++) {
if (announcement.groups[i] == vm.allGroups[j].id) {
vm.allGroups[j].isSelected = true;
}
}
}
editAnnouncementEditor.focus();
},
cancelEdit: function () {
vm.editingAnnouncementId = 0;
},
submitChange: function () {
var title = $("#newTitle").val();
var title = vm.newTitle;
var content = editAnnouncementEditor.getValue();
if (content && title) {
$.ajax({
beforeSend: csrfTokenHeader,
url: "/api/admin/announcement/",
dataType: "json",
method: "put",
data: {
id: vm.editingAnnouncementId,
title: title,
content: content,
visible: vm.announcementVisible
},
success: function (data) {
if (!data.code) {
bsAlert("修改成功");
vm.editingAnnouncementId = 0;
getPageData(1);
}
else {
bsAlert(data.data);
}
if (content == "" || title == "") {
bsAlert("标题和内容都不能为空");
return false;
}
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);
}
});
}
}
else {
bsAlert("标题和公告内容不得为空");
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("请至少选择一个小组");
return false;
}
$.ajax({
beforeSend: csrfTokenHeader,
url: "/api/admin/announcement/",
contentType: "application/json",
dataType: "json",
method: "put",
data: JSON.stringify({
id: vm.editingAnnouncementId,
title: title,
content: content,
visible: vm.announcementVisible,
is_global: vm.isGlobal,
groups: selectedGroups
}),
success: function (data) {
if (!data.code) {
bsAlert("修改成功");
vm.editingAnnouncementId = 0;
getPageData(1);
}
else {
bsAlert(data.data);
}
}
});
}
});
vm.$watch("showVisibleOnly", function () {
@@ -98,8 +125,44 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
getPageData(1);
$.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["isSelected"] = false;
vm.allGroups.push(item);
}
}
else {
bsAlert(data.data);
}
}
});
$.ajax({
url: "/api/user/",
method: "get",
dataType: "json",
success: function (data) {
if (!data.code) {
if (data.data.admin_type == 1) {
vm.isGlobal = false;
vm.showGlobalViewRadio = false;
}
}
}
});
function getPageData(page) {
var url = "/api/announcements/?paging=true&page=" + page + "&page_size=10";
var url = "/api/admin/announcement/?paging=true&page=" + page + "&page_size=10";
if (vm.showVisibleOnly)
url += "&visible=true";
$.ajax({
@@ -122,9 +185,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
}
//新建公告表单验证与数据提交
$('form').validator().on('submit', function (e) {
$("#announcement-form").validator().on('submit', function (e) {
if (!e.isDefaultPrevented()) {
var title = $("#title").val();
var content = createAnnouncementEditor.getValue();
@@ -132,10 +193,29 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
bsAlert("请填写公告内容");
return false;
}
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);
}
}
}
if (!vm.isGlobal && !selectedGroups.length) {
bsAlert("请至少选择一个小组");
return false;
}
$.ajax({
beforeSend: csrfTokenHeader,
url: "/api/admin/announcement/",
data: {title: title, content: content},
contentType: "application/json",
data: JSON.stringify({
title: title,
content: content,
is_global: vm.isGlobal,
groups: selectedGroups
}),
dataType: "json",
method: "post",
success: function (data) {
@@ -148,7 +228,7 @@ require(["jquery", "avalon", "csrfToken", "bsAlert", "editor", "validator"],
bsAlert(data.data);
}
}
})
});
return false;
}
})

View File

@@ -1,80 +1,48 @@
require(["jquery", "chart"], function ($, Chart) {
var data2 = {
labels: ["January", "February", "March", "April", "May", "June", "July",
"January", "February", "March", "April", "January", "February", "March", "April"],
datasets: [
{
label: "2222222",
fillColor: "rgba(255,255,255,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [3, 7, 8, 9, 1, 4, 10, 10, 9, 8, 7, 10, 10, 10, 10]
}
]
};
new Chart($("#waiting-queue-chart").get(0).getContext("2d")).Line(data2);
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July",
"January", "February", "March", "April", "January", "February", "March", "April"],
labels: ["初始化"],
datasets: [
{
label: "11111111",
fillColor: "rgba(255,255,255,0.2)",
strokeColor: "rgba(250,68,68,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
},
{
label: "2222222",
label: "队列长度",
fillColor: "rgba(255,255,255,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [3, 7, 8, 9, 1, 4, 10, 10, 9, 8, 7, 10, 10, 10, 10]
data: [0]
}
]
};
Chart.defaults.global.responsive = true;
new Chart($("#judge-instance-chart").get(0).getContext("2d")).Line(data);
var chart = new Chart($("#waiting-queue-chart").get(0).getContext("2d")).Line(data);
var data1 = {
labels: ["January", "February", "March", "April", "May", "June", "July",
"January", "February", "March", "April", "January", "February", "March", "April"],
datasets: [
{
label: "2222222",
fillColor: "rgba(255,255,255,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [3, 7, 8, 9, 1, 4, 10, 10, 9, 8, 7, 10, 10, 10, 10]
},
{
label: "2222222",
fillColor: "rgba(255,255,255,0.2)",
strokeColor: "rgba(252,214,48,1)",
pointColor: "rgba(252,214,48,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [30, 70, 58, 49, 19, 44, 100, 100, 89, 88, 77, 50, 80, 66, 100]
var dataCounter = 0;
function getMonitorData(){
var hash = location.hash;
if (hash != "#monitor/monitor"){
clearInterval(intervalId);
}
$.ajax({
url: "/api/admin/monitor/",
method: "get",
dataType: "json",
success: function(data){
if(!data.code){
chart.addData([data.data["count"]], data.data["time"])
dataCounter ++;
}
}
]
};
Chart.defaults.global.responsive = true;
new Chart($("#c1").get(0).getContext("2d")).Line(data1);
})
}
$("#clear-chart-data").click(function(){
for(var i = 0;i < dataCounter;i++) {
chart.removeData();
dataCounter = 0;
}
});
var intervalId = setInterval(getMonitorData, 3000);
});

View File

@@ -11,7 +11,14 @@ require(["jquery", "bsAlert", "csrfToken", "validator"], function ($, bsAlert, c
method: "post",
success: function (data) {
if (!data.code) {
window.location.href = "/";
//成功登陆
var ref = document.referrer;
if(ref){
if(ref.split("/")[2] == location.hostname){
location.href = ref;
}
}
location.href = "/";
}
else {
bsAlert(data.data);