Browse Source

Merge branch 'master' of zhaojunzhe/fair-web into master

pull/31/head
richie 5 years ago committed by Gogs
parent
commit
547d5380ce
  1. 10
      models-built/judge_state.js
  2. 2
      models-built/judge_state.js.map
  3. 5
      models-built/user_to_practice.js
  4. 2
      models-built/user_to_practice.js.map
  5. 7
      models/judge_state.ts
  6. 4
      models/user_to_practice.ts
  7. 8
      modules/practice.js
  8. 26
      modules/submission.js
  9. 11
      views/submission_practice.ejs

10
models-built/judge_state.js

@ -354,16 +354,6 @@ var JudgeState = /** @class */ (function (_super) {
TypeORM.Column({ nullable: true, type: "integer" }), TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number) __metadata("design:type", Number)
], JudgeState.prototype, "submit_time"); ], JudgeState.prototype, "submit_time");
__decorate([
TypeORM.Index(),
TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number)
], JudgeState.prototype, "c_id");
__decorate([
TypeORM.Index(),
TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number)
], JudgeState.prototype, "is_practice");
__decorate([ __decorate([
TypeORM.Column({ nullable: true, type: "integer" }), TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number) __metadata("design:type", Number)

2
models-built/judge_state.js.map

File diff suppressed because one or more lines are too long

5
models-built/user_to_practice.js

@ -49,6 +49,11 @@ var UserToPractice = /** @class */ (function (_super) {
TypeORM.Column({ nullable: true, type: "integer" }), TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number) __metadata("design:type", Number)
], UserToPractice.prototype, "p_id"); ], UserToPractice.prototype, "p_id");
__decorate([
TypeORM.Index(),
TypeORM.Column({ nullable: true, type: "integer" }),
__metadata("design:type", Number)
], UserToPractice.prototype, "s_id");
__decorate([ __decorate([
TypeORM.Index(), TypeORM.Index(),
TypeORM.Column({ type: "integer" }), TypeORM.Column({ type: "integer" }),

2
models-built/user_to_practice.js.map

@ -1 +1 @@
{"version":3,"file":"user_to_practice.js","sourceRoot":"","sources":["../models/user_to_practice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAA4C,kCAAK;IAAjD;;IA6BA,CAAC;IA5BU,oBAAK,GAAG,IAAI,CAAC;IAGpB;QADC,OAAO,CAAC,sBAAsB,EAAE;;sCACtB;IAIX;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAChB;IAIpB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAChB;IAIpB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;gDACf;IA5BJ,cAAc;QADlC,OAAO,CAAC,MAAM,EAAE;OACI,cAAc,CA6BlC;IAAD,qBAAC;CAAA,AA7BD,CAA4C,mBAAK,GA6BhD;qBA7BoB,cAAc"} {"version":3,"file":"user_to_practice.js","sourceRoot":"","sources":["../models/user_to_practice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAmC;AACnC,mCAA6B;AAG7B;IAA4C,kCAAK;IAAjD;;IAiCA,CAAC;IAhCU,oBAAK,GAAG,IAAI,CAAC;IAGpB;QADC,OAAO,CAAC,sBAAsB,EAAE;;sCACtB;IAIX;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;wCACvC;IAIb;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAChB;IAIpB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;+CAChB;IAIpB;QAFC,OAAO,CAAC,KAAK,EAAE;QACf,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;gDACf;IAhCJ,cAAc;QADlC,OAAO,CAAC,MAAM,EAAE;OACI,cAAc,CAiClC;IAAD,qBAAC;CAAA,AAjCD,CAA4C,mBAAK,GAiChD;qBAjCoB,cAAc"}

7
models/judge_state.ts

@ -87,13 +87,6 @@ export default class JudgeState extends Model {
@TypeORM.Column({ nullable: true, type: "integer" }) @TypeORM.Column({ nullable: true, type: "integer" })
submit_time: number; submit_time: number;
@TypeORM.Index()
@TypeORM.Column({ nullable: true, type: "integer" })
c_id: number;
@TypeORM.Index()
@TypeORM.Column({ nullable: true, type: "integer" })
is_practice: number;
/* /*
* "type" indicate it's contest's submission(type = 1) or normal submission(type = 0) * "type" indicate it's contest's submission(type = 1) or normal submission(type = 0)
* if it's contest's submission (type = 1), the type_info is contest_id * if it's contest's submission (type = 1), the type_info is contest_id

4
models/user_to_practice.ts

@ -20,6 +20,10 @@ export default class UserToPractice extends Model {
@TypeORM.Column({ nullable: true, type: "integer" }) @TypeORM.Column({ nullable: true, type: "integer" })
p_id: number; p_id: number;
@TypeORM.Index()
@TypeORM.Column({ nullable: true, type: "integer" })
s_id: number;
@TypeORM.Index() @TypeORM.Index()
@TypeORM.Column({ type: "integer" }) @TypeORM.Column({ type: "integer" })
is_practice: number; is_practice: number;

8
modules/practice.js

@ -162,11 +162,12 @@ app.get('/api/practice/classify/:id', async (req, res) => {
} }
}); });
app.get('/api/pass/:cid/:pid',async (req, res) => { app.get('/api/pass/:cid/:pid/:sid',async (req, res) => {
try { try {
const c_id = parseInt(req.params.cid); const c_id = parseInt(req.params.cid);
const p_id = parseInt(req.params.pid); const p_id = parseInt(req.params.pid);
const u_id = res.locals.user.id; const u_id = res.locals.user.id;
const s_id = parseInt(req.params.sid);
let utopQuery = UToP.createQueryBuilder(); let utopQuery = UToP.createQueryBuilder();
let query = Classify.createQueryBuilder(); let query = Classify.createQueryBuilder();
let userQuery = User.createQueryBuilder(); let userQuery = User.createQueryBuilder();
@ -185,6 +186,7 @@ app.get('/api/pass/:cid/:pid',async (req, res) => {
u_id, u_id,
c_id, c_id,
p_id, p_id,
s_id,
is_practice: 1, is_practice: 1,
is_finished: 1, is_finished: 1,
practice_num: 1 practice_num: 1
@ -205,11 +207,12 @@ app.get('/api/pass/:cid/:pid',async (req, res) => {
} }
}); });
app.get('/api/nopass/:cid/:pid',async (req, res) => { app.get('/api/nopass/:cid/:pid/:sid',async (req, res) => {
try { try {
const c_id = parseInt(req.params.cid); const c_id = parseInt(req.params.cid);
const p_id = parseInt(req.params.pid); const p_id = parseInt(req.params.pid);
const u_id = res.locals.user.id; const u_id = res.locals.user.id;
const s_id = parseInt(req.params.sid);
let utopQuery = UToP.createQueryBuilder(); let utopQuery = UToP.createQueryBuilder();
let query = Classify.createQueryBuilder(); let query = Classify.createQueryBuilder();
let utopResult = await utopQuery.where("c_id = :c_id", { c_id }).andWhere("u_id=:u_id", {u_id}).andWhere("p_id=:p_id", {p_id}).getOne(); let utopResult = await utopQuery.where("c_id = :c_id", { c_id }).andWhere("u_id=:u_id", {u_id}).andWhere("p_id=:p_id", {p_id}).getOne();
@ -223,6 +226,7 @@ app.get('/api/nopass/:cid/:pid',async (req, res) => {
u_id, u_id,
c_id, c_id,
p_id, p_id,
s_id,
is_practice: 1, is_practice: 1,
practice_num: 1, practice_num: 1,
is_finished: 0 is_finished: 0

26
modules/submission.js

@ -3,6 +3,7 @@ let FormattedCode = syzoj.model('formatted_code');
let User = syzoj.model('user'); let User = syzoj.model('user');
let Contest = syzoj.model('contest'); let Contest = syzoj.model('contest');
let Problem = syzoj.model('problem'); let Problem = syzoj.model('problem');
let UToP = syzoj.model('user_to_practice');
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const { getSubmissionInfo, getRoughResult, processOverallResult } = require('../libs/submissions_process'); const { getSubmissionInfo, getRoughResult, processOverallResult } = require('../libs/submissions_process');
@ -125,10 +126,17 @@ app.get('/submissions', async (req, res) => {
await judge_state.forEachAsync(async obj => { await judge_state.forEachAsync(async obj => {
await obj.loadRelationships(); await obj.loadRelationships();
}); });
res.render('submissions', { const items = await judge_state.mapAsync(async x => {
items: judge_state.map(x => ({ let utopQuery = UToP.createQueryBuilder();
info: getSubmissionInfo(x, displayConfig), let practiceInfo = await utopQuery.where("s_id = :s_id", { s_id:x.id }).getOne();
let info = getSubmissionInfo(x, displayConfig);
if (practiceInfo) {
info.isPractice = true;
info.c_id = practiceInfo.c_id;
}
return {
info,
token: (x.pending && x.task_id != null) ? jwt.sign({ token: (x.pending && x.task_id != null) ? jwt.sign({
taskId: x.task_id, taskId: x.task_id,
type: 'rough', type: 'rough',
@ -136,7 +144,11 @@ app.get('/submissions', async (req, res) => {
}, syzoj.config.session_secret) : null, }, syzoj.config.session_secret) : null,
result: getRoughResult(x, displayConfig, true), result: getRoughResult(x, displayConfig, true),
running: false, running: false,
})), }
})
res.render('submissions', {
items,
paginate: paginate, paginate: paginate,
pushType: 'rough', pushType: 'rough',
form: req.query, form: req.query,
@ -161,7 +173,6 @@ app.get('/submission/practice/:id/:pid/:cid', async (req, res) => {
if (!judge) throw new ErrorMessage("提交记录 ID 不正确。"); if (!judge) throw new ErrorMessage("提交记录 ID 不正确。");
const curUser = res.locals.user; const curUser = res.locals.user;
if (!await judge.isAllowedVisitBy(curUser)) throw new ErrorMessage('您没有权限进行此操作。'); if (!await judge.isAllowedVisitBy(curUser)) throw new ErrorMessage('您没有权限进行此操作。');
await judge.loadRelationships(); await judge.loadRelationships();
if (judge.problem.type !== 'submit-answer') { if (judge.problem.type !== 'submit-answer') {
@ -208,7 +219,8 @@ app.get('/submission/practice/:id/:pid/:cid', async (req, res) => {
}, syzoj.config.session_secret) : null, }, syzoj.config.session_secret) : null,
displayConfig: currentConfig, displayConfig: currentConfig,
cid, cid,
pid pid,
sid: id
}); });
} catch (e) { } catch (e) {
syzoj.log(e); syzoj.log(e);

11
views/submission_practice.ejs

@ -57,6 +57,7 @@
</table> </table>
<div id="cid" class="disabled"><%= cid %></div> <div id="cid" class="disabled"><%= cid %></div>
<div id="pid" class="disabled"><%= pid %></div> <div id="pid" class="disabled"><%= pid %></div>
<div id="sid" class="disabled"><%= sid %></div>
<code-box no-escape v-bind:content="code"> <code-box no-escape v-bind:content="code">
<% if (formattedCode !== null) { %> <% if (formattedCode !== null) { %>
<a onclick="toggleFormattedCode()" class="ui button" style="position: absolute; top: 0px; right: -4px; border-top-left-radius: 0; border-bottom-right-radius: 0; "> <a onclick="toggleFormattedCode()" class="ui button" style="position: absolute; top: 0px; right: -4px; border-top-left-radius: 0; border-bottom-right-radius: 0; ">
@ -319,6 +320,8 @@ if (token != null) {
const loadSocketIO = function () { const loadSocketIO = function () {
const cid = parseInt(document.getElementById('cid').innerHTML); const cid = parseInt(document.getElementById('cid').innerHTML);
const pid = parseInt(document.getElementById('pid').innerHTML); const pid = parseInt(document.getElementById('pid').innerHTML);
const sid = parseInt(document.getElementById('sid').innerHTML);
console.log(sid);
let currentVersion = 0; let currentVersion = 0;
const socket = io(socketUrl); const socket = io(socketUrl);
socket.on('connect', function () { socket.on('connect', function () {
@ -345,7 +348,7 @@ if (token != null) {
vueApp.roughData.result = p.roughResult; vueApp.roughData.result = p.roughResult;
if (p.roughResult.result === 'Accepted') { if (p.roughResult.result === 'Accepted') {
$.ajax({ $.ajax({
url: `/api/pass/${cid}/${pid}`, url: `/api/pass/${cid}/${pid}/${sid}`,
type: 'GET', type: 'GET',
success: function (data) { success: function (data) {
}, },
@ -355,7 +358,7 @@ if (token != null) {
}); });
} else { } else {
$.ajax({ $.ajax({
url: `/api/nopass/${cid}/${pid}`, url: `/api/nopass/${cid}/${pid}/${sid}`,
type: 'GET', type: 'GET',
success: function (data) { success: function (data) {
}, },
@ -386,7 +389,7 @@ if (token != null) {
vueApp.roughData.running = false; vueApp.roughData.running = false;
// if (data.roughResult.result === 'Accepted') { // if (data.roughResult.result === 'Accepted') {
// $.ajax({ // $.ajax({
// url: `/api/pass/${cid}/${pid}`, // url: `/api/pass/${cid}/${pid}/${sid}`,
// type: 'GET', // type: 'GET',
// success: function (data) { // success: function (data) {
// }, // },
@ -396,7 +399,7 @@ if (token != null) {
// }); // });
// } else { // } else {
// $.ajax({ // $.ajax({
// url: `/api/nopass/${cid}/${pid}`, // url: `/api/nopass/${cid}/${pid}/${sid}`,
// type: 'GET', // type: 'GET',
// success: function (data) { // success: function (data) {
// }, // },

Loading…
Cancel
Save