Pisces000221
7 years ago
48 changed files with 1143 additions and 454 deletions
@ -0,0 +1,101 @@
|
||||
/* |
||||
* This file is part of SYZOJ. |
||||
* |
||||
* Copyright (c) 2016 Menci <huanghaorui301@gmail.com> |
||||
* |
||||
* SYZOJ is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* SYZOJ is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU Affero General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU Affero General Public |
||||
* License along with SYZOJ. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
let Sequelize = require('sequelize'); |
||||
let db = syzoj.db; |
||||
|
||||
let User = syzoj.model('user'); |
||||
let Problem = syzoj.model('problem'); |
||||
|
||||
let model = db.define('custom_test', { |
||||
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true }, |
||||
|
||||
input_filepath: { type: Sequelize.TEXT }, |
||||
code: { type: Sequelize.TEXT('medium') }, |
||||
language: { type: Sequelize.STRING(20) }, |
||||
|
||||
status: { type: Sequelize.STRING(50) }, |
||||
|
||||
time: { type: Sequelize.INTEGER }, |
||||
pending: { type: Sequelize.BOOLEAN }, |
||||
memory: { type: Sequelize.INTEGER }, |
||||
|
||||
result: { type: Sequelize.TEXT('medium'), json: true }, |
||||
|
||||
user_id: { type: Sequelize.INTEGER }, |
||||
|
||||
problem_id: { type: Sequelize.INTEGER }, |
||||
|
||||
submit_time: { type: Sequelize.INTEGER } |
||||
}, { |
||||
timestamps: false, |
||||
tableName: 'custom_test', |
||||
indexes: [ |
||||
{ |
||||
fields: ['status'], |
||||
}, |
||||
{ |
||||
fields: ['user_id'], |
||||
}, |
||||
{ |
||||
fields: ['problem_id'], |
||||
} |
||||
] |
||||
}); |
||||
|
||||
let Model = require('./common'); |
||||
class CustomTest extends Model { |
||||
static async create(val) { |
||||
return CustomTest.fromRecord(CustomTest.model.build(Object.assign({ |
||||
input_filepath: '', |
||||
code: '', |
||||
language: '', |
||||
user_id: 0, |
||||
problem_id: 0, |
||||
submit_time: parseInt((new Date()).getTime() / 1000), |
||||
|
||||
pending: true, |
||||
|
||||
time: 0, |
||||
memory: 0, |
||||
status: 'Waiting', |
||||
}, val))); |
||||
} |
||||
|
||||
async loadRelationships() { |
||||
this.user = await User.fromID(this.user_id); |
||||
this.problem = await Problem.fromID(this.problem_id); |
||||
} |
||||
|
||||
async updateResult(result) { |
||||
this.pending = result.pending; |
||||
this.status = result.status; |
||||
this.time = result.time_used; |
||||
this.memory = result.memory_used; |
||||
this.result = result; |
||||
} |
||||
|
||||
getModel() { return model; } |
||||
} |
||||
|
||||
CustomTest.model = model; |
||||
|
||||
module.exports = CustomTest; |
@ -0,0 +1,34 @@
|
||||
var addUrlParam = function (url, key, val) { |
||||
var newParam = encodeURIComponent(key) + '=' + encodeURIComponent(val); |
||||
|
||||
url = url.split('#')[0]; |
||||
if (url.indexOf('?') === -1) url += '?' + newParam; |
||||
else url += '&' + newParam; |
||||
|
||||
return url; |
||||
}; |
||||
|
||||
$(function () { |
||||
$(document).on('click', 'a[href-post]', function (e) { |
||||
e.preventDefault(); |
||||
|
||||
var form = document.createElement('form'); |
||||
form.style.display = 'none'; |
||||
form.method = 'post'; |
||||
form.action = $(this).attr('href-post'); |
||||
form.target = '_self'; |
||||
|
||||
var input = document.createElement('input'); |
||||
input.type = 'hidden'; |
||||
input.name = '_csrf'; |
||||
input.value = document.head.getAttribute('data-csrf-token'); |
||||
form.appendChild(input); |
||||
|
||||
document.body.appendChild(form); |
||||
form.submit(); |
||||
}); |
||||
|
||||
$('form').each(function () { |
||||
this.action = addUrlParam(this.action || location.href, '_csrf', document.head.getAttribute('data-csrf-token')); |
||||
}); |
||||
}); |
@ -0,0 +1,30 @@
|
||||
<% include util %> |
||||
<div style="padding-bottom: 1.5rem; "> |
||||
<div class="ui styled fluid accordion" id="custom-test-accordion"> |
||||
<div class="title"<% if (custom_test.pending) { %> style="cursor: auto; "<% } %>> |
||||
<div class="ui grid"> |
||||
<div class="four wide column"><i class="dropdown icon"></i>自定义测试</div> |
||||
<div class="four wide column status status_detail <%= getStatusMeta(custom_test.status).toLowerCase().split(' ').join('_') %>"> |
||||
<i class="<%= icon[getStatusMeta(custom_test.status)] || 'remove' %> icon"></i> |
||||
<%= custom_test.status %></div> |
||||
<% if (!custom_test.pending) { %> |
||||
<div class="four wide column">用时:<span style="font-weight: normal; "><%= custom_test.time %> ms</span></div> |
||||
<div class="four wide column">内存:<span style="font-weight: normal; "><%= custom_test.memory %> KiB</span></div> |
||||
<% } %> |
||||
</div> |
||||
</div> |
||||
<% if (!custom_test.pending) { %> |
||||
<div class="content"> |
||||
<strong>选手输出</strong> |
||||
<div class="ui existing segment"><pre style="margin-top: 0; margin-bottom: 0; "><code><%= custom_test.result.user_out %></code></pre></div> |
||||
</div> |
||||
<% } %> |
||||
</div> |
||||
<% if (!custom_test.pending) { %> |
||||
<script> |
||||
$(function () { |
||||
$('#custom-test-accordion').accordion(); |
||||
}); |
||||
</script> |
||||
<% } %> |
||||
</div> |
Loading…
Reference in new issue