Skip to content

Conversation

Lirzh
Copy link

@Lirzh Lirzh commented Aug 24, 2025

为训练和比赛添加了带小标签的标题栏。我学艺不精,没找到关于自定义顶部导航栏的相关代码。。。

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

  • New Features
    • Homework detail page: Added a new header showing title, status, problem count, “Open Since,” and Deadline/Hard Deadline with formatted dates.
    • Training detail page: Added a new header with title and status (Completed/In Progress/Not Enrolled or unavailable), progress percentage for enrolled users, attendance count, and creator info.
    • Training detail page: Added notices prompting login or enrollment when applicable, and now renders the training description content prominently.

Lirzh added 2 commits August 24, 2025 14:17
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
Copy link

coderabbitai bot commented Aug 24, 2025

Walkthrough

Adds 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
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7f25b0c and 64b6569.

📒 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.

Comment on lines +49 to +63
<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>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

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.

Suggested change
<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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant