path_components

This commit is contained in:
masnn committed 2020-06-13 12:24:54 +08:00
1 parent 5ca424da0b
commit c93597703e
15 files changed
+134 -130

No files matched your search

+20 -20
View File
@@ -35,7 +35,7 @@ class ContestListHandler extends ContestHandler {
for (const tdoc of tdocs) tids.push(tdoc.docId); for (const tdoc of tdocs) tids.push(tdoc.docId);
const tsdict = await contest.getListStatus(domainId, this.user._id, tids); const tsdict = await contest.getListStatus(domainId, this.user._id, tids);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', null], ['contest_main', null],
]; ];
this.response.body = { this.response.body = {
@@ -71,9 +71,9 @@ class ContestDetailHandler extends ContestHandler {
} else attended = false; } else attended = false;
const udict = await user.getList(domainId, [this.tdoc.owner]); const udict = await user.getList(domainId, [this.tdoc.owner]);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
[this.tdoc.title, null, true], [this.tdoc.title, null, null, true],
]; ];
this.response.body = { this.response.body = {
path, tdoc: this.tdoc, tsdoc, attended, udict, pdict, psdict, rdict, page, path, tdoc: this.tdoc, tsdoc, attended, udict, pdict, psdict, rdict, page,
@@ -91,9 +91,9 @@ class ContestScoreboardHandler extends ContestDetailHandler {
async get({ domainId, tid }) { async get({ domainId, tid }) {
const [tdoc, rows, udict] = await this.getScoreboard(domainId, tid); const [tdoc, rows, udict] = await this.getScoreboard(domainId, tid);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
[tdoc.title, `/c/${tid}`, true], [tdoc.title, 'contest_detail', { tid }, true],
['contest_scoreboard', null], ['contest_scoreboard', null],
]; ];
this.response.template = 'contest_scoreboard.html'; this.response.template = 'contest_scoreboard.html';
@@ -128,9 +128,9 @@ class ContestEditHandler extends ContestDetailHandler {
} }
const duration = (this.tdoc.endAt.getTime() - this.tdoc.beginAt.getTime()) / 3600 / 1000; const duration = (this.tdoc.endAt.getTime() - this.tdoc.beginAt.getTime()) / 3600 / 1000;
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
[this.tdoc.title, `/c/${this.tdoc.docId}`, true], [this.tdoc.title, 'contest_detail', { tid: this.tdoc.docId }, true],
['contest_edit', null], ['contest_edit', null],
]; ];
const dt = this.tdoc.beginAt; const dt = this.tdoc.beginAt;
@@ -192,10 +192,10 @@ class ContestProblemHandler extends ContestDetailHandler {
async get({ tid }) { async get({ tid }) {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
[this.tdoc.title, `/c/${tid}`, true], [this.tdoc.title, 'contest_detail', { tid }, true],
[this.pdoc.title, null, true], [this.pdoc.title, null, null, true],
]; ];
this.response.body = { this.response.body = {
tdoc: this.tdoc, tdoc: this.tdoc,
@@ -219,10 +219,10 @@ class ContestProblemSubmitHandler extends ContestProblemHandler {
} }
this.response.template = 'problem_submit.html'; this.response.template = 'problem_submit.html';
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
[this.tdoc.title, `/c/${tid}`, true], [this.tdoc.title, 'contest_detail', { tid }, true],
[this.pdoc.title, `/c/${tid}/p/${pid}`, true], [this.pdoc.title, 'contest_detail_problem', { tid, pid }, true],
['contest_detail_problem_submit', null], ['contest_detail_problem_submit', null],
]; ];
this.response.body = { this.response.body = {
@@ -269,8 +269,8 @@ class ContestCreateHandler extends ContestHandler {
ts = ts - (ts % (15 * 60 * 1000)) + 15 * 60 * 1000; ts = ts - (ts % (15 * 60 * 1000)) + 15 * 60 * 1000;
const dt = new Date(ts); const dt = new Date(ts);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['contest_main', '/c'], ['contest_main', 'contest_main'],
['contest_create', null], ['contest_create', null],
]; ];
this.response.body = { this.response.body = {
+15 -15
View File
@@ -67,7 +67,7 @@ class DiscussionMainHandler extends Handler {
); );
const udict = await user.getList(domainId, ddocs.map((ddoc) => ddoc.owner)); const udict = await user.getList(domainId, ddocs.map((ddoc) => ddoc.owner));
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['discussion_main', null], ['discussion_main', null],
]; ];
const vndict = await discussion.getListVnodes(domainId, ddocs, this); const vndict = await discussion.getListVnodes(domainId, ddocs, this);
@@ -89,8 +89,8 @@ class DiscussionNodeHandler extends DiscussionHandler {
); );
const udict = await user.getList(domainId, ddocs.map((ddoc) => ddoc.owner)); const udict = await user.getList(domainId, ddocs.map((ddoc) => ddoc.owner));
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['discussion_main', '/discuss'], ['discussion_main', 'discussion_main'],
[this.vnode.title, null, true], [this.vnode.title, null, true],
]; ];
const vndict = { [typeMapper[type]]: { [name]: this.vnode } }; const vndict = { [typeMapper[type]]: { [name]: this.vnode } };
@@ -116,9 +116,9 @@ class DiscussionCreateHandler extends DiscussionHandler {
async get({ type, name }) { async get({ type, name }) {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['discussion_main', '/discuss'], ['discussion_main', 'discussion_main'],
[this.vnode.title, `/discuss/${type}/${name}`, true], [this.vnode.title, 'discussion_node', { type, name }, true],
['discussion_create', null], ['discussion_create', null],
]; ];
this.response.template = 'discussion_create.html'; this.response.template = 'discussion_create.html';
@@ -161,10 +161,10 @@ class DiscussionDetailHandler extends DiscussionHandler {
} }
const udict = await user.getList(domainId, uids); const udict = await user.getList(domainId, uids);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['discussion_main', '/discuss'], ['discussion_main', 'discussion_main'],
[this.vnode.title, `/discuss/${discussion.typeDisplay[this.ddoc.parentType]}/${this.ddoc.parentId}`, true], [this.vnode.title, 'discussion_node', { type: discussion.typeDisplay[this.ddoc.parentType], name: this.ddoc.parentId }, true],
[this.ddoc.title, null, true], [this.ddoc.title, null, null, true],
]; ];
this.response.template = 'discussion_detail.html'; this.response.template = 'discussion_detail.html';
this.response.body = { this.response.body = {
@@ -253,10 +253,10 @@ class DiscussionEditHandler extends DiscussionHandler {
async get() { async get() {
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_DISCUSSION); if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_DISCUSSION);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['discussion_main', '/discuss'], ['discussion_main', 'discussion_main'],
[this.vnode.title, `/discuss/${this.ddoc.parentType}`, true], [this.vnode.title, 'discussion_node', { type: discussion.typeDisplay[this.ddoc.parentType], name: this.ddoc.parentId }, true],
[this.ddoc.title, `/discuss/${this.ddoc.docId}`, true], [this.ddoc.title, 'discussion_detail', { did: this.ddoc.docId }, true],
['discussion_edit', null], ['discussion_edit', null],
]; ];
this.response.template = 'discussion_edit.html'; this.response.template = 'discussion_edit.html';
@@ -278,7 +278,7 @@ class DiscussionEditHandler extends DiscussionHandler {
if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_DISCUSSION); if (this.ddoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_DISCUSSION);
await discussion.delete(domainId, did); await discussion.delete(domainId, did);
this.response.body = { type: this.ddoc.parentType, parent: this.ddoc.parentId }; this.response.body = { type: this.ddoc.parentType, parent: this.ddoc.parentId };
this.response.redirect = `/discuss/${this.ddoc.type}/${this.ddoc.parent}`; this.response.redirect = `/discuss/${this.ddoc.parentType}/${this.ddoc.parentId}`;
} }
} }
+12 -12
View File
@@ -19,7 +19,7 @@ class DomainRankHandler extends Handler {
} }
udocs = await Promise.all(udocs); udocs = await Promise.all(udocs);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['ranking', null], ['ranking', null],
]; ];
this.response.template = 'ranking.html'; this.response.template = 'ranking.html';
@@ -38,7 +38,7 @@ class DomainCreateHandler extends Handler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain_create', null], ['domain_create', null],
]; ];
this.response.body = { path }; this.response.body = { path };
@@ -62,8 +62,8 @@ class ManageHandler extends Handler {
class DomainEditHandler extends ManageHandler { class DomainEditHandler extends ManageHandler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain', '/domain'], ['domain', null],
['domain_edit', null], ['domain_edit', null],
]; ];
this.response.template = 'domain_edit.html'; this.response.template = 'domain_edit.html';
@@ -81,8 +81,8 @@ class DomainEditHandler extends ManageHandler {
class DomainDashboardHandler extends ManageHandler { class DomainDashboardHandler extends ManageHandler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain', '/domain'], ['domain', null],
['domain_dashboard', null], ['domain_dashboard', null],
]; ];
this.response.template = 'domain_dashboard.html'; this.response.template = 'domain_dashboard.html';
@@ -115,8 +115,8 @@ class DomainUserHandler extends ManageHandler {
const rolesSelect = roles.map((role) => [role._id, role._id]); const rolesSelect = roles.map((role) => [role._id, role._id]);
const udict = await user.getList(domainId, uids); const udict = await user.getList(domainId, uids);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain', '/domain'], ['domain', null],
['domain_user', null], ['domain_user', null],
]; ];
this.response.template = 'domain_user.html'; this.response.template = 'domain_user.html';
@@ -135,8 +135,8 @@ class DomainPermissionHandler extends ManageHandler {
async get({ domainId }) { async get({ domainId }) {
const roles = await user.getRoles(domainId); const roles = await user.getRoles(domainId);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain', '/domain'], ['domain', null],
['domain_permission', null], ['domain_permission', null],
]; ];
this.response.template = 'domain_permission.html'; this.response.template = 'domain_permission.html';
@@ -159,8 +159,8 @@ class DomainRoleHandler extends ManageHandler {
async get({ domainId }) { async get({ domainId }) {
const roles = await user.getRoles(domainId); const roles = await user.getRoles(domainId);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['domain', '/domain'], ['domain', null],
['domain_role', null], ['domain_role', null],
]; ];
this.response.template = 'domain_role.html'; this.response.template = 'domain_role.html';
+4 -2
View File
@@ -28,6 +28,7 @@ class HomeHandler extends Handler {
async homework(domainId) { async homework(domainId) {
if (this.user.hasPerm(PERM_VIEW_HOMEWORK)) { if (this.user.hasPerm(PERM_VIEW_HOMEWORK)) {
const tdocs = await contest.getMulti(domainId, {}, document.TYPE_HOMEWORK) const tdocs = await contest.getMulti(domainId, {}, document.TYPE_HOMEWORK)
.sort('beginAt', -1)
.limit(await system.get('HOMEWORK_ON_MAIN')) .limit(await system.get('HOMEWORK_ON_MAIN'))
.toArray(); .toArray();
const tsdict = await contest.getListStatus( const tsdict = await contest.getListStatus(
@@ -42,6 +43,7 @@ class HomeHandler extends Handler {
async contest(domainId) { async contest(domainId) {
if (this.user.hasPerm(PERM_VIEW_CONTEST)) { if (this.user.hasPerm(PERM_VIEW_CONTEST)) {
const tdocs = await contest.getMulti(domainId) const tdocs = await contest.getMulti(domainId)
.sort('beginAt', -1)
.limit(await system.get('CONTESTS_ON_MAIN')) .limit(await system.get('CONTESTS_ON_MAIN'))
.toArray(); .toArray();
const tsdict = await contest.getListStatus( const tsdict = await contest.getListStatus(
@@ -159,7 +161,7 @@ class HomeSettingsHandler extends Handler {
async get({ category }) { async get({ category }) {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
[`home_${category}`, null], [`home_${category}`, null],
]; ];
this.response.template = 'home_settings.html'; this.response.template = 'home_settings.html';
@@ -245,7 +247,7 @@ class HomeMessagesHandler extends Handler {
} }
} }
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['home_messages', null], ['home_messages', null],
]; ];
this.response.body = { messages, udict, path }; this.response.body = { messages, udict, path };
+19 -18
View File
@@ -38,7 +38,7 @@ class HomeworkMainHandler extends HomeworkHandler {
calendar.push(cal); calendar.push(cal);
} }
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', null], ['homework_main', null],
]; ];
this.response.body = { tdocs, calendar, path }; this.response.body = { tdocs, calendar, path };
@@ -80,9 +80,9 @@ class HomeworkDetailHandler extends HomeworkHandler {
uids.push(tdoc.owner); uids.push(tdoc.owner);
const udict = await user.getList(domainId, uids); const udict = await user.getList(domainId, uids);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', '/homework'], ['homework_main', 'homework_main'],
[tdoc.title, null, true], [tdoc.title, null, null, true],
]; ];
this.response.template = 'homework_detail.html'; this.response.template = 'homework_detail.html';
this.response.body = { this.response.body = {
@@ -118,10 +118,10 @@ class HomeworkDetailProblemHandler extends HomeworkHandler {
} }
if (!this.tdoc.pids.includes(pid)) throw new ProblemNotFoundError(domainId, pid, tid); if (!this.tdoc.pids.includes(pid)) throw new ProblemNotFoundError(domainId, pid, tid);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', '/homework'], ['homework_main', '/homework'],
[this.tdoc.title, `/homework/${tid}`, true], [this.tdoc.title, 'homework_detail', { tid }, true],
[this.pdoc.title, null, true], [this.pdoc.title, null, null, true],
]; ];
this.response.template = 'problem_detail.html'; this.response.template = 'problem_detail.html';
this.response.body = { this.response.body = {
@@ -142,10 +142,10 @@ class HomeworkDetailProblemSubmitHandler extends HomeworkDetailProblemHandler {
.sort('_id', -1).limit(10).toArray() .sort('_id', -1).limit(10).toArray()
: []; : [];
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', '/homework'], ['homework_main', 'homework_main'],
[this.tdoc.title, `/homework/${tid}`, true], [this.tdoc.title, 'homework_detail', { tid }, true],
[this.pdoc.title, `/homework/${tid}/p/${pid}`, true], [this.pdoc.title, 'homework_detail_problem', { tid, pid }, true],
['homework_detail_problem_submit', null], ['homework_detail_problem_submit', null],
]; ];
this.response.template = 'problem_submit.html'; this.response.template = 'problem_submit.html';
@@ -178,8 +178,8 @@ class HomeworkCreateHandler extends HomeworkHandler {
const beginAt = moment().add(1, 'day'); const beginAt = moment().add(1, 'day');
const penaltySince = beginAt.add(7, 'days'); const penaltySince = beginAt.add(7, 'days');
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', '/homework'], ['homework_main', 'homework_main'],
['homework_create', null], ['homework_create', null],
]; ];
this.response.template = 'homework_edit.html'; this.response.template = 'homework_edit.html';
@@ -233,9 +233,9 @@ class HomeworkEditHandler extends HomeworkHandler {
(tdoc.endAt.getTime() - tdoc.penaltySince.getTime()) / 36000 / 24, (tdoc.endAt.getTime() - tdoc.penaltySince.getTime()) / 36000 / 24,
) / 100; ) / 100;
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['homework_main', '/homework'], ['homework_main', 'homework_main'],
[tdoc.title, `/homework/${tid}`, true], [tdoc.title, 'homework_detail', { tid }, true],
['homework_edit', null], ['homework_edit', null],
]; ];
const beginAt = moment(tdoc.beginAt).tz(this.user.timeZone); const beginAt = moment(tdoc.beginAt).tz(this.user.timeZone);
@@ -299,8 +299,9 @@ class HomeworkScoreboardHandler extends HomeworkHandler {
domainId, tid, false, document.TYPE_HOMEWORK, domainId, tid, false, document.TYPE_HOMEWORK,
); );
const path = [ const path = [
['homework_main', '/homework'], ['Hydro', 'homepage'],
[tdoc.title, `/homework/${tid}`, true], ['homework_main', 'homework_main'],
[tdoc.title, 'homework_detail', { tid }, true],
['homework_scoreboard', null], ['homework_scoreboard', null],
]; ];
this.response.template = 'contest_scoreboard.html'; this.response.template = 'contest_scoreboard.html';
+2 -2
View File
@@ -12,8 +12,8 @@ class ProblemImportHandler extends Handler {
this.response.template = 'problem_import.html'; this.response.template = 'problem_import.html';
this.response.body = { this.response.body = {
path: [ path: [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
['problem_import', null], ['problem_import', null],
], ],
}; };
+2 -2
View File
@@ -10,8 +10,8 @@ class SystemHandler extends Handler {
if (!this.user.priv) throw new PermissionError('???'); if (!this.user.priv) throw new PermissionError('???');
this.response.body = { this.response.body = {
path: [ path: [
['Hydro', '/'], ['Hydro', 'homepage'],
['manage_main', '/manage'], ['manage_main', null],
], ],
}; };
} }
+2 -1
View File
@@ -28,7 +28,8 @@ class StatusHandler extends Handler {
stats[i].status = desc; stats[i].status = desc;
} }
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['status', null],
]; ];
this.response.body = { stats, path }; this.response.body = { stats, path };
this.response.template = 'status.html'; this.response.template = 'status.html';
+38 -40
View File
@@ -45,7 +45,7 @@ class ProblemHandler extends Handler {
); );
} }
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', null], ['problem_main', null],
]; ];
this.response.body = { this.response.body = {
@@ -95,8 +95,8 @@ class ProblemCategoryHandler extends ProblemHandler {
); );
} }
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
[category, null, true], [category, null, true],
]; ];
this.response.body = { this.response.body = {
@@ -119,11 +119,9 @@ class ProblemRandomHandler extends ProblemHandler {
class ProblemDetailHandler extends ProblemHandler { class ProblemDetailHandler extends ProblemHandler {
async _prepare({ domainId, pid }) { async _prepare({ domainId, pid }) {
this.response.template = 'problem_detail.html'; this.response.template = 'problem_detail.html';
this.uid = this.user._id;
this.pid = pid;
if (pid) { if (pid) {
this.pdoc = await problem.get(domainId, pid, this.uid); this.pdoc = await problem.get(domainId, pid, this.user._id);
if (this.pdoc.hidden && this.pdoc.owner !== this.uid) { if (this.pdoc.hidden && this.pdoc.owner !== this.user._id) {
this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN); this.checkPerm(PERM_VIEW_PROBLEM_HIDDEN);
} }
if (this.pdoc) this.udoc = await user.getById(domainId, this.pdoc.owner); if (this.pdoc) this.udoc = await user.getById(domainId, this.pdoc.owner);
@@ -137,8 +135,8 @@ class ProblemDetailHandler extends ProblemHandler {
async get() { async get() {
this.response.body.path = [ this.response.body.path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, null, true], [this.pdoc.title, null, true],
]; ];
} }
@@ -149,17 +147,17 @@ class ProblemSubmitHandler extends ProblemDetailHandler {
this.checkPerm(PERM_SUBMIT_PROBLEM); this.checkPerm(PERM_SUBMIT_PROBLEM);
} }
async get({ domainId }) { async get({ domainId, pid }) {
this.response.template = 'problem_submit.html'; this.response.template = 'problem_submit.html';
const rdocs = await record.getUserInProblemMulti(domainId, this.uid, this.pdoc.docId) const rdocs = await record.getUserInProblemMulti(domainId, this.user._id, this.pdoc.docId)
.sort({ _id: -1 }) .sort({ _id: -1 })
.limit(10) .limit(10)
.toArray(); .toArray();
this.response.body = { this.response.body = {
path: [ path: [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, `/p/${this.pid}`, true], [this.pdoc.title, 'problem_detail', { pid }, true],
['problem_submit', null], ['problem_submit', null],
], ],
pdoc: this.pdoc, pdoc: this.pdoc,
@@ -172,7 +170,7 @@ class ProblemSubmitHandler extends ProblemDetailHandler {
async post({ domainId }) { async post({ domainId }) {
const { lang, code } = this.request.body; const { lang, code } = this.request.body;
const rid = await record.add(domainId, { const rid = await record.add(domainId, {
uid: this.uid, lang, code, pid: this.pdoc.docId, uid: this.user._id, lang, code, pid: this.pdoc.docId,
}); });
await Promise.all([ await Promise.all([
record.judge(domainId, rid), record.judge(domainId, rid),
@@ -189,7 +187,7 @@ class ProblemPretestHandler extends ProblemDetailHandler {
}) { }) {
this.limitRate('add_record', 60, 100); this.limitRate('add_record', 60, 100);
const rid = await record.add(domainId, { const rid = await record.add(domainId, {
uid: this.uid, lang, code, pid: this.pdoc.docId, input, uid: this.user._id, lang, code, pid: this.pdoc.docId, input,
}); });
await record.judge(domainId, rid); await record.judge(domainId, rid);
this.response.body = { rid }; this.response.body = { rid };
@@ -223,8 +221,8 @@ class ProblemStatisticsHandler extends ProblemDetailHandler {
async get({ domainId }) { async get({ domainId }) {
const udoc = await user.getById(domainId, this.pdoc.owner); const udoc = await user.getById(domainId, this.pdoc.owner);
const path = [ const path = [
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, `/p/${this.pdoc.pid}`, true], [this.pdoc.title, 'problem_detail', { pid: this.pdoc.pid }, true],
['problem_statistics', null], ['problem_statistics', null],
]; ];
this.response.template = 'problem_statistics.html'; this.response.template = 'problem_statistics.html';
@@ -234,17 +232,17 @@ class ProblemStatisticsHandler extends ProblemDetailHandler {
class ProblemManageHandler extends ProblemDetailHandler { class ProblemManageHandler extends ProblemDetailHandler {
async prepare() { async prepare() {
if (this.pdoc.owner !== this.uid) this.checkPerm(PERM_EDIT_PROBLEM); if (this.pdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_PROBLEM);
} }
} }
class ProblemSettingsHandler extends ProblemManageHandler { class ProblemSettingsHandler extends ProblemManageHandler {
async get() { async get({ pid }) {
this.response.template = 'problem_settings.html'; this.response.template = 'problem_settings.html';
this.response.body.path = [ this.response.body.path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, `/p/${this.pid}`, true], [this.pdoc.title, 'problem_detail', { pid }, true],
['problem_settings', null], ['problem_settings', null],
]; ];
} }
@@ -259,9 +257,9 @@ class ProblemEditHandler extends ProblemManageHandler {
async get({ pid }) { async get({ pid }) {
this.response.template = 'problem_edit.html'; this.response.template = 'problem_edit.html';
this.response.body.path = [ this.response.body.path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, `/p/${pid}`, true], [this.pdoc.title, 'problem_detail', { pid }, true],
['problem_edit', null], ['problem_edit', null],
]; ];
this.response.body.page_name = 'problem_edit'; this.response.body.page_name = 'problem_edit';
@@ -302,7 +300,7 @@ class ProblemDataUploadHandler extends ProblemManageHandler {
class ProblemDataDownloadHandler extends ProblemDetailHandler { class ProblemDataDownloadHandler extends ProblemDetailHandler {
async get({ pid }) { async get({ pid }) {
if (this.uid !== this.pdoc.owner) this.checkPerm([PERM_READ_PROBLEM_DATA, PERM_JUDGE]); if (this.user._id !== this.pdoc.owner) this.checkPerm([PERM_READ_PROBLEM_DATA, PERM_JUDGE]);
if (!this.pdoc.data) throw new ProblemDataNotFoundError(pid); if (!this.pdoc.data) throw new ProblemDataNotFoundError(pid);
else if (typeof this.pdoc.data === 'string') [, this.response.redirect] = this.pdoc.data.split('from:'); else if (typeof this.pdoc.data === 'string') [, this.response.redirect] = this.pdoc.data.split('from:');
this.response.redirect = file.url(this.pdoc.data, this.pdoc.title); this.response.redirect = file.url(this.pdoc.data, this.pdoc.title);
@@ -328,10 +326,10 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
} }
} }
const udict = await user.getList(uids); const udict = await user.getList(uids);
const pssdict = solution.getListStatus(domainId, docids, this.uid); const pssdict = solution.getListStatus(domainId, docids, this.user._id);
const path = [ const path = [
['problem_main', '/p'], ['problem_main', 'problem_main'],
[this.pdoc.title, `/p/${this.pdoc.pid}`, true], [this.pdoc.title, 'problem_detail', { pid: this.pdoc.pid }, true],
['problem_solution', null], ['problem_solution', null],
]; ];
this.response.body = { this.response.body = {
@@ -345,19 +343,19 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
async postSubmit({ domainId, content }) { async postSubmit({ domainId, content }) {
this.checkPerm(PERM_CREATE_PROBLEM_SOLUTION); this.checkPerm(PERM_CREATE_PROBLEM_SOLUTION);
await solution.add(domainId, this.pdoc.docId, this.uid, content); await solution.add(domainId, this.pdoc.docId, this.user._id, content);
this.back(); this.back();
} }
async postEditSolution({ domainId, content }) { async postEditSolution({ domainId, content }) {
if (this.psdoc.owner !== this.uid) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION); if (this.psdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION);
this.psdoc = await solution.edit(domainId, this.psdoc.docId, content); this.psdoc = await solution.edit(domainId, this.psdoc.docId, content);
this.ctx.body.psdoc = this.psdoc; this.ctx.body.psdoc = this.psdoc;
this.back(); this.back();
} }
async postDeleteSolution({ domainId }) { async postDeleteSolution({ domainId }) {
if (this.psdoc.owner !== this.uid) this.checkPerm(PERM_DELETE_PROBLEM_SOLUTION); if (this.psdoc.owner !== this.user._id) this.checkPerm(PERM_DELETE_PROBLEM_SOLUTION);
await solution.del(domainId, this.psdoc.docId); await solution.del(domainId, this.psdoc.docId);
this.back(); this.back();
} }
@@ -365,7 +363,7 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
async postReply({ domainId, psid, content }) { async postReply({ domainId, psid, content }) {
this.checkPerm(PERM_REPLY_PROBLEM_SOLUTION); this.checkPerm(PERM_REPLY_PROBLEM_SOLUTION);
const psdoc = await solution.get(domainId, psid); const psdoc = await solution.get(domainId, psid);
await solution.reply(domainId, psdoc.docId, this.uid, content); await solution.reply(domainId, psdoc.docId, this.user._id, content);
} }
async postEditReply({ async postEditReply({
@@ -373,26 +371,26 @@ class ProblemSolutionHandler extends ProblemDetailHandler {
}) { }) {
const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid); const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid);
if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(psid); if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(psid);
if (psrdoc.owner !== this.uid) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION_REPLY); if (psrdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION_REPLY);
await solution.editReply(domainId, psid, psrid, content); await solution.editReply(domainId, psid, psrid, content);
} }
async postDeleteReply({ domainId, psid, psrid }) { async postDeleteReply({ domainId, psid, psrid }) {
const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid); const [psdoc, psrdoc] = await solution.getReply(domainId, psid, psrid);
if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(psid); if ((!psdoc) || psdoc.pid !== this.pdoc.docId) throw new SolutionNotFoundError(psid);
if (psrdoc.owner !== this.uid) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION_REPLY); if (psrdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_PROBLEM_SOLUTION_REPLY);
await solution.delReply(domainId, psid, psrid); await solution.delReply(domainId, psid, psrid);
this.back(); this.back();
} }
async postUpvote({ domainId }) { async postUpvote({ domainId }) {
const [psdoc, pssdoc] = await solution.vote(domainId, this.psdoc.docId, this.uid, 1); const [psdoc, pssdoc] = await solution.vote(domainId, this.psdoc.docId, this.user._id, 1);
this.response.body = { vote: psdoc.vote, user_vote: pssdoc.vote }; this.response.body = { vote: psdoc.vote, user_vote: pssdoc.vote };
this.back(); this.back();
} }
async postDownvote({ domainId }) { async postDownvote({ domainId }) {
const [psdoc, pssdoc] = await solution.vote(domainId, this.psdoc.docId, this.uid, -1); const [psdoc, pssdoc] = await solution.vote(domainId, this.psdoc.docId, this.user._id, -1);
this.response.body = { vote: psdoc.vote, user_vote: pssdoc.vote }; this.response.body = { vote: psdoc.vote, user_vote: pssdoc.vote };
this.back(); this.back();
} }
@@ -423,8 +421,8 @@ class ProblemCreateHandler extends Handler {
this.checkPerm(PERM_CREATE_PROBLEM); this.checkPerm(PERM_CREATE_PROBLEM);
this.response.body = { this.response.body = {
path: [ path: [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/p'], ['problem_main', 'problem_main'],
['problem_create', null], ['problem_create', null],
], ],
page_name: 'problem_create', page_name: 'problem_create',
+2 -2
View File
@@ -31,7 +31,7 @@ class RecordListHandler extends RecordHandler {
problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), false), problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), false),
]); ]);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['record_main', null], ['record_main', null],
]; ];
this.response.body = { this.response.body = {
@@ -64,7 +64,7 @@ class RecordDetailHandler extends RecordHandler {
]); ]);
this.response.body = { this.response.body = {
path: [ path: [
['Hydro', '/'], ['Hydro', 'homepage'],
['record_detail', null], ['record_detail', null],
], ],
udoc, udoc,
+4 -4
View File
@@ -16,8 +16,8 @@ class SystemHandler extends Handler {
class SystemDashboardHandler extends SystemHandler { class SystemDashboardHandler extends SystemHandler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['manage', '/manage'], ['manage', null],
['manage_dashboard', null], ['manage_dashboard', null],
]; ];
this.response.template = 'manage_dashboard.html'; this.response.template = 'manage_dashboard.html';
@@ -29,8 +29,8 @@ class SystemModuleHandler extends SystemHandler {
async get() { async get() {
const installed = await hpm.getInstalled(); const installed = await hpm.getInstalled();
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['manage', '/manage'], ['manage', null],
['manage_module', null], ['manage_module', null],
]; ];
this.response.body = { installed, active: loader.active, path }; this.response.body = { installed, active: loader.active, path };
+9 -7
View File
@@ -87,7 +87,7 @@ class TrainingMainHandler extends TrainingHandler {
} }
for (const tdoc in tdocs) tdict[tdoc.docId] = tdoc; for (const tdoc in tdocs) tdict[tdoc.docId] = tdoc;
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['training_main', null], ['training_main', null],
]; ];
this.response.template = 'training_main.html'; this.response.template = 'training_main.html';
@@ -139,8 +139,9 @@ class TrainingDetailHandler extends TrainingHandler {
done: doneNids.size === tdoc.dag.length, done: doneNids.size === tdoc.dag.length,
}); });
const path = [ const path = [
['Hydro', 'homepage'],
['training_main', 'training_main'], ['training_main', 'training_main'],
[tdoc.title, null, true], [tdoc.title, null, null, true],
]; ];
this.response.template = 'training_detail.html'; this.response.template = 'training_detail.html';
this.response.body = { this.response.body = {
@@ -159,9 +160,9 @@ class TrainingDetailHandler extends TrainingHandler {
class TrainingCreateHandler extends TrainingHandler { class TrainingCreateHandler extends TrainingHandler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['problem_main', '/t'], ['training_main', 'training_main'],
['problem_create', null], ['training_create', null],
]; ];
this.response.template = 'training_edit.html'; this.response.template = 'training_edit.html';
this.response.body = { page_name: 'training_create', path }; this.response.body = { page_name: 'training_create', path };
@@ -201,8 +202,9 @@ class TrainingEditHandler extends TrainingHandler {
if (tdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_TRAINING); if (tdoc.owner !== this.user._id) this.checkPerm(PERM_EDIT_TRAINING);
const dag = JSON.stringify(tdoc.dag, null, 2); const dag = JSON.stringify(tdoc.dag, null, 2);
const path = [ const path = [
['training_main', '/t'], ['Hydro', 'homepage'],
[tdoc.title, `/t/${tdoc.docId}`, true], ['training_main', 'training_main'],
[tdoc.title, 'training_detail', { tid: tdoc.docId }, true],
['training_edit', null], ['training_edit', null],
]; ];
this.response.template = 'training_edit.html'; this.response.template = 'training_edit.html';
+2 -2
View File
@@ -6,8 +6,8 @@ class WikiHandler extends Handler {
if (!global.Hydro.wiki[page]) throw new NotFoundError(page); if (!global.Hydro.wiki[page]) throw new NotFoundError(page);
const contents = global.Hydro.wiki[page]; const contents = global.Hydro.wiki[page];
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['wiki', '/wiki'], ['wiki', null],
[`wiki_${page}`, null], [`wiki_${page}`, null],
]; ];
this.response.body = { this.response.body = {
+2 -2
View File
@@ -13,7 +13,7 @@ class PasteShowHandler extends Handler {
async get({ docId }) { async get({ docId }) {
const doc = await pastebin.get(docId); const doc = await pastebin.get(docId);
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['paste_show', null], ['paste_show', null],
[doc.title, null, true], [doc.title, null, true],
]; ];
@@ -29,7 +29,7 @@ class PasteCreateHandler extends Handler {
async get() { async get() {
const path = [ const path = [
['Hydro', '/'], ['Hydro', 'homepage'],
['paste_create', null], ['paste_create', null],
]; ];
this.response.body = { path }; this.response.body = { path };
+1 -1
View File
@@ -5,7 +5,7 @@
<div class="media__body"> <div class="media__body">
<div class="location-path"> <div class="location-path">
{% for c in path %} {% for c in path %}
/ {% if loop.index < path.length %}<a href="{{ c[1]|default('#') }}">{{ c[0] if c[2] else _(c[0]) }}</a>{% endif %} / {% if loop.index < path.length %}<a href="{{ url(c[1], c[2])|default('#') }}">{{ c[0] if c[3] else _(c[0]) }}</a>{% endif %}
{%- endfor %} {%- endfor %}
</div> </div>
<h1 class="location-current" data-emoji-enabled>{{ path[path.length - 1][0] if path[path.length - 1][2] else _(path[path.length - 1][0]) }}</h1> <h1 class="location-current" data-emoji-enabled>{{ path[path.length - 1][0] if path[path.length - 1][2] else _(path[path.length - 1][0]) }}</h1>