mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
Merge branch 'master' into remove-union
This commit is contained in:
7 files changed
+60
-68
No files matched your search
@@ -30,13 +30,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<li>{{ _('{0} views').format(ddoc.views) }}</li>
|
<li>{{ _('{0} views').format(ddoc.views) }}</li>
|
||||||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
|
||||||
<li><form class="form--inline" method="post">
|
<li data-star="{{ dsdoc['star'] }}"></li>
|
||||||
<input type="hidden" name="operation" value="{% if not dsdoc['star'] %}star{% else %}unstar{% endif %}">
|
|
||||||
<button class="star{% if dsdoc['star'] %} activated{% endif %}" type="submit">
|
|
||||||
<span class="starred--hide"><span class="icon icon-star--outline"></span> {{ _('Star') }}</span>
|
|
||||||
<span class="starred--show"><span class="icon icon-star"></span> {{ _('Unstar') }}</span>
|
|
||||||
</button>
|
|
||||||
</form></li>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li><a href="{{ url('wiki_help', anchor='contact') }}">
|
<li><a href="{{ url('wiki_help', anchor='contact') }}">
|
||||||
<span class="icon icon-warning"></span> {{ _('Report') }}
|
<span class="icon icon-warning"></span> {{ _('Report') }}
|
||||||
|
|||||||
@@ -338,15 +338,10 @@ class DiscussionDetailHandler extends DiscussionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@param('did', Types.ObjectId)
|
@param('did', Types.ObjectId)
|
||||||
async postStar(domainId: string, did: ObjectId) {
|
@param('star', Types.Boolean)
|
||||||
await discussion.setStar(domainId, did, this.user._id, true);
|
async postStar(domainId: string, did: ObjectId, star = false) {
|
||||||
this.back({ star: true });
|
await discussion.setStar(domainId, did, this.user._id, star);
|
||||||
}
|
this.back({ star });
|
||||||
|
|
||||||
@param('did', Types.ObjectId)
|
|
||||||
async postUnstar(domainId: string, did: ObjectId) {
|
|
||||||
await discussion.setStar(domainId, did, this.user._id, false);
|
|
||||||
this.back({ star: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -352,28 +352,43 @@ class HomeSecurityHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function set(s: Setting, key: string, value: any) {
|
function set(s: Setting, key: string, value: any) {
|
||||||
if (s) {
|
if (!s) return undefined;
|
||||||
if (s.family === 'setting_storage') return undefined;
|
if (s.family === 'setting_storage') return undefined;
|
||||||
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
if (s.flag & setting.FLAG_DISABLED) return undefined;
|
||||||
if ((s.flag & setting.FLAG_SECRET) && !value) return undefined;
|
if ((s.flag & setting.FLAG_SECRET) && !value) return undefined;
|
||||||
if (s.type === 'boolean') {
|
if (s.type === 'boolean') {
|
||||||
if (value === 'on') return true;
|
if (value === 'on') return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if (s.type === 'number') {
|
|
||||||
if (!Number.isSafeInteger(+value)) throw new ValidationError(key);
|
|
||||||
return +value;
|
|
||||||
}
|
|
||||||
if (s.subType === 'yaml') {
|
|
||||||
try {
|
|
||||||
yaml.load(value);
|
|
||||||
} catch (e) {
|
|
||||||
throw new ValidationError(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
return undefined;
|
if (s.type === 'number') {
|
||||||
|
if (!Number.isSafeInteger(+value)) throw new ValidationError(key);
|
||||||
|
return +value;
|
||||||
|
}
|
||||||
|
if (s.type === 'float') {
|
||||||
|
if (Number.isNaN(+value)) throw new ValidationError(key);
|
||||||
|
return +value;
|
||||||
|
}
|
||||||
|
if (['json', 'yaml', 'markdown', 'textarea'].includes(s.type)) {
|
||||||
|
if (!Types.Content[1](value)) throw new ValidationError(key);
|
||||||
|
}
|
||||||
|
if (s.type === 'text') {
|
||||||
|
if (!Types.String[1](value)) throw new ValidationError(key);
|
||||||
|
}
|
||||||
|
if (s.subType === 'yaml') {
|
||||||
|
try {
|
||||||
|
yaml.load(value);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s.subType === 'json') {
|
||||||
|
try {
|
||||||
|
JSON.parse(value);
|
||||||
|
} catch (e) {
|
||||||
|
throw new ValidationError(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HomeSettingsHandler extends Handler {
|
class HomeSettingsHandler extends Handler {
|
||||||
@@ -484,15 +499,11 @@ class HomeDomainHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@param('id', Types.String)
|
@param('id', Types.String)
|
||||||
async postStar(domainId: string, id: string) {
|
@param('star', Types.Boolean)
|
||||||
await user.setById(this.user._id, { pinnedDomains: [...this.user.pinnedDomains, id] });
|
async postStar({ }, id: string, star = false) {
|
||||||
this.back({ star: true });
|
if (star) await user.setById(this.user._id, { pinnedDomains: [...this.user.pinnedDomains, id] });
|
||||||
}
|
else user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.filter((i) => i !== id) });
|
||||||
|
this.back({ star });
|
||||||
@param('id', Types.String)
|
|
||||||
async postUnstar(domainId: string, id: string) {
|
|
||||||
await user.setById(this.user._id, { pinnedDomains: this.user.pinnedDomains.filter((i) => i !== id) });
|
|
||||||
this.back({ star: false });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import { AutoloadPage } from 'vj/misc/Page';
|
import { AutoloadPage } from 'vj/misc/Page';
|
||||||
import { request, tpl } from 'vj/utils';
|
import { i18n, request, tpl } from 'vj/utils';
|
||||||
|
|
||||||
function setStarButtonState($starButton: JQuery<any>, star: boolean) {
|
function setStarButtonState($starButton: JQuery<any>, star: boolean) {
|
||||||
if (star) {
|
if (star) {
|
||||||
@@ -14,18 +14,17 @@ const starPage = new AutoloadPage('starPage', () => {
|
|||||||
function render(container) {
|
function render(container) {
|
||||||
const eles = $(container).find('[data-star]');
|
const eles = $(container).find('[data-star]');
|
||||||
for (const el of eles) {
|
for (const el of eles) {
|
||||||
if ($(el).find('.star-form')) continue;
|
if ($(el).find('.star-form').length) continue;
|
||||||
const pid = $(el).closest('[data-pid]').data('pid');
|
const action = $(el).closest('[data-star-action]').data('star-action');
|
||||||
const star = $(el).data('star') === 'true' ? 1 : 0;
|
const star = ['true', true].includes($(el).data('star')) ? 1 : 0;
|
||||||
if (!pid) continue;
|
$(tpl`<form class="star-form form--inline" action="${action}" method="post">
|
||||||
$(tpl`<form class="form--inline" action="/d/${UiContext.domain._id}/p/${pid}" method="post">
|
|
||||||
<input type="hidden" name="operation" value="star">
|
<input type="hidden" name="operation" value="star">
|
||||||
<input type="hidden" name="star" value="${star ? 'false' : 'true'}">
|
<input type="hidden" name="star" value="${star ? 'false' : 'true'}">
|
||||||
<button class="star${star ? ' activated' : ''}" type="submit">
|
<button class="star${star ? ' activated' : ''}" type="submit">
|
||||||
<span class="starred--hide"><span class="icon icon-star--outline" data-tooltip="{{ _('Star') }}"></span></span>
|
<span class="starred--hide"><span class="icon icon-star--outline" data-tooltip="${i18n('Star')}"></span></span>
|
||||||
<span class="starred--show"><span class="icon icon-star" data-tooltip="{{ _('Unstar') }}"></span></span>
|
<span class="starred--show"><span class="icon icon-star" data-tooltip="${i18n('Unstar')}"></span></span>
|
||||||
</button>
|
</button>
|
||||||
</form>`);
|
</form>`).prependTo($(el));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,9 +38,10 @@ const starPage = new AutoloadPage('starPage', () => {
|
|||||||
const currentState = $button.hasClass('activated');
|
const currentState = $button.hasClass('activated');
|
||||||
const $form = $button.closest('form');
|
const $form = $button.closest('form');
|
||||||
const $op = $form.find('[name="operation"]');
|
const $op = $form.find('[name="operation"]');
|
||||||
if (!['star', 'unstar'].includes($op.val() as any)) return;
|
const $star = $form.find('[name="star"]');
|
||||||
|
if ($op.val() !== 'star') return;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
$op.val(currentState ? 'unstar' : 'star');
|
$star.val(currentState ? 'false' : 'true');
|
||||||
setStarButtonState($button, !currentState);
|
setStarButtonState($button, !currentState);
|
||||||
request
|
request
|
||||||
.post($form.attr('action'), $form)
|
.post($form.attr('action'), $form)
|
||||||
|
|||||||
@@ -32,16 +32,8 @@
|
|||||||
<td class="col--icon">
|
<td class="col--icon">
|
||||||
<img src="{{ avatarUrl(ddoc.avatar, 32) }}" width="32" height="32">
|
<img src="{{ avatarUrl(ddoc.avatar, 32) }}" width="32" height="32">
|
||||||
</td>
|
</td>
|
||||||
<td class="col--name">
|
|
||||||
<form class="form--inline" method="post">
|
|
||||||
<input type="hidden" name="id" value="{{ ddoc['_id'] }}">
|
|
||||||
{% set _show = handler.user.pinnedDomains.includes(ddoc._id) %}
|
{% set _show = handler.user.pinnedDomains.includes(ddoc._id) %}
|
||||||
<input type="hidden" name="operation" value="{{ "unstar" if _show else "star" }}">
|
<td class="col--name" data-action="?id={{ ddoc['_id'] }}" data-star="{{ _show }}">
|
||||||
<button class="star{% if _show %} activated{% endif %}" type="submit">
|
|
||||||
<span class="starred--hide"><span class="icon icon-star--outline" data-tooltip="{{ _('Star') }}"></span></span>
|
|
||||||
<span class="starred--show"><span class="icon icon-star" data-tooltip="{{ _('Unstar') }}"></span></span>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
{{ ddoc['name'] }} ({{ ddoc['_id'] }})
|
{{ ddoc['name'] }} ({{ ddoc['_id'] }})
|
||||||
</td>
|
</td>
|
||||||
<td class="col--role">
|
<td class="col--role">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section__body typo no-media col--problem-name">
|
<div class="section__body typo no-media col--problem-name">
|
||||||
{%- for pdoc in pdocs -%}
|
{%- for pdoc in pdocs -%}
|
||||||
<p data-pid="{{ pdoc.docId }}" data-star="true">
|
<p data-action="{{ url('problem_detail', pid=pdoc.docId) }}" data-star="true">
|
||||||
{{ problem.render_problem_title(pdoc, show_tags=false, show_invisible_flag=false) }}
|
{{ problem.render_problem_title(pdoc, show_tags=false, show_invisible_flag=false) }}
|
||||||
</p>
|
</p>
|
||||||
{%- endfor -%}
|
{%- endfor -%}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
<td class="col--status record-status--border edit-mode-hide"></td>
|
<td class="col--status record-status--border edit-mode-hide"></td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<td class="col--name col--problem-name" {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} data-star="{{ psdoc.star }}"{% endif %}>
|
<td class="col--name col--problem-name" data-action="{{ url('problem_detail', docId=pdoc.docId) }}" {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} data-star="{{ psdoc.star }}"{% endif %}>
|
||||||
{{ problem.render_problem_title(pdoc) }}
|
{{ problem.render_problem_title(pdoc) }}
|
||||||
</td>
|
</td>
|
||||||
<td class="col--ac-tried">{{ pdoc.nAccept }} / {{ pdoc.nSubmit }}</td>
|
<td class="col--ac-tried">{{ pdoc.nAccept }} / {{ pdoc.nSubmit }}</td>
|
||||||
|
|||||||
Reference in new issue
Block a user