import { withStatus } from "./api.js"; import { openChart, renderChart } from "./chart.js"; import { dom } from "./dom.js"; import { closeApiDocDrawer, openApiDocDrawer } from "./docs.js"; import { loadEvents } from "./events.js"; import { applyBatchEquipmentUnit, clearEquipmentFilter, clearPointBinding, clearSelectedEquipments, closeEquipmentModal, loadEquipments, openCreateEquipmentModal, resetEquipmentForm, saveEquipment, } from "./equipment.js"; import { startPointSocket, startLogs, stopLogs } from "./logs.js"; import { startOps, renderOpsUnits, loadAllEquipmentCards } from "./ops.js"; import { clearBatchBinding, browseAndLoadTree, clearSelectedPoints, createPoints, loadPoints, loadTree, openBatchBinding, openPointCreateModal, renderSelectedNodes, saveBatchBinding, savePointBinding, updatePointFilterSummary, updateSelectedPointSummary, } from "./points.js"; import { state } from "./state.js"; import { loadSources, saveSource } from "./sources.js"; import { closeUnitModal, loadUnits, openCreateUnitModal, resetUnitForm, renderUnits, saveUnit } from "./units.js"; function switchView(view) { state.activeView = view; const main = document.querySelector("main"); main.className = view === "ops" ? "grid-ops" : "grid-config"; dom.tabOps.classList.toggle("active", view === "ops"); dom.tabConfig.classList.toggle("active", view === "config"); // config-only panels ["top-left", "top-right", "bottom-left", "bottom-right"].forEach((cls) => { const el = main.querySelector(`.panel.${cls}`); if (el) el.classList.toggle("hidden", view === "ops"); }); // bottom-mid is log-stream in config, hidden in ops const logStreamPanel = main.querySelector(".panel.bottom-mid"); if (logStreamPanel) logStreamPanel.classList.toggle("hidden", view === "ops"); // ops-only panels const opsMain = main.querySelector(".panel.ops-main"); const opsBottom = main.querySelector(".panel.ops-bottom"); if (opsMain) opsMain.classList.toggle("hidden", view === "config"); if (opsBottom) opsBottom.classList.toggle("hidden", view === "config"); if (view === "config") { startLogs(); } else { stopLogs(); } } function bindEvents() { dom.unitForm.addEventListener("submit", (event) => withStatus(saveUnit(event))); dom.sourceForm.addEventListener("submit", (event) => withStatus(saveSource(event))); dom.equipmentForm.addEventListener("submit", (event) => withStatus(saveEquipment(event))); dom.pointBindingForm.addEventListener("submit", (event) => withStatus(savePointBinding(event))); 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); dom.closeUnitModalBtn.addEventListener("click", closeUnitModal); dom.sourceResetBtn.addEventListener("click", () => dom.sourceForm.reset()); dom.equipmentResetBtn.addEventListener("click", resetEquipmentForm); dom.refreshEquipmentBtn.addEventListener("click", () => withStatus(loadEquipments())); dom.newEquipmentBtn.addEventListener("click", openCreateEquipmentModal); dom.closeEquipmentModalBtn.addEventListener("click", closeEquipmentModal); dom.clearEquipmentFilterBtn.addEventListener("click", () => withStatus(clearEquipmentFilter())); dom.applyEquipmentUnitBtn.addEventListener("click", () => withStatus(applyBatchEquipmentUnit())); dom.clearEquipmentSelectionBtn.addEventListener("click", clearSelectedEquipments); dom.openPointModalBtn.addEventListener("click", openPointCreateModal); dom.pointSourceSelect.addEventListener("change", () => { dom.nodeTree.innerHTML = '