core: feat: allow star problem

This commit is contained in:
undefined committed 2021-10-17 18:02:33 +08:00
1 parent f7f977293c
commit ef32ee3865
8 files changed
+63 -4

No files matched your search

+1
View File
@@ -720,6 +720,7 @@ Source type: 来源类型
Split View: 分屏预览
Star Topic: 收藏讨论
Star: 收藏
Starred Problems: 收藏的题目
Start at: 开始于
Statistics: 统计
Status is hidden: 状态已隐藏
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.39.28",
"version": "2.39.29",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+18
View File
@@ -95,6 +95,21 @@ class HomeHandler extends Handler {
return ['ranking', []];
}
async getStarredProblem(domainId: string, limit = 50) {
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) {
const psdocs = await ProblemModel.getMultiStatus(domainId, { uid: this.user._id, star: true })
.sort('_id', 1).limit(limit).toArray();
const psdict = {};
for (const psdoc of psdocs) psdict[psdoc.docId] = psdoc;
const pdict = await ProblemModel.getList(
domainId, psdocs.map((pdoc) => pdoc.docId), false,
);
const pdocs = Object.keys(pdict).filter((i) => +i).map((i) => pdict[i]);
return ['problem', pdocs, psdict];
}
return ['problem', [], {}];
}
async get({ domainId }) {
const homepageConfig = system.get('hydrooj.homepage');
const tasks = [];
@@ -104,6 +119,7 @@ class HomeHandler extends Handler {
if (!this[func]) continue;
tasks.push(this[func](domainId, +info[key]));
}
const [, pdocs, psdict] = await this.getStarredProblem(domainId);
const contents = await Promise.all(tasks);
const [udict, dodoc, vnodes] = await Promise.all([
user.getList(domainId, Array.from(this.uids)),
@@ -116,6 +132,8 @@ class HomeHandler extends Handler {
udict,
domain: dodoc,
vnodes,
pdocs,
psdict,
};
}
}
@@ -12,6 +12,7 @@ export default new AutoloadPage('media', async () => {
};
users.get().forEach((ele) => resolve(ele, { type: 'user', id: +$(ele).text() }));
$dom.find('.typo').get().forEach((el) => {
if (el.className.includes('no-media')) return;
$(el).find('a[href]').get().forEach((ele) => {
if ($(ele).parent().hasClass('user-profile-link')) return;
let target = $(ele).attr('href');
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.25.8",
"version": "4.25.9",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
+21 -1
View File
@@ -1,7 +1,7 @@
{% set no_path_section = true %}
{% set page_name = "homepage" %}
{% extends "layout/basic.html" %}
{% import "components/contest.html" as contest with context %}
{% import "components/problem.html" as problem with context %}
{% block content %}
<div class="row">
<div class="large-9 columns">
@@ -49,6 +49,26 @@
</div>
<div class="section__body typo" name="hitokoto"></div>
</div>
{% if pdocs.length %}
<div class="section side nojs--hide">
<div class="section__header">
<h1 class="section__title">{{ _('Starred Problems') }}</h1>
</div>
<div class="section__body typo no-media col--problem-name">
{%- for pdoc in pdocs -%}
<form class="form--inline" action="{{ url('problem_main') }}" method="post">
<input type="hidden" name="pid" value="{{ pdoc.docId }}">
<input type="hidden" name="operation" value="unstar">
<button class="star activated" 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>
{{ problem.render_problem_title(pdoc, show_tags=false, show_invisible_flag=false) }}<br/>
{%- endfor -%}
</div>
</div>
{% endif %}
{% if handler.user.hasPerm(perm.PERM_VIEW_DISCUSSION) %}
{% include 'partials/discussion_nodes_widget.html' %}
{% endif %}
@@ -59,6 +59,16 @@
{% endif %}
{% endif %}
<td class="col--name col--problem-name">
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
<form class="form--inline" action="{{ url('problem_main') }}" method="post">
<input type="hidden" name="pid" value="{{ pdoc.docId }}">
<input type="hidden" name="operation" value="{{ "star" if not psdoc.star else "unstar" }}">
<button class="star{% if psdoc.star %} 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>
{% endif %}
{{ problem.render_problem_title(pdoc) }}
</td>
<td class="col--tried">{{ pdoc.nSubmit }}</td>
@@ -1,4 +1,3 @@
{% set no_path_section = true %}
{% extends "layout/basic.html" %}
{% block content %}
<script>
@@ -35,6 +34,16 @@
<span class="record-status--text {{ model.builtin.STATUS_CODES[rdoc['status']] }}">{{ rdoc.score }}</span>
</a>
{% endif %}
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) and not tdoc %}
<form class="form--inline" action="{{ url('problem_main') }}" method="post">
<input type="hidden" name="pid" value="{{ pdoc.docId }}">
<input type="hidden" name="operation" value="{{ "star" if not psdoc.star else "unstar" }}">
<button class="star{% if psdoc.star %} 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>
{% endif %}
#{{ pdoc.pid|default(pdoc.docId) }}. {{ pdoc.title }}
</h1>
</div>