mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
修改前端提交代码的界面
This commit is contained in:
parent
da03f902c5
commit
5a967789a6
@ -1,13 +1,19 @@
|
|||||||
require(["jquery", "code_mirror", "csrf"], function ($, code_mirror, csrfHeader) {
|
require(["jquery", "code_mirror", "csrf", "bs_alert"], function ($, code_mirror, csrfHeader, bs_alert) {
|
||||||
var code_editor = code_mirror($("#code-editor")[0], "text/x-csrc");
|
var code_editor = code_mirror($("#code-editor")[0], "text/x-csrc");
|
||||||
var language = "1";
|
var language = $("input[name='language'][checked]").val();
|
||||||
|
var submission_id;
|
||||||
|
|
||||||
$("#language-selector").change(function () {
|
$("input[name='language']").change(function () {
|
||||||
language = $("#language-selector").val();
|
language = this.value;
|
||||||
var language_types = {c: "text/x-csrc", cpp: "text/x-c++src", java: "text/x-java"};
|
var language_types = {"1": "text/x-csrc", "2": "text/x-c++src", "3": "text/x-java"};
|
||||||
code_editor.setOption("mode", language_types[language]);
|
code_editor.setOption("mode", language_types[language]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#show-more-btn").click(function () {
|
||||||
|
$(".hide").attr("class", "problem-section");
|
||||||
|
$("#show-more-btn").hide();
|
||||||
|
});
|
||||||
|
|
||||||
function show_loading() {
|
function show_loading() {
|
||||||
$("#submit-code-button").attr("disabled", "disabled");
|
$("#submit-code-button").attr("disabled", "disabled");
|
||||||
$("#loading-gif").show();
|
$("#loading-gif").show();
|
||||||
@ -18,24 +24,108 @@ require(["jquery", "code_mirror", "csrf"], function ($, code_mirror, csrfHeader)
|
|||||||
$("#loading-gif").hide();
|
$("#loading-gif").hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function get_result_html(result) {
|
||||||
|
console.log(result);
|
||||||
|
// 0 结果正确 1 运行错误 2 超时 3 超内存 4 编译错误
|
||||||
|
// 5 格式错误 6 结果错误 7 系统错误 8 等待判题
|
||||||
|
var results = {
|
||||||
|
0: {"alert_class": "success", message: "Accepted"},
|
||||||
|
1: {"alert_class": "danger", message: "Runtime Error"},
|
||||||
|
2: {"alert_class": "warning", message: "Time Limit Exceeded"},
|
||||||
|
3: {"alert_class": "warning", message: "Memory Limit Exceeded"},
|
||||||
|
4: {"alert_class": "danger", message: "Compile Error"},
|
||||||
|
5: {"alert_class": "warning", message: "Format Error"},
|
||||||
|
6: {"alert_class": "danger", message: "Wrong Answer"},
|
||||||
|
7: {"alert_class": "danger", message: "System Error"},
|
||||||
|
8: {"alert_class": "info", message: "Waiting"}
|
||||||
|
};
|
||||||
|
|
||||||
|
var html = '<div class="alert alert-' +
|
||||||
|
results[result].alert_class + ' result"' +
|
||||||
|
' role="alert">' +
|
||||||
|
'<div class="alert-link">' +
|
||||||
|
results[result].message +
|
||||||
|
'! ' +
|
||||||
|
'<a href="#">查看详情</a> ' +
|
||||||
|
'</div> </div>';
|
||||||
|
console.log(html);
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_result() {
|
||||||
|
$.ajax({
|
||||||
|
url: "/api/submission/?submission_id=" + submission_id,
|
||||||
|
method: "get",
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
if (!data.code) {
|
||||||
|
// 8是还没有完成判题
|
||||||
|
if (data.data.result == 8) {
|
||||||
|
// 1秒之后重新去获取
|
||||||
|
setTimeout(get_result, 1000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
hide_loading();
|
||||||
|
$("#result").html(get_result_html(data.data.result));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bs_alert(data.data);
|
||||||
|
hide_loading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
$("#submit-code-button").click(function () {
|
$("#submit-code-button").click(function () {
|
||||||
|
var problem_id = window.location.pathname.split("/")[2];
|
||||||
|
var code = code_editor.getValue();
|
||||||
|
|
||||||
show_loading();
|
show_loading();
|
||||||
|
|
||||||
|
if(!code){
|
||||||
|
bs_alert("请填写代码!");
|
||||||
|
hide_loading();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#result").html("");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
beforeSend: csrfHeader,
|
beforeSend: csrfHeader,
|
||||||
url: "/api/submission/",
|
url: "/api/submission/",
|
||||||
method: "post",
|
method: "post",
|
||||||
data: JSON.stringify({problem_id: 2, language: language, code: code_editor.getValue()}),
|
data: JSON.stringify({
|
||||||
contentType: "application/json"
|
problem_id: window.location.pathname.split("/")[2],
|
||||||
});
|
language: language,
|
||||||
setTimeout(
|
code: code_editor.getValue()
|
||||||
function () {
|
}),
|
||||||
$("#a").animate({opacity: '1'})
|
contentType: "application/json",
|
||||||
}, 3);
|
success: function (data) {
|
||||||
|
if (!data.code) {
|
||||||
|
submission_id = data.data.submission_id;
|
||||||
|
// 获取到id 之后2秒去查询一下判题结果
|
||||||
|
setTimeout(get_result, 2000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bs_alert(data.data);
|
||||||
|
hide_loading();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#show-more-btn").click(function(){
|
});
|
||||||
$(".hide").attr("class", "problem-section");
|
|
||||||
$("#show-more-btn").hide();
|
$.ajax({
|
||||||
|
url : "/api/user/",
|
||||||
|
method: "get",
|
||||||
|
dataType: "json",
|
||||||
|
success: function(data){
|
||||||
|
if(data.code){
|
||||||
|
$("#submit-code-button").attr("disabled", "disabled");
|
||||||
|
$("#result").html('<div class="alert alert-danger" role="alert"><div class="alert-link">请先<a href="/login/" target="_blank">登录</a>!</div> </div>');
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -22,7 +22,7 @@ class SubmissionnAPIView(APIView):
|
|||||||
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
|
connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
|
||||||
return connection["oj"]["oj_submission"]
|
return connection["oj"]["oj_submission"]
|
||||||
|
|
||||||
# @login_required
|
@login_required
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
"""
|
"""
|
||||||
提交代码
|
提交代码
|
||||||
@ -48,12 +48,12 @@ class SubmissionnAPIView(APIView):
|
|||||||
else:
|
else:
|
||||||
return serializer_invalid_response(serializer)
|
return serializer_invalid_response(serializer)
|
||||||
|
|
||||||
# @login_required
|
@login_required
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
submission_id = request.GET.get("submission_id", None)
|
submission_id = request.GET.get("submission_id", None)
|
||||||
if not submission_id:
|
if not submission_id:
|
||||||
return error_response(u"参数错误")
|
return error_response(u"参数错误")
|
||||||
submission = self._create_mondodb_connection().find_one({"_id": ObjectId(submission_id), "user_id": result.user.id})
|
submission = self._create_mondodb_connection().find_one({"_id": ObjectId(submission_id), "user_id": request.user.id})
|
||||||
if submission:
|
if submission:
|
||||||
return success_response({"result": submission["result"]})
|
return success_response({"result": submission["result"]})
|
||||||
else:
|
else:
|
||||||
|
@ -9,7 +9,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<h2 class="text-center">{{ problem.title }}</h2>
|
<h2 class="text-center">{{ problem.title }}</h2>
|
||||||
|
|
||||||
<p class="text-muted text-center">发布时间: {{ problem.create_time }} CPU: {{ problem.time_limit }}ms 内存: {{ problem.memory_limit }}M</p>
|
<p class="text-muted text-center">发布时间: {{ problem.create_time }} CPU: {{ problem.time_limit }}ms
|
||||||
|
内存: {{ problem.memory_limit }}M</p>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="problem-section">
|
<div class="problem-section">
|
||||||
@ -66,13 +67,13 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="inlineRadioOptions" value="1" checked> c (gcc 4.8)
|
<input type="radio" name="language" value="1" checked> c (gcc 4.8)
|
||||||
</label>
|
</label>
|
||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="inlineRadioOptions" value="2"> c++ (g++ 4.3)
|
<input type="radio" name="language" value="2"> c++ (g++ 4.3)
|
||||||
</label>
|
</label>
|
||||||
<label class="radio-inline">
|
<label class="radio-inline">
|
||||||
<input type="radio" name="inlineRadioOptions" value="3"> Java (jre 1.7)
|
<input type="radio" name="language" value="3"> Java (jre 1.7)
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -89,24 +90,10 @@
|
|||||||
<img src="/static/img/loading.gif" id="loading-gif">
|
<img src="/static/img/loading.gif" id="loading-gif">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="result">
|
||||||
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class="result">
|
|
||||||
<div class="alert alert-success" role="alert" id="a" style="opacity: 0">
|
|
||||||
<div class="alert-link">
|
|
||||||
Accepted! 时间:378ms 内存: 35m
|
|
||||||
<a href="#">查看详情</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="alert alert-danger" role="alert">
|
|
||||||
<div class="alert-link">Wrong Answer!</div>
|
|
||||||
</div>
|
|
||||||
<div class="alert alert-danger" role="alert">
|
|
||||||
<div class="alert-link">Compile Error!</div>
|
|
||||||
</div>
|
|
||||||
<div class="alert alert-warning" role="alert">
|
|
||||||
<div class="alert-link">Error Format!</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user