fix(feeder): render units in app-config panel, remove from platform-config
- Delete feeder source-panel override (units no longer in platform config) - Extract buildUnitCard() and render to both unitList and unitConfigList - Guard null DOM refs for removed unit buttons Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
63cf3d8c67
commit
bc8b5a24ab
|
|
@ -1,22 +0,0 @@
|
|||
<section class="panel bottom-left">
|
||||
<div class="stack-panel">
|
||||
<div class="stack-section">
|
||||
<div class="panel-head">
|
||||
<h2>控制单元</h2>
|
||||
<div class="toolbar">
|
||||
<button type="button" class="secondary" id="refreshUnitBtn">刷新</button>
|
||||
<button type="button" id="newUnitBtn">+ 新增</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list unit-list" id="unitList"></div>
|
||||
</div>
|
||||
|
||||
<div class="stack-section stack-section-bordered">
|
||||
<div class="panel-head">
|
||||
<h2>数据源</h2>
|
||||
<button type="button" id="openSourceForm">+ 新增</button>
|
||||
</div>
|
||||
<div class="source-panels" id="sourceList"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
@ -96,8 +96,8 @@ function bindEvents() {
|
|||
dom.batchBindingForm.addEventListener("submit", (event) => withStatus(saveBatchBinding(event)));
|
||||
|
||||
dom.unitResetBtn.addEventListener("click", resetUnitForm);
|
||||
dom.refreshUnitBtn.addEventListener("click", () => withStatus(loadUnits().then(loadEvents)));
|
||||
dom.newUnitBtn.addEventListener("click", openCreateUnitModal);
|
||||
if (dom.refreshUnitBtn) dom.refreshUnitBtn.addEventListener("click", () => withStatus(loadUnits().then(loadEvents)));
|
||||
if (dom.newUnitBtn) dom.newUnitBtn.addEventListener("click", openCreateUnitModal);
|
||||
dom.closeUnitModalBtn.addEventListener("click", closeUnitModal);
|
||||
|
||||
dom.sourceResetBtn.addEventListener("click", () => dom.sourceForm.reset());
|
||||
|
|
@ -183,7 +183,7 @@ function bindEvents() {
|
|||
dom.tabAppConfig.addEventListener("click", () => switchView("app-config"));
|
||||
dom.tabConfig.addEventListener("click", () => switchView("config"));
|
||||
|
||||
dom.refreshUnitBtn2.addEventListener("click", () => withStatus(loadUnits()));
|
||||
dom.refreshUnitBtn2.addEventListener("click", () => withStatus(loadUnits().then(loadEvents)));
|
||||
dom.newUnitBtn2.addEventListener("click", openCreateUnitModal);
|
||||
|
||||
document.addEventListener("equipments-updated", () => {
|
||||
|
|
|
|||
|
|
@ -97,17 +97,9 @@ function runtimeBadge(runtime) {
|
|||
return `<span class="badge ${cls}">${label}</span>`;
|
||||
}
|
||||
|
||||
export function renderUnits() {
|
||||
dom.unitList.innerHTML = "";
|
||||
|
||||
if (!state.units.length) {
|
||||
dom.unitList.innerHTML = '<div class="list-item"><div class="muted">暂无控制单元</div></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
state.units.forEach((unit) => {
|
||||
function buildUnitCard(unit, interactive) {
|
||||
const card = document.createElement("div");
|
||||
const selected = state.selectedUnitId === unit.id;
|
||||
const selected = interactive && state.selectedUnitId === unit.id;
|
||||
card.className = `list-item unit-card ${selected ? "selected" : ""}`;
|
||||
const runtime = state.runtimes.get(unit.id);
|
||||
card.innerHTML = `
|
||||
|
|
@ -122,11 +114,13 @@ export function renderUnits() {
|
|||
<div class="row unit-card-actions"></div>
|
||||
`;
|
||||
|
||||
if (interactive) {
|
||||
card.addEventListener("click", () => {
|
||||
selectUnit(unit.id).catch((error) => {
|
||||
dom.statusText.textContent = error.message;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const actions = card.querySelector(".unit-card-actions");
|
||||
|
||||
|
|
@ -181,10 +175,28 @@ export function renderUnits() {
|
|||
actions.append(ackBtn);
|
||||
}
|
||||
|
||||
dom.unitList.appendChild(card);
|
||||
return card;
|
||||
}
|
||||
|
||||
function renderToContainer(container, interactive) {
|
||||
if (!container) return;
|
||||
container.innerHTML = "";
|
||||
|
||||
if (!state.units.length) {
|
||||
container.innerHTML = '<div class="list-item"><div class="muted">暂无控制单元</div></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
state.units.forEach((unit) => {
|
||||
container.appendChild(buildUnitCard(unit, interactive));
|
||||
});
|
||||
}
|
||||
|
||||
export function renderUnits() {
|
||||
renderToContainer(dom.unitList, true);
|
||||
renderToContainer(dom.unitConfigList, false);
|
||||
}
|
||||
|
||||
export async function loadUnits() {
|
||||
const response = await apiFetch("/api/unit?page=1&page_size=-1");
|
||||
state.units = response.data || [];
|
||||
|
|
|
|||
Loading…
Reference in New Issue