Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 29 additions & 25 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
flex-wrap: wrap;
}

.auth-status {
max-width: 260px;
overflow: hidden;
text-overflow: ellipsis;
}

.shell {
width: min(1160px, calc(100vw - 36px));
margin: 0 auto;
Expand Down Expand Up @@ -526,7 +532,9 @@ <h1 data-i18n="appTitle">策略切换</h1>
<p data-i18n="appSubtitle">选平台、目标账号和策略,一次执行完成切换。</p>
</div>
<div class="top-actions">
<a class="btn" id="account-link" href="https://github.com/QuantStrategyLab/QuantRuntimeSettings/tree/main/web/strategy-switch-console" data-i18n="loginManage">登录管理</a>
<span class="pill ready auth-status" id="auth-status" hidden></span>
<a class="btn" id="login-link" href="/login" hidden data-i18n="login">登录</a>
<button class="btn" id="logout-button" type="button" hidden data-i18n="logout">退出</button>
Comment on lines +535 to +537

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve hidden auth controls

The new auth controls rely on the hidden attribute, but these elements also match .pill/.btn, whose author CSS sets display: inline-flex; that can override the browser's [hidden] display rule, so the later *.hidden = ... toggles do not reliably hide them. In the static/GitHub Pages fallback this leaves Sign in/Sign out controls visible even though /api/session is unavailable, and on the Worker the inactive auth action can appear beside the active one. Add an explicit [hidden] { display: none !important; } rule or toggle a class that wins.

Useful? React with 👍 / 👎.

</div>
</header>

Expand Down Expand Up @@ -659,7 +667,9 @@ <h2 data-i18n="summary">切换摘要</h2>
zh: {
appTitle: "策略切换",
appSubtitle: "选平台、目标账号和策略,一次执行完成切换。",
loginManage: "登录管理",
login: "登录",
logout: "退出",
signedInAs: "已登录 {login}",
activePlatform: "当前平台",
account: "目标账号",
strategy: "策略",
Expand Down Expand Up @@ -694,7 +704,9 @@ <h2 data-i18n="summary">切换摘要</h2>
en: {
appTitle: "Strategy Switch",
appSubtitle: "Pick platform, target account, and strategy. One action switches everything.",
loginManage: "Login Management",
login: "Sign in",
logout: "Sign out",
signedInAs: "Signed in as {login}",
activePlatform: "Active Platform",
account: "Target account",
strategy: "Strategy",
Expand Down Expand Up @@ -903,24 +915,18 @@ <h2 data-i18n="summary">切换摘要</h2>
}

function renderAuth() {
const accountLink = el("account-link");
if (!state.auth.available) {
accountLink.href = "https://github.com/QuantStrategyLab/QuantRuntimeSettings/tree/main/web/strategy-switch-console";
accountLink.dataset.action = "setup";
accountLink.textContent = t("loginManage");
} else if (state.auth.admin) {
accountLink.href = "/admin";
accountLink.dataset.action = "admin";
accountLink.textContent = t("loginManage");
} else if (state.auth.allowed) {
accountLink.href = "#logout";
accountLink.dataset.action = "logout";
accountLink.textContent = t("loginManage");
} else {
accountLink.href = "/login";
accountLink.dataset.action = "login";
accountLink.textContent = t("loginManage");
}
const status = el("auth-status");
const loginLink = el("login-link");
const logoutButton = el("logout-button");
const signedIn = Boolean(state.auth.allowed && state.auth.login);

status.hidden = !signedIn;
status.textContent = signedIn ? t("signedInAs").replace("{login}", state.auth.login) : "";
loginLink.hidden = !state.auth.available || signedIn;
loginLink.href = "/login";
loginLink.textContent = t("login");
logoutButton.hidden = !signedIn;
logoutButton.textContent = t("logout");

const dispatch = el("dispatch-button");
const hasPrivateAccounts = state.configSource === "private";
Expand Down Expand Up @@ -1016,9 +1022,7 @@ <h2 data-i18n="summary">切换摘要</h2>
}
}

async function handleAccountLink(event) {
if (el("account-link").dataset.action !== "logout") return;
event.preventDefault();
async function handleLogout() {
await fetch("/api/logout", { method: "POST" });
window.location.reload();
}
Expand Down Expand Up @@ -1074,7 +1078,7 @@ <h2 data-i18n="summary">切换摘要</h2>
});

el("dispatch-button").addEventListener("click", dispatchSwitch);
el("account-link").addEventListener("click", handleAccountLink);
el("logout-button").addEventListener("click", handleLogout);

render();
refreshSession();
Expand Down
Loading