Files
MajoorWaldi-ComfyUI-Majoor-…/js/features/panel/controllers/scopeController.js
T
Ewald 00d141ef8c Add tests and enhancements for browser navigation and asset management
- Implemented size filters in the filesystem browser and added tests to ensure correct application of size constraints.
- Updated write access guard tests to reflect changes in handling forwarded remote requests.
- Introduced a new browser navigation controller to manage folder navigation and breadcrumb rendering.
- Added regression tests to ensure proper binding order for asset manager and back navigation functionality.
- Created tests to validate the absence of double reloads on folder context opening and the use of single folder keys in browser state.
- Added various regression tests to ensure database integrity, asset metadata handling, and viewer functionality.
- Enhanced tests for media filters and search scope to ensure correct behavior and data handling.
2026-02-18 08:11:14 +01:00

62 lines
1.8 KiB
JavaScript

export function createScopeController({
state,
tabButtons,
customMenuBtn,
customPopover,
popovers,
reloadGrid,
onChanged = null,
onScopeChanged = null,
onBeforeReload = null
}) {
let scopeSwitchSeq = 0;
const setActiveTabStyles = () => {
const buttons = Object.values(tabButtons || {});
buttons.forEach((b) => {
const scope = b?.dataset?.scope;
const active = scope === state.scope;
b?.classList?.toggle?.("is-active", active);
});
customMenuBtn.style.display = "none";
customPopover.style.display = "none";
popovers.close(customPopover);
};
const setScope = async (scope) => {
const requestedSeq = ++scopeSwitchSeq;
const allowed = new Set(["output", "outputs", "input", "inputs", "all", "custom"]);
const normalized = String(scope || "").toLowerCase();
if (!allowed.has(normalized)) return;
// Switching scope exits any active collection view.
state.collectionId = "";
state.collectionName = "";
state.scope = normalized === "outputs" ? "output" : normalized === "inputs" ? "input" : normalized;
// Scope switch should reset folder context to avoid stale filtering behavior.
state.currentFolderRelativePath = "";
if (state.scope !== "custom") {
state.customRootId = "";
}
setActiveTabStyles();
try {
onChanged?.();
} catch {}
try {
await onScopeChanged?.(state);
} catch {}
if (requestedSeq !== scopeSwitchSeq) return;
try {
await onBeforeReload?.(state);
} catch {}
if (requestedSeq !== scopeSwitchSeq) return;
await reloadGrid();
};
return { setScope, setActiveTabStyles };
}