fix: keep modal rows compact and label project by name
This commit is contained in:
parent
ec32d591df
commit
a117a29b0d
@ -400,6 +400,7 @@
|
||||
const state = {
|
||||
projects: [],
|
||||
currentProjectId: null,
|
||||
currentProjectName: null,
|
||||
currentCards: [],
|
||||
collectionTree: [],
|
||||
isImportModalOpen: false,
|
||||
@ -582,10 +583,21 @@
|
||||
elements.selectedCount.textContent = `已选 ${state.selectedItemKeys.size} 篇`;
|
||||
}
|
||||
|
||||
function syncCurrentProjectLabels() {
|
||||
if (state.currentProjectName) {
|
||||
const label = `当前项目:${state.currentProjectName}`;
|
||||
elements.currentProjectLabel.textContent = label;
|
||||
elements.importModalProjectLabel.textContent = label;
|
||||
return;
|
||||
}
|
||||
elements.currentProjectLabel.textContent = "当前未选择项目。";
|
||||
elements.importModalProjectLabel.textContent = "未选择项目";
|
||||
}
|
||||
|
||||
function updateImportActionState() {
|
||||
const hasProject = Boolean(state.currentProjectId);
|
||||
const hasSelection = state.selectedItemKeys.size > 0;
|
||||
elements.importModalProjectLabel.textContent = hasProject ? `当前项目:${state.currentProjectId}` : "未选择项目";
|
||||
syncCurrentProjectLabels();
|
||||
elements.importSelectedItemsButton.disabled = !hasProject || !hasSelection;
|
||||
elements.importSelectedItemsButton.title = !hasProject ? "请先选择项目" : (hasSelection ? "" : "请先选择文献");
|
||||
elements.selectDescendantsButton.disabled = !state.visibleCollectionItems.length;
|
||||
@ -709,7 +721,6 @@
|
||||
<div>
|
||||
<strong>${item.title}</strong>
|
||||
<div class="meta">${item.item_key} · ${item.year || "-"} · ${item.item_type || "-"}</div>
|
||||
<p>${item.abstract || "暂无摘要"}</p>
|
||||
</div>
|
||||
`;
|
||||
row.querySelector("input").addEventListener("change", () => toggleItemSelection(item.item_key));
|
||||
@ -843,19 +854,19 @@
|
||||
if (!state.currentProjectId && projects.length) {
|
||||
state.currentProjectId = projects[0].id;
|
||||
}
|
||||
state.currentProjectName = state.projects.find((project) => project.id === state.currentProjectId)?.name || null;
|
||||
renderProjects();
|
||||
updateImportActionState();
|
||||
if (state.currentProjectId) {
|
||||
await selectProject(state.currentProjectId, false);
|
||||
return;
|
||||
}
|
||||
elements.currentProjectLabel.textContent = "当前未选择项目。";
|
||||
renderCards([]);
|
||||
}
|
||||
|
||||
async function selectProject(projectId, rerender = true) {
|
||||
state.currentProjectId = projectId;
|
||||
elements.currentProjectLabel.textContent = `当前项目:${projectId}`;
|
||||
state.currentProjectName = state.projects.find((project) => project.id === projectId)?.name || projectId;
|
||||
updateImportActionState();
|
||||
if (rerender) {
|
||||
renderProjects();
|
||||
|
||||
@ -41,7 +41,9 @@ def test_index_contains_import_modal_controls(tmp_path) -> None:
|
||||
assert 'id="item-preview-popover"' in html
|
||||
assert 'const ABSTRACT_PREVIEW_DELAY_MS = 3000;' in html
|
||||
assert 'isImportModalOpen: false' in html
|
||||
assert "currentProjectName: null" in html
|
||||
assert "function openImportModal()" in html
|
||||
assert "function closeImportModal()" in html
|
||||
assert "function updateImportActionState()" in html
|
||||
assert 'document.body.classList.toggle("modal-open"' in html
|
||||
assert "${item.abstract" not in html
|
||||
|
||||
Loading…
Reference in New Issue
Block a user