ui: 修复problem_create页面添加标签无效的问题

This commit is contained in:
undefined committed 2021-04-08 14:35:23 +08:00
1 parent 8a114abb55
commit 05968798fe
5 files changed
+29 -12

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ export default function (env = {}) {
context: root(), context: root(),
entry: { entry: {
hydro: './entry.js', hydro: './entry.js',
'theme.default': './theme/default.js', 'default.theme': './theme/default.js',
// 'theme.98': './theme/98.js', // 'theme.98': './theme/98.js',
}, },
output: { output: {
+19 -7
View File
@@ -4,10 +4,10 @@ const { join } = require('path');
const crypto = require('crypto'); const crypto = require('crypto');
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const { tmpdir } = require('os'); const { tmpdir } = require('os');
const bus = require('hydrooj/dist/service/bus');
const markdown = require('./backendlib/markdown.js'); const markdown = require('./backendlib/markdown.js');
const { bus } = global.Hydro.service; const { system, domain, user } = global.Hydro.model;
const { system, domain } = global.Hydro.model;
const { Route, Handler, UiContextBase } = global.Hydro.service.server; const { Route, Handler, UiContextBase } = global.Hydro.service.server;
class WikiHelpHandler extends Handler { class WikiHelpHandler extends Handler {
@@ -94,6 +94,13 @@ class LocaleHandler extends Handler {
} }
} }
class SetThemeHandler extends Handler {
async get({ theme }) {
await user.setById(this.user._id, { theme });
this.back();
}
}
class MarkdownHandler extends Handler { class MarkdownHandler extends Handler {
async post({ text, html = false, inline = false }) { async post({ text, html = false, inline = false }) {
this.response.body = inline this.response.body = inline
@@ -104,16 +111,20 @@ class MarkdownHandler extends Handler {
} }
} }
bus.on('app/started', () => { const getUrl = (files) => files.map((i) => {
const files = readdirSync(join(tmpdir(), 'hydro', 'public'));
const pages = files.filter((file) => file.endsWith('.page.js'));
UiContextBase.extraPages = pages.map((i) => {
const shasum = crypto.createHash('sha1'); const shasum = crypto.createHash('sha1');
const file = readFileSync(join(tmpdir(), 'hydro', 'public', i)); const file = readFileSync(join(tmpdir(), 'hydro', 'public', i));
shasum.update(file); shasum.update(file);
const hash = shasum.digest('hex').substr(0, 10); const hash = shasum.digest('hex').substr(0, 10);
return `/${i}?${hash}`; return `/${i}?${hash}`;
}); });
bus.on('app/started', () => {
const files = readdirSync(join(tmpdir(), 'hydro', 'public'));
const pages = files.filter((file) => file.endsWith('.page.js'));
const themes = files.filter((file) => file.endsWith('.theme.js'));
UiContextBase.extraPages = getUrl(pages);
UiContextBase.themes = getUrl(themes);
}); });
global.Hydro.handler.ui = async () => { global.Hydro.handler.ui = async () => {
@@ -121,6 +132,7 @@ global.Hydro.handler.ui = async () => {
Route('wiki_about', '/wiki/about', WikiAboutHandler); Route('wiki_about', '/wiki/about', WikiAboutHandler);
Route('ui_constants', '/ui-constants.js', UiConstantsHandler); Route('ui_constants', '/ui-constants.js', UiConstantsHandler);
Route('locale', '/locale/:id', LocaleHandler); Route('locale', '/locale/:id', LocaleHandler);
Route('set_theme', '/set_theme/:id', SetThemeHandler);
Route('ui_extracss', '/extra.css', UiSettingsHandler); Route('ui_extracss', '/extra.css', UiSettingsHandler);
Route('markdown', '/markdown', MarkdownHandler); Route('markdown', '/markdown', MarkdownHandler);
}; };
@@ -142,7 +142,7 @@ function buildCategoryFilter() {
}); });
} }
const page = new NamedPage('problem_edit', async () => { export default new NamedPage(['problem_create', 'problem_edit'], () => {
$(document).on('click', '[name="problem-sidebar__show-category"]', (ev) => { $(document).on('click', '[name="problem-sidebar__show-category"]', (ev) => {
$(ev.currentTarget).hide(); $(ev.currentTarget).hide();
$('[name="problem-sidebar__categories"]').show(); $('[name="problem-sidebar__categories"]').show();
@@ -171,5 +171,3 @@ const page = new NamedPage('problem_edit', async () => {
buildCategoryFilter(); buildCategoryFilter();
parseCategorySelection(); parseCategorySelection();
}); });
export default page;
@@ -26,7 +26,7 @@
<meta property="og:url" content="{{ handler.ctx.request.href }}" /> <meta property="og:url" content="{{ handler.ctx.request.href }}" />
<meta property="og:image" content="{{ static_url('favicon-96x96.png') }}" /> <meta property="og:image" content="{{ static_url('favicon-96x96.png') }}" />
{% endblock %} {% endblock %}
<link rel="stylesheet" media="all" href="{{ static_url('theme.' + handler.user.theme|default('default') + '.css') }}"> <link rel="stylesheet" media="all" href="{{ static_url(handler.user.theme|default('default') + '.theme.js') }}">
<link rel="stylesheet" media="all" href="{{ url('ui_extracss') }}"> <link rel="stylesheet" media="all" href="{{ url('ui_extracss') }}">
<title>{{ handler.renderTitle(page_name) }}</title> <title>{{ handler.renderTitle(page_name) }}</title>
{% if not isIE(handler.request.headers['user-agent']) %} {% if not isIE(handler.request.headers['user-agent']) %}
@@ -57,6 +57,13 @@
<li class="menu__item"><a class="menu__link" href="{{ url('switch_language', lang=k) }}">{{ v }}</a></li> <li class="menu__item"><a class="menu__link" href="{{ url('switch_language', lang=k) }}">{{ v }}</a></li>
{%- endfor -%} {%- endfor -%}
</ol> </ol>
<li class="footer__extra-link-item" data-dropdown-target="#menu-footer-theme">
<span><span class="icon icon-global"></span> Theme <span class="icon icon-expand_less"></span></span>
<ol class="dropdown-target menu" id="menu-footer-theme">
{%- for k in UiContext.themes -%}
<li class="menu__item"><a class="menu__link" href="{{ url('set_theme', theme=k) }}">{{ k }}</a></li>
{%- endfor -%}
</ol>
</li> </li>
</ol> </ol>
</div> </div>