Show next scheduled sync time on every page
Exposes the scheduler's next_tick in the topbar via a safe Jinja helper (falls back to nothing if the scheduler isn't running yet), and converts the server-rendered UTC timestamp to the visitor's local time client-side so it reads correctly regardless of timezone. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,14 @@ router = APIRouter()
|
||||
templates = Jinja2Templates(directory=str(Path(__file__).resolve().parent / "templates"))
|
||||
|
||||
|
||||
def _next_sync_tick(request: Request):
|
||||
scheduler = getattr(request.app.state, "scheduler", None)
|
||||
return getattr(scheduler, "next_tick", None)
|
||||
|
||||
|
||||
templates.env.globals["next_sync_tick"] = _next_sync_tick
|
||||
|
||||
|
||||
def _get_user_or_404(repository: UserRepository, user_id: int) -> SyncUser:
|
||||
user = repository.get(user_id)
|
||||
if user is None:
|
||||
|
||||
10
app/web/static/app.js
Normal file
10
app/web/static/app.js
Normal file
@@ -0,0 +1,10 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll("time[data-utc]").forEach((el) => {
|
||||
const date = new Date(el.dataset.utc);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return;
|
||||
}
|
||||
el.textContent = date.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
|
||||
el.title = `${el.dataset.utc} (UTC)`;
|
||||
});
|
||||
});
|
||||
@@ -64,12 +64,36 @@ a:hover {
|
||||
border-radius: 7px;
|
||||
}
|
||||
|
||||
.topbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.25rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.topbar nav {
|
||||
display: flex;
|
||||
gap: 1.25rem;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.sync-status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
padding: 0.3rem 0.7rem;
|
||||
border-radius: 999px;
|
||||
background: var(--info-bg);
|
||||
color: var(--info);
|
||||
font-size: 0.78rem;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sync-status time {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
|
||||
@@ -9,19 +9,26 @@
|
||||
<link rel="shortcut icon" href="/static/favicon.ico">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
<script src="/static/app.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<span class="brand"><img src="/static/logo.png" alt="" class="brand-logo" width="28" height="28">MyWhoosh → Garmin Sync</span>
|
||||
<nav>
|
||||
{% if request.session.get('admin_authenticated') %}
|
||||
<a href="/">Dashboard</a>
|
||||
<a href="/system">System</a>
|
||||
<div class="topbar-right">
|
||||
<nav>
|
||||
{% if request.session.get('admin_authenticated') %}
|
||||
<a href="/">Dashboard</a>
|
||||
<a href="/system">System</a>
|
||||
{% endif %}
|
||||
{% if request.session.get('self_service_user_id') %}
|
||||
<a href="/account">My Account</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% set next_tick = next_sync_tick(request) %}
|
||||
{% if next_tick %}
|
||||
<span class="sync-status">Next sync: <time class="next-sync" datetime="{{ next_tick.isoformat() }}" data-utc="{{ next_tick.isoformat() }}">{{ next_tick.strftime('%Y-%m-%d %H:%M UTC') }}</time></span>
|
||||
{% endif %}
|
||||
{% if request.session.get('self_service_user_id') %}
|
||||
<a href="/account">My Account</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
<main class="container">
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user