From a2600d5cc4bca9d72ad1ef52ad12d185a6645490 Mon Sep 17 00:00:00 2001 From: masnn Date: Thu, 9 Apr 2020 20:10:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0path=5Fsection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hydro/handler/problem.js | 47 ++++++++++++++++--- hydro/handler/record.js | 16 ++++++- templates/partials/header.html | 7 +-- templates/partials/path.html | 6 +-- .../scratchpad/ScratchpadToolbarContainer.js | 15 +----- ui/jsconfig.json | 1 + ui/pages/problem_copy.page.js | 8 ---- ui/pages/problem_import.page.js | 6 +++ 8 files changed, 67 insertions(+), 39 deletions(-) delete mode 100644 ui/pages/problem_copy.page.js create mode 100644 ui/pages/problem_import.page.js diff --git a/hydro/handler/problem.js b/hydro/handler/problem.js index 3df5bbfa..e448cbc5 100644 --- a/hydro/handler/problem.js +++ b/hydro/handler/problem.js @@ -31,7 +31,13 @@ GET('/p', requirePerm(PERM_VIEW_PROBLEM), async ctx => { if (ctx.query.category) q.category = ctx.query.category; if (!ctx.state.user.hasPerm(PERM_VIEW_PROBLEM_HIDDEN)) q.hidden = false; let pdocs = await problem.getMany(q, { pid: 1 }, page, constants.PROBLEM_PER_PAGE); - ctx.body = { page, pdocs, category: '' }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['problem_main', null] + ], + page, pdocs, category: '' + }; }); GET('/problem/random', requirePerm(PERM_VIEW_PROBLEM), async ctx => { let q = {}; @@ -47,7 +53,14 @@ GET('/p/:pid', requirePerm(PERM_VIEW_PROBLEM), async ctx => { let pdoc = await problem.get({ pid, uid }); if (pdoc.hidden) ctx.checkPerm(PERM_VIEW_PROBLEM_HIDDEN); let udoc = await user.getById(pdoc.owner); - ctx.body = { pdoc, udoc, title: pdoc.title }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['problem_main', '/p'], + [pdoc.title, null, true] + ], + pdoc, udoc, title: pdoc.title + }; }); GET('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => { ctx.templateName = 'problem_submit.html'; @@ -56,7 +69,15 @@ GET('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => { let pdoc = await problem.get({ pid, uid }); if (pdoc.hidden) ctx.checkPerm(PERM_VIEW_PROBLEM_HIDDEN); let udoc = await user.getById(pdoc.owner); - ctx.body = { pdoc, udoc, title: pdoc.title }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['problem_main', '/p'], + [pdoc.title, `/p/${pid}`, true], + ['problem_submit', null] + ], + pdoc, udoc, title: pdoc.title + }; }); POST('/p/:pid/submit', requirePerm(PERM_SUBMIT_PROBLEM), async ctx => { let rid = await record.add({ @@ -74,13 +95,19 @@ GET('/p/:pid/settings', async ctx => { ctx.templateName = 'problem_settings.html'; let pdoc = await problem.get({ pid: ctx.params.pid, uid: ctx.state.user._id }); if (pdoc.hidden) ctx.checkPerm(PERM_VIEW_PROBLEM_HIDDEN); - ctx.body = { pdoc }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['problem_main', '/p'], + [pdoc.title, `/p/${ctx.params.pid}`, true], + ['problem_settings', null] + ], pdoc + }; }); POST('/p/:pid/settings', async ctx => { ctx.templateName = 'problem_settings.html'; // TODO(masnn) - let pdoc = await problem.get({ pid: ctx.params.pid, uid: ctx.state.user._id }); - ctx.body = { pdoc }; + ctx.back(); }); GET('/p/:pid/upload', async ctx => { ctx.templateName = 'problem_upload.html'; @@ -123,7 +150,13 @@ GET('/p/:pid/data', async ctx => { }); GET('/problem/create', requirePerm(PERM_CREATE_PROBLEM), async ctx => { ctx.templateName = 'problem_edit.html'; - ctx.body = { page_name: 'problem_create' }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['problem_main', '/p'], + ['problem_create', null] + ], page_name: 'problem_create' + }; }); POST('/problem/create', requirePerm(PERM_CREATE_PROBLEM), async ctx => { let { title, pid, content, hidden } = ctx.request.body; diff --git a/hydro/handler/record.js b/hydro/handler/record.js index 489d1f28..42a5767d 100644 --- a/hydro/handler/record.js +++ b/hydro/handler/record.js @@ -21,7 +21,13 @@ GET('/r', async ctx => { udict[rdoc.uid] = await user.getById(rdoc.uid); pdict[rdoc.pid] = await problem.get({ pid: rdoc.pid, uid: ctx.state.user._id }); } - ctx.body = { page, rdocs, pdict, udict }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['record_main', null] + ], + page, rdocs, pdict, udict + }; }); SOCKET('/record-conn', [], conn => { let tid = conn.params.tid; @@ -43,7 +49,13 @@ GET('/r/:rid', async ctx => { let rdoc = await record.get(rid); if (rdoc.hidden) ctx.checkPerm(PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); if (rdoc.uid != uid && !ctx.state.user.hasPerm(PERM_READ_RECORD_CODE)) rdoc.code = null; - ctx.body = { rdoc, show_status: true }; + ctx.body = { + path: [ + ['Hydro', '/'], + ['record_detail', null] + ], + rdoc, show_status: true + }; }); SOCKET('/record-detail-conn', [], async conn => { let rdoc = await record.get(conn.params.rid); diff --git a/templates/partials/header.html b/templates/partials/header.html index f869224d..8ba1591f 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -1,11 +1,6 @@
- {% if domain_id == vj4.model.builtin.DOMAIN_ID_SYSTEM %} - - {% else %} - - - {% endif %} +
{% include "partials/path.html" %}
diff --git a/templates/partials/path.html b/templates/partials/path.html index 52c79795..b669c3ed 100644 --- a/templates/partials/path.html +++ b/templates/partials/path.html @@ -4,11 +4,11 @@
- {% for c in path_components %} - / {% if c[1] %}{{ c[0] }}{% endif %} + {% for c in path %} + / {% if c[1] %}{{ c[0] if c[2] else _(c[0]) }}{% endif %} {%- endfor %}
-

{{ path_components[-1][0] }}

+

{{ path[path.length - 1][0] if path[path.length - 1][0] else _(path[path.length - 1][0]) }}

{% include "partials/hamburger.html" %} diff --git a/ui/components/scratchpad/ScratchpadToolbarContainer.js b/ui/components/scratchpad/ScratchpadToolbarContainer.js index ed604b1a..2e0b7bfd 100644 --- a/ui/components/scratchpad/ScratchpadToolbarContainer.js +++ b/ui/components/scratchpad/ScratchpadToolbarContainer.js @@ -13,20 +13,11 @@ import Toolbar, { ToolbarSplitComponent as ToolbarSplit, } from './ToolbarComponent'; -function isTestCaseDataValid(data) { - return data.input.trim().length > 0 && data.output.trim().length > 0; -} - -function isPretestValid(state) { - return _.some(state.tabs, id => isTestCaseDataValid(state.data[id])); -} - const mapStateToProps = state => ({ pretestVisible: state.ui.pretest.visible, recordsVisible: state.ui.records.visible, isPosting: state.ui.isPosting, editorLang: state.editor.lang, - pretestValid: isPretestValid(state.pretest), }); const mapDispatchToProps = dispatch => ({ @@ -45,9 +36,7 @@ const mapDispatchToProps = dispatch => ({ postPretest(context) { const state = context.store.getState(); const { pretest } = state; - const testCases = pretest.tabs - .filter(tabId => isTestCaseDataValid(pretest.data[tabId])); - // const titles = testCases.map(tabId => pretest.meta[tabId].title); + const testCases = pretest.tabs; const inputs = testCases.map(tabId => pretest.data[tabId].input); const outputs = testCases.map(tabId => pretest.data[tabId].output); const req = request.post(Context.postPretestUrl, { @@ -123,7 +112,7 @@ export default class ScratchpadToolbarContainer extends React.PureComponent { this.props.togglePanel('pretest')} data-global-hotkey="alt+p" data-tooltip={`${i18n('Toggle Pretest Panel')} (Alt+P)`} diff --git a/ui/jsconfig.json b/ui/jsconfig.json index ddde7e50..da29ffa9 100644 --- a/ui/jsconfig.json +++ b/ui/jsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "experimentalDecorators": true, "target": "ES6", "baseUrl": ".", "paths": { diff --git a/ui/pages/problem_copy.page.js b/ui/pages/problem_copy.page.js deleted file mode 100644 index b0abf1e7..00000000 --- a/ui/pages/problem_copy.page.js +++ /dev/null @@ -1,8 +0,0 @@ -import { NamedPage } from 'vj/misc/PageLoader'; -import DomainSelectAutoComplete from 'vj/components/autocomplete/DomainSelectAutoComplete'; - -const page = new NamedPage('problem_copy', async () => { - DomainSelectAutoComplete.getOrConstruct($('.section__body [name="src_domain_id"]')); -}); - -export default page; diff --git a/ui/pages/problem_import.page.js b/ui/pages/problem_import.page.js new file mode 100644 index 00000000..7c645097 --- /dev/null +++ b/ui/pages/problem_import.page.js @@ -0,0 +1,6 @@ +import { NamedPage } from 'vj/misc/PageLoader'; + +const page = new NamedPage('problem_import', async () => { +}); + +export default page;