From 141113a9f7973b938d2b0ec5ec4a57aa33b4607d Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 14 Dec 2016 16:36:31 +0800 Subject: [PATCH] New UI for problem submit --- config-example.json | 48 +++++++++--- models/problem.js | 24 ++++-- modules/contest.js | 7 +- modules/problem.js | 7 +- views/contest_problem.ejs | 81 -------------------- views/problem.ejs | 156 ++++++++++++++++++++++++++++++-------- views/submit.ejs | 26 ------- 7 files changed, 189 insertions(+), 160 deletions(-) delete mode 100644 views/contest_problem.ejs delete mode 100644 views/submit.ejs diff --git a/config-example.json b/config-example.json index 4b636f1..6437c22 100644 --- a/config-example.json +++ b/config-example.json @@ -32,51 +32,75 @@ "languages": { "cpp": { "show": "C++", - "highlight": "cpp" + "highlight": "cpp", + "version": "GCC 5.4.0", + "editor": "c_cpp" }, "cpp11": { "show": "C++11", - "highlight": "cpp" + "highlight": "cpp", + "version": "GCC 5.4.0", + "editor": "c_cpp" }, "csharp": { "show": "C#", - "highlight": "csharp" + "highlight": "csharp", + "version": "MCS 4.6.2.0, Mono 4.6.2", + "editor": "csharp" }, "c": { "show": "C", - "highlight": "c" + "highlight": "c", + "version": "GCC 5.4.0", + "editor": "c_cpp" }, "java": { "show": "Java", - "highlight": "java" + "highlight": "java", + "version": "GCC 5.4.0", + "editor": "java" }, "pascal": { "show": "Pascal", - "highlight": "pascal" + "highlight": "pascal", + "version": "FPC 3.0.0", + "editor": "pascal" }, "python2": { "show": "Python 2", - "highlight": "python" + "highlight": "python", + "version": "CPython 2.7.12", + "editor": "python" }, "python3": { "show": "Python 3", - "highlight": "python" + "highlight": "python", + "version": "CPython 3.5.2", + "editor": "python" }, "nodejs": { "show": "Node.js", - "highlight": "js" + "highlight": "js", + "version": "7.2.1", + "editor": "javascript" }, "ruby": { "show": "Ruby", - "highlight": "ruby" + "highlight": "ruby", + "version": "2.3.1", + "editor": "ruby" }, "haskell": { "show": "Haskell", - "highlight": "haskell" + "highlight": "haskell", + "version": "GHC 7.10.3", + "editor": "haskell" }, "vbnet": { "show": "Visual Basic", - "highlight": "vbnet" + "highlight": "vbnet", + "version": "VBNC 0.0.0.5943, Mono 4.6.2", + "editor": "vbscript" } }, "notices": [ diff --git a/models/problem.js b/models/problem.js index cc9b065..51fceb3 100644 --- a/models/problem.js +++ b/models/problem.js @@ -129,23 +129,33 @@ class Problem extends Model { this.testdata_id = file.id; } - async getJudgeState(user) { + async getJudgeState(user, acFirst) { if (!user) return null; let JudgeState = syzoj.model('judge_state'); - let states = await JudgeState.query(null, { + let where = { user_id: user.id, problem_id: this.id - }, [['submit_time', 'desc']]); + }; - if (!states || states.length === 0) return null; + if (acFirst) { + where.status = 'Accepted'; - for (let x of states) { - if (x.status === 'Accepted') return x; + let state = await JudgeState.findOne({ + where: where, + order: [['submit_time', 'desc']] + }); + + if (state) return state; } - return states[0]; + if (where.status) delete where.status; + + return await JudgeState.findOne({ + where: where, + order: [['submit_time', 'desc']] + }); } getModel() { return model; } diff --git a/modules/contest.js b/modules/contest.js index d09b40b..4fd1a85 100644 --- a/modules/contest.js +++ b/modules/contest.js @@ -218,9 +218,12 @@ app.get('/contest/:id/:pid', async (req, res) => { await syzoj.utils.markdown(problem, [ 'description', 'input_format', 'output_format', 'example', 'limit_and_hint' ]); - res.render('contest_problem', { + let state = await problem.getJudgeState(res.locals.user, false); + + res.render('problem', { contest: contest, - problem: problem + problem: problem, + state: state }); } catch (e) { syzoj.log(e); diff --git a/modules/problem.js b/modules/problem.js index a38a7e1..67ca719 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -31,7 +31,7 @@ app.get('/problem', async (req, res) => { await problems.forEachAsync(async problem => { problem.allowedEdit = await problem.isAllowedEditBy(res.locals.user); - problem.judge_state = await problem.getJudgeState(res.locals.user); + problem.judge_state = await problem.getJudgeState(res.locals.user, true); }); res.render('problem_set', { @@ -64,8 +64,11 @@ app.get('/problem/:id', async (req, res) => { throw 'Permission denied'; } + let state = await problem.getJudgeState(res.locals.user, false); + res.render('problem', { - problem: problem + problem: problem, + state: state }); } catch (e) { syzoj.log(e); diff --git a/views/contest_problem.ejs b/views/contest_problem.ejs deleted file mode 100644 index 7fc4fca..0000000 --- a/views/contest_problem.ejs +++ /dev/null @@ -1,81 +0,0 @@ -<% this.title = syzoj.utils.removeTitleTag(problem.title) + ' - ' + contest.title + ' - 比赛' %> -<% include header %> -
-
-

<%= syzoj.utils.removeTitleTag(problem.title) %>

-
-
- 内存限制: <%= problem.memory_limit %> MiB - 时间限制: <%= problem.time_limit %> ms -
-
- <% if (problem.file_io) { %> - 输入文件: <%= problem.file_io_input_name %> - 输出文件: <%= problem.file_io_output_name %> - <% } else { %> - 标准输入输出 - <% } %> -
-
-
-
-
- -
-
-
-
-

题目描述

-
<%- problem.description %>
-
-
-
-
-

输入格式

-
<%- problem.input_format %>
-
-
-
-
-

输出格式

-
<%- problem.output_format %>
-
-
-
-
-

测试样例

-
<%- problem.example %>
-
-
-
-
-

数据范围与提示

-
<%- problem.limit_and_hint %>
-
-
-
- -

提交代码

-
-
- - -
-
- -
- -
- -<% include footer %> diff --git a/views/problem.ejs b/views/problem.ejs index 707d0cb..fcc9dd7 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -1,38 +1,66 @@ -<% this.title = problem.title + ' - 题目' %> +<% +if (typeof contest === 'undefined') contest = null; +if (contest) { + this.title = syzoj.utils.removeTitleTag(problem.title) + ' - ' + contest.title + ' - 比赛'; +} else { + this.title = problem.title + ' - 题目'; +} +%> <% include header %> -
-
-

<%= problem.title %><% if (problem.allowedEdit && !problem.is_public) { %>未公开<% } %>

-
-
- 内存限制: <%= problem.memory_limit %> MiB - 时间限制: <%= problem.time_limit %> ms -
-
- <% if (problem.file_io) { %> - 输入文件: <%= problem.file_io_input_name %> - 输出文件: <%= problem.file_io_output_name %> - <% } else { %> - 标准输入输出 - <% } %> -
+ +
+
+

+ <% if (contest) { %> + <%= syzoj.utils.removeTitleTag(problem.title) %> + <% } else { %> + <%= problem.title %><% if (problem.allowedEdit && !problem.is_public) { %>未公开<% } %> + <% } %> +

+
+
+ 内存限制: <%= problem.memory_limit %> MiB + 时间限制: <%= problem.time_limit %> ms
+
+ <% if (problem.file_io) { %> + 输入文件: <%= problem.file_io_input_name %> + 输出文件: <%= problem.file_io_output_name %> + <% } else { %> + 标准输入输出 + <% } %> +
+
- 提交 - 提交记录 - 下载测试数据 - <% if (problem.allowedEdit) { %> - 编辑题面 - 上传测试数据 - <% } %> - <% if (user && user.is_admin) { %> - <% if (problem.is_public) { %> - - <% } else { %> - + 提交 + <% if (contest) { %> + 返回比赛 + <% } else { %> + 提交记录 + 下载测试数据 + <% if (problem.allowedEdit) { %> + 编辑题面 + 上传测试数据 + <% } %> + <% if (user && user.is_admin) { %> + <% if (problem.is_public) { %> + + <% } else { %> + + <% } %> <% } %> <% } %>
@@ -68,9 +96,77 @@
<%- problem.limit_and_hint %>
+
+
+ <% + let formUrl; + if (contest) formUrl = syzoj.utils.makeUrl(['submit', problem.id], { contest_id: contest.id }); + else formUrl = syzoj.utils.makeUrl(['submit', problem.id]); + %> +
+ + +
+
+ +
+
+
<% if (state) { %><%= state.code %><% } %>
+
+
+
+
+
+
+ <% include footer %> diff --git a/views/submit.ejs b/views/submit.ejs deleted file mode 100644 index 09774ce..0000000 --- a/views/submit.ejs +++ /dev/null @@ -1,26 +0,0 @@ -<% this.title = problem.title + ' - 提交'; %> -<% include header %> -

提交 <%= problem.title %>

-
-
-
- - -
-
- - -
- -
-
- -<% include footer %>