mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 00:13:18 +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 language = "1";
|
||||
var language = $("input[name='language'][checked]").val();
|
||||
var submission_id;
|
||||
|
||||
$("#language-selector").change(function () {
|
||||
language = $("#language-selector").val();
|
||||
var language_types = {c: "text/x-csrc", cpp: "text/x-c++src", java: "text/x-java"};
|
||||
$("input[name='language']").change(function () {
|
||||
language = this.value;
|
||||
var language_types = {"1": "text/x-csrc", "2": "text/x-c++src", "3": "text/x-java"};
|
||||
code_editor.setOption("mode", language_types[language]);
|
||||
});
|
||||
|
||||
$("#show-more-btn").click(function () {
|
||||
$(".hide").attr("class", "problem-section");
|
||||
$("#show-more-btn").hide();
|
||||
});
|
||||
|
||||
function show_loading() {
|
||||
$("#submit-code-button").attr("disabled", "disabled");
|
||||
$("#loading-gif").show();
|
||||
@ -18,24 +24,108 @@ require(["jquery", "code_mirror", "csrf"], function ($, code_mirror, csrfHeader)
|
||||
$("#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 () {
|
||||
var problem_id = window.location.pathname.split("/")[2];
|
||||
var code = code_editor.getValue();
|
||||
|
||||
show_loading();
|
||||
|
||||
if(!code){
|
||||
bs_alert("请填写代码!");
|
||||
hide_loading();
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#result").html("");
|
||||
|
||||
$.ajax({
|
||||
beforeSend: csrfHeader,
|
||||
url: "/api/submission/",
|
||||
method: "post",
|
||||
data: JSON.stringify({problem_id: 2, language: language, code: code_editor.getValue()}),
|
||||
contentType: "application/json"
|
||||
data: JSON.stringify({
|
||||
problem_id: window.location.pathname.split("/")[2],
|
||||
language: language,
|
||||
code: code_editor.getValue()
|
||||
}),
|
||||
contentType: "application/json",
|
||||
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();
|
||||
}
|
||||
}
|
||||
});
|
||||
setTimeout(
|
||||
function () {
|
||||
$("#a").animate({opacity: '1'})
|
||||
}, 3);
|
||||
|
||||
});
|
||||
|
||||
$("#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"])
|
||||
return connection["oj"]["oj_submission"]
|
||||
|
||||
# @login_required
|
||||
@login_required
|
||||
def post(self, request):
|
||||
"""
|
||||
提交代码
|
||||
@ -48,12 +48,12 @@ class SubmissionnAPIView(APIView):
|
||||
else:
|
||||
return serializer_invalid_response(serializer)
|
||||
|
||||
# @login_required
|
||||
@login_required
|
||||
def get(self, request):
|
||||
submission_id = request.GET.get("submission_id", None)
|
||||
if not submission_id:
|
||||
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:
|
||||
return success_response({"result": submission["result"]})
|
||||
else:
|
||||
|
@ -9,7 +9,8 @@
|
||||
</ul>
|
||||
<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 class="problem-section">
|
||||
@ -28,35 +29,35 @@
|
||||
<p class="problem-detail">第一行包括两个数n,k</p>
|
||||
</div>
|
||||
{% for item in samples %}
|
||||
<div class="problem-section">
|
||||
<label class="problem-label">样例输入1</label>
|
||||
<div class="problem-section">
|
||||
<label class="problem-label">样例输入1</label>
|
||||
<pre>
|
||||
{{ item.input }}</pre>
|
||||
|
||||
</div>
|
||||
<div class="problem-section">
|
||||
</div>
|
||||
<div class="problem-section">
|
||||
|
||||
<label class="problem-label">样例输出1</label>
|
||||
<label class="problem-label">样例输出1</label>
|
||||
<pre>
|
||||
{{ item.output }}</pre>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div>
|
||||
<button type="button" id="show-more-btn" class="btn btn-info btn-sm">查看隐藏信息</button>
|
||||
</div>
|
||||
{% if problem.hind %}
|
||||
<div class="problem-section hide">
|
||||
<label class="problem-label">提示</label>
|
||||
<div class="problem-section hide">
|
||||
<label class="problem-label">提示</label>
|
||||
|
||||
<p class="problem-detail">{{ problem.hint|safe }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="problem-detail">{{ problem.hint|safe }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="problem-section hide">
|
||||
<label class="problem-label">标签</label>
|
||||
|
||||
<p class="problem-detail">
|
||||
{% for tag in problem.tags.all %}
|
||||
<span class="label label-success">{{ tag.name }}</span>
|
||||
<span class="label label-success">{{ tag.name }}</span>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
@ -66,13 +67,13 @@
|
||||
|
||||
<div>
|
||||
<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 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 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>
|
||||
</div>
|
||||
</div>
|
||||
@ -89,24 +90,10 @@
|
||||
<img src="/static/img/loading.gif" id="loading-gif">
|
||||
|
||||
</div>
|
||||
<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 id="result">
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user