diff --git a/modules/judge.js b/modules/judge.js index ac274df..f83e7a7 100644 --- a/modules/judge.js +++ b/modules/judge.js @@ -51,6 +51,25 @@ app.get('/judge_state', async (req, res) => { } }); +app.get('/judge_state/:id/ajax', async (req, res) => { + try { + let judge_state = await JudgeState.fromID(req.params.id); + if (!judge_state) throw 'No such judge state'; + + judge_state.hidden = !(await judge_state.isAllowedSeeResultBy(res.locals.user)); + judge_state.allowedSeeCode = await judge_state.isAllowedSeeCodeBy(res.locals.user); + + res.render('judge_state_item', { + judge: judge_state + }); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }); + } +}); + app.get('/judge_detail/:id', async (req, res) => { try { let id = parseInt(req.params.id); @@ -71,3 +90,24 @@ app.get('/judge_detail/:id', async (req, res) => { }); } }); + +app.get('/judge_detail/:id/ajax', async (req, res) => { + try { + let id = parseInt(req.params.id); + let judge = await JudgeState.fromID(id); + + judge.code = await syzoj.utils.highlight(judge.code, judge.language); + if (judge.result.compiler_output) judge.result.compiler_output = syzoj.utils.ansiToHTML(judge.result.compiler_output); + judge.allowedSeeResult = await judge.isAllowedSeeResultBy(res.locals.user); + judge.allowedSeeCode = await judge.isAllowedSeeCodeBy(res.locals.user); + + res.render('judge_detail_item', { + judge: judge + }); + } catch (e) { + syzoj.log(e); + res.render('error', { + err: e + }); + } +}); diff --git a/views/header.ejs b/views/header.ejs index 24f06b2..34eb6ff 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -1,25 +1,4 @@ -<% -this.getStatusMeta = (status) => { - if (status.startsWith('Running')) return 'Running'; - else return status; -} - -this.icon = { - 'Accepted': 'checkmark', - 'Wrong Answer': 'remove', - 'Runtime Error': 'bomb', - 'Time Limit Exceeded': 'clock', - 'Memory Limit Exceeded': 'disk outline', - 'Output Limit Exceeded': 'print', - 'File Error': 'file outline', - 'Waiting': 'hourglass half', - 'Running': 'spinner', - 'Compiling': 'spinner', - 'Compile Error': 'code', - 'System Error': 'server', - 'No Testdata': 'folder open outline' -} -%> +<% include util %> diff --git a/views/judge_detail.ejs b/views/judge_detail.ejs index 4c6c4a3..d4053fe 100644 --- a/views/judge_detail.ejs +++ b/views/judge_detail.ejs @@ -1,101 +1,4 @@ <% this.title = '评测详细信息' %> <% include header %> -
- - - - - - - - - - - - - - - - - - <% if (judge.allowedSeeResult) { %> - - - - - <% } else { %> - - - - - <% } %> - - - - -
编号题目名称状态分数总时间内存提交者提交时间
#<%= judge.id %>#<%= judge.problem_id %>. <%= judge.problem.title %> - - <%= judge.result.status %> - <%= judge.result.score %><%= judge.result.total_time %> ms<%= judge.result.max_memory %> KiB隐藏隐藏隐藏隐藏<%= judge.user.username %><% if (judge.user.nameplate) { %><%- judge.user.nameplate %><% } %><%= syzoj.utils.formatDate(judge.submit_time) %>
- <% if (judge.allowedSeeCode) { %> -
<%- judge.code %>
- <% } %> -<% if (judge.result.compiler_output && judge.result.status === 'Compile Error' && judge.allowedSeeCode) { %> -

编译信息

-
<%- judge.result.compiler_output %>
-<% } else if (judge.allowedSeeResult) { %> -
- <% for (let i = 0; i < judge.result.case_num; i++) { %> - <% - let testcase = judge.result[i], pending = false; - if (!testcase) { - pending = true; - if (i == 0 || judge.result[i - 1]) { - testcase = { - status: 'Running' - }; - } else { - testcase = { - status: 'Waiting' - }; - } - } - %> -
style="cursor: auto; "<% } %>> -
-
测试点 #<%= i + 1 %>
-
- - <%= testcase.status %>
- <% if (!pending) { %> -
用时:<%= testcase.time_used %> ms
-
内存:<%= testcase.memory_used %> KiB
- <% } %> -
-
- <% if (!pending) { %> -
-

- 输入文件 -

<%= testcase.input %>
- 期望输出 -
<%= testcase.answer %>
- 你的输出 -
<%= testcase.user_out %>
-

-
- <% } %> - <% } %> -
-<% } %> - - +<% include judge_detail_item %> <% include footer %> diff --git a/views/judge_detail_item.ejs b/views/judge_detail_item.ejs new file mode 100644 index 0000000..cbcece4 --- /dev/null +++ b/views/judge_detail_item.ejs @@ -0,0 +1,119 @@ +
+ + + + + + + + + + + + + + + + + + <% if (judge.allowedSeeResult) { %> + + + + + <% } else { %> + + + + + <% } %> + + + + +
编号题目名称状态分数总时间内存提交者提交时间
#<%= judge.id %>#<%= judge.problem_id %>. <%= judge.problem.title %> + + <%= judge.result.status %> + <%= judge.result.score %><%= judge.result.total_time %> ms<%= judge.result.max_memory %> KiB隐藏隐藏隐藏隐藏<%= judge.user.username %><% if (judge.user.nameplate) { %><%- judge.user.nameplate %><% } %><%= syzoj.utils.formatDate(judge.submit_time) %>
+ <% if (judge.allowedSeeCode) { %> +
<%- judge.code %>
+ <% } %> +<% if (judge.result.compiler_output && judge.result.status === 'Compile Error' && judge.allowedSeeCode) { %> +

编译信息

+
<%- judge.result.compiler_output %>
+<% } else if (judge.allowedSeeResult) { %> +
+ <% for (let i = 0; i < judge.result.case_num; i++) { %> + <% + let testcase = judge.result[i], pending = false; + if (!testcase) { + pending = true; + if (i == 0 || judge.result[i - 1]) { + testcase = { + status: 'Running' + }; + } else { + testcase = { + status: 'Waiting' + }; + } + } + %> +
style="cursor: auto; "<% } %>> +
+
测试点 #<%= i + 1 %>
+
+ + <%= testcase.status %>
+ <% if (!pending) { %> +
用时:<%= testcase.time_used %> ms
+
内存:<%= testcase.memory_used %> KiB
+ <% } %> +
+
+ <% if (!pending) { %> +
+

+ 输入文件 +

<%= testcase.input %>
+ 期望输出 +
<%= testcase.answer %>
+ 你的输出 +
<%= testcase.user_out %>
+

+
+ <% } %> + <% } %> +
+<% } %> +
+ + + +<% if (isPending(judge.status)) { %> + +<% } %> diff --git a/views/judge_state.ejs b/views/judge_state.ejs index 29a1d1e..8929575 100644 --- a/views/judge_state.ejs +++ b/views/judge_state.ejs @@ -31,30 +31,8 @@ <% for (let judge of judge_state) { %> - - #<%= judge.id %> - #<%= judge.problem_id %>. <%= judge.problem.title %> - <% if (!judge.hidden) { %> - - - - <%= judge.status %> - - - <%= judge.result.score %> - <%= judge.result.total_time %> ms - <%= judge.result.max_memory %> KiB - <% } else { %> - 隐藏 - 隐藏 - 隐藏 - 隐藏 - <% } %> - <%= judge.user.username %><% if (judge.user.nameplate) { %><%- judge.user.nameplate %><% } %> - <%= syzoj.utils.formatDate(judge.submit_time) %> - - - <% } %> + <% include judge_state_item %> + <% } %>
diff --git a/views/judge_state_item.ejs b/views/judge_state_item.ejs new file mode 100644 index 0000000..a22a42b --- /dev/null +++ b/views/judge_state_item.ejs @@ -0,0 +1,36 @@ +<% include util %> +#<%= judge.id %> +#<%= judge.problem_id %>. <%= judge.problem.title %> +<% if (!judge.hidden) { %> + + + + <%= judge.status %> + + +<%= judge.result.score %> +<%= judge.result.total_time %> ms +<%= judge.result.max_memory %> KiB +<% } else { %> + 隐藏 + 隐藏 + 隐藏 + 隐藏 +<% } %> +<%= judge.user.username %><% if (judge.user.nameplate) { %><%- judge.user.nameplate %><% } %> +<%= syzoj.utils.formatDate(judge.submit_time) %> + +<% if (isPending(judge.status)) { %> + +<% } %> diff --git a/views/util.ejs b/views/util.ejs new file mode 100644 index 0000000..8e47d14 --- /dev/null +++ b/views/util.ejs @@ -0,0 +1,31 @@ +<% +this.getStatusMeta = (status) => { + if (status.startsWith('Running')) return 'Running'; + else return status; +} + +this.isPending = (status) => { + let pending = [ + 'Waiting', + 'Compiling', + 'Running' + ]; + return pending.includes(this.getStatusMeta(status)); +} + +this.icon = { + 'Accepted': 'checkmark', + 'Wrong Answer': 'remove', + 'Runtime Error': 'bomb', + 'Time Limit Exceeded': 'clock', + 'Memory Limit Exceeded': 'disk outline', + 'Output Limit Exceeded': 'print', + 'File Error': 'file outline', + 'Waiting': 'hourglass half', + 'Running': 'spinner', + 'Compiling': 'spinner', + 'Compile Error': 'code', + 'System Error': 'server', + 'No Testdata': 'folder open outline' +} +%>