-
-
Notifications
You must be signed in to change notification settings - Fork 403
ui: 为训练和比赛添加了带小标签的标题栏 #1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ui: 为训练和比赛添加了带小标签的标题栏 #1045
Conversation
ui: Added a small label to the title bar for training and competition
ui: Added a small label to the title bar for training and competition
WalkthroughAdds header sections to homework_detail.html and training_detail.html. For homework: inserts a left-column header showing tdoc.title and tags for Status (model.contest.statusText(tdoc)), Problems (pids length), Open Since (beginAt), and a deadline label that switches between Hard Deadline and Deadline based on model.contest.isExtended(tdoc) or model.contest.isDone(tdoc), displaying endAt or penaltySince via datetimeSpan. For training: adds a top header with tdoc.title and tags for status (based on PRIV_USER_PROFILE and tsdoc enroll/done), progress percentage, attend count, and creator. Adds a notice-rich body area conditioned on privileges/enrollment and renders tdoc.description. Mixed tsdoc['enroll]/tsdoc.enroll usage introduced. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/ui-default/templates/training_detail.html (1)
117-121
: Deduplicate status/progress logic with safe math and consistent access.Repeat of header logic; apply the same consistency and zero-division guard.
- {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} - <dt>{{ _('Status') }}</dt><dd>{% if tsdoc['enroll'] %}{{ _('Completed' if tsdoc['done'] else 'In Progress') }}{% else %}{{ _('Not Enrolled') }}{% endif %}</dd> - {% endif %} - {% if tsdoc['enroll'] %} - <dt>{{ _('Progress') }}</dt><dd>{{ _('Completed') }} {{ (100 * tsdoc['donePids']|length / pids|length)|round|int }}%</dd> - {% endif %} + {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} + <dt>{{ _('Status') }}</dt> + <dd>{% if tsdoc.enroll %}{{ _('Completed' if tsdoc.done else 'In Progress') }}{% else %}{{ _('Not Enrolled') }}{% endif %}</dd> + {% endif %} + {% if tsdoc.enroll %} + {% set total = tdoc.pids|length %} + {% set done = tsdoc.donePids|length %} + <dt>{{ _('Progress') }}</dt> + <dd>{{ _('Completed') }} {{ (100 * done / total)|round|int if total > 0 else 0 }}%</dd> + {% endif %}
🧹 Nitpick comments (6)
packages/ui-default/templates/homework_detail.html (1)
9-25
: Move meta tags out of section__header; keep BEM semantics consistent.Placing section__body inside section__header is atypical for this codebase’s section component and can break layout/styling. Header should contain only the title; body sits as a sibling.
Additionally, access style is mixed (tdoc.pids vs tdoc['beginAt']). Pick one (prefer dot notation throughout) for consistency and fewer surprises.
Apply:
- <div class="section"> - <div class="section__header"> - <h1 class="section__title">{{ tdoc.title }}</h1> - <div class="section__body"> + <div class="section"> + <div class="section__header"> + <h1 class="section__title">{{ tdoc.title }}</h1> + </div> + <div class="section__body"> <span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Status') }}: {{ _(model.contest.statusText(tdoc)) }}</span> - <span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Problems') }}: {{ tdoc.pids|length }}</span> - <span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Open Since') }}: {{ datetimeSpan(tdoc['beginAt'])|safe }}</span> + <span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Problems') }}: {{ tdoc.pids|length }}</span> + <span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Open Since') }}: {{ datetimeSpan(tdoc.beginAt)|safe }}</span> <span class="bp6-tag bp6-large bp6-minimal problem__tag-item"> - {% if model.contest.isExtended(tdoc) or model.contest.isDone(tdoc) %} - {{ _('Hard Deadline') }}: {{ datetimeSpan(tdoc['endAt'])|safe }} + {% if model.contest.isExtended(tdoc) or model.contest.isDone(tdoc) %} + {{ _('Hard Deadline') }}: {{ datetimeSpan(tdoc.endAt)|safe }} {% else %} - {{ _('Deadline') }}: {{ datetimeSpan(tdoc['penaltySince'])|safe }} + {{ _('Deadline') }}: {{ datetimeSpan(tdoc.penaltySince)|safe }} {% endif %} </span> - </div> - </div> + </div> + </div>packages/ui-default/templates/training_detail.html (5)
45-47
: Inline style uses invalid property; drop or replace with text-align.style="align: center" won’t have any effect. Either remove inline style or use text-align:center via a utility class.
- <div class="section__header" style="align: center"> + <div class="section__header"> <h1 class="section__title">{{ tdoc.title }}</h1> </div>
62-63
: Verify creator variable is in scope.user.render_inline(udoc, ...) assumes udoc refers to the training creator. In this template udoc is also used as a loop variable in the left sidebar and may be undefined here. Please confirm what variable represents the creator (e.g., creatorDoc/ownerDoc) and render that instead.
If you share the expected context variable name for the creator, I can propose the exact patch.
70-80
: Align tsdoc access style and notice key.
- Here you use tsdoc.enroll (dot), elsewhere tsdoc['enroll'] (bracket). Standardize.
- Ensure the translation key page.training_detail.invalid_when_not_enrolled exists; otherwise use a user-facing sentence already present in the project.
- {% elif not tsdoc.enroll %} + {% elif not tsdoc.enroll %} <blockquote class="typo note"> <p>{{ _('page.training_detail.invalid_when_not_enrolled') }}</p> </blockquote>Note: If the key is missing, consider:
{{ _('You need to enroll to access this training.') }}
90-99
: Unify enrollment check to dot style.Keep access consistent with earlier changes.
- {% if not tsdoc['enroll'] and handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} + {% if not tsdoc.enroll and handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
44-64
: DRY: consider extracting a reusable “meta header” partial for detail pages.You’ve implemented a neat small-label header in both homework and training. To keep things consistent and easier to evolve, consider a shared macro/partial (e.g., components/meta_header.html) that accepts title and an array of tag fragments/slots.
Also applies to: 70-80, 90-121
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/ui-default/templates/homework_detail.html
(2 hunks)packages/ui-default/templates/training_detail.html
(2 hunks)
🔇 Additional comments (1)
packages/ui-default/templates/homework_detail.html (1)
13-21
: Confirm statusText localization contract.If model.contest.statusText(tdoc) already returns a localized string, wrapping it in _() can lead to a no-op or wrong key lookup. If it returns a msgid, wrapping is correct. Please confirm and unify with other templates.
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item"> | ||
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} | ||
{{ _('Completed' if tsdoc['done'] else 'In Progress') if tsdoc['enroll'] else _('Not Enrolled') }} | ||
{% else %} | ||
{{ _('Status Unavailable') }} | ||
{% endif %} | ||
</span> | ||
{% if tsdoc['enroll'] %} | ||
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-progress"> | ||
{{ _('Completed') }} {{ (100 * tsdoc['donePids']|length / pids|length)|round|int }}% | ||
</span> | ||
{% endif %} | ||
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-user--multiple">{{ tdoc.attend|default(0) }} </span> | ||
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Created By') }}: {{ user.render_inline(udoc, badge=false) }}</span> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Unify tsdoc access and fix potential division-by-zero and undefined variable.
- Mixed tsdoc['...'] and tsdoc.... Use one style (prefer dot).
- Progress uses pids|length, which appears undefined in this template. Use tdoc.pids|length.
- Guard against zero problems to avoid division-by-zero at render time.
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item">
- {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
- {{ _('Completed' if tsdoc['done'] else 'In Progress') if tsdoc['enroll'] else _('Not Enrolled') }}
+ {% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %}
+ {{ _('Completed' if tsdoc.done else 'In Progress') if tsdoc.enroll else _('Not Enrolled') }}
{% else %}
{{ _('Status Unavailable') }}
{% endif %}
</span>
- {% if tsdoc['enroll'] %}
+ {% if tsdoc.enroll %}
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-progress">
- {{ _('Completed') }} {{ (100 * tsdoc['donePids']|length / pids|length)|round|int }}%
+ {# avoid division by zero #}
+ {% set total = tdoc.pids|length %}
+ {% set done = tsdoc.donePids|length %}
+ {{ _('Completed') }} {{ (100 * done / total)|round|int if total > 0 else 0 }}%
</span>
{% endif %}
- <span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-user--multiple">{{ tdoc.attend|default(0) }} </span>
+ <span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-user--multiple">{{ tdoc.attend|default(0) }}</span>
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item"> | |
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} | |
{{ _('Completed' if tsdoc['done'] else 'In Progress') if tsdoc['enroll'] else _('Not Enrolled') }} | |
{% else %} | |
{{ _('Status Unavailable') }} | |
{% endif %} | |
</span> | |
{% if tsdoc['enroll'] %} | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-progress"> | |
{{ _('Completed') }} {{ (100 * tsdoc['donePids']|length / pids|length)|round|int }}% | |
</span> | |
{% endif %} | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-user--multiple">{{ tdoc.attend|default(0) }} </span> | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Created By') }}: {{ user.render_inline(udoc, badge=false) }}</span> | |
</div> | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item"> | |
{% if handler.user.hasPriv(PRIV.PRIV_USER_PROFILE) %} | |
{{ _('Completed' if tsdoc.done else 'In Progress') if tsdoc.enroll else _('Not Enrolled') }} | |
{% else %} | |
{{ _('Status Unavailable') }} | |
{% endif %} | |
</span> | |
{% if tsdoc.enroll %} | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-progress"> | |
{# avoid division by zero #} | |
{% set total = tdoc.pids|length %} | |
{% set done = tsdoc.donePids|length %} | |
{{ _('Completed') }} {{ (100 * done / total)|round|int if total > 0 else 0 }}% | |
</span> | |
{% endif %} | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item icon icon-user--multiple">{{ tdoc.attend|default(0) }}</span> | |
<span class="bp6-tag bp6-large bp6-minimal problem__tag-item">{{ _('Created By') }}: {{ user.render_inline(udoc, badge=false) }}</span> | |
</div> |
🤖 Prompt for AI Agents
In packages/ui-default/templates/training_detail.html around lines 49 to 63,
standardize tsdoc access to dot notation (e.g. tsdoc.enroll, tsdoc.done instead
of tsdoc['...']), replace the undefined pids|length with tdoc.pids|length, and
avoid a division-by-zero by only rendering the progress percentage when
tdoc.pids|length > 0 (or by using a conditional that falls back to 0% when
length is zero); keep the existing rounding/int behavior for the percentage and
ensure you reference tsdoc.donePids|length for numerator.
为训练和比赛添加了带小标签的标题栏。我学艺不精,没找到关于自定义顶部导航栏的相关代码。。。
Added a small-label header for training and competitions. I'm still learning, so I haven't found any code examples for customizing the top navigation bar...
Summary by CodeRabbit