Files
MajoorWaldi-ComfyUI-Majoor-…/js/features/panel/controllers/contextController.js
T
Your Name 39a6d6c2b8 Refactor viewer buttons and update gitignore
- Create js/components/buttons.js specific for shared UI elements

- Refactor toolbar.js and Viewer.js to use shared buttons

- Fix viewer overlay theme variable inheritance

- specific ignore patterns added to .gitignore
2026-02-01 22:47:59 +01:00

203 lines
5.8 KiB
JavaScript

import { normalizeQuery } from "./query.js";
const _safeSetValue = (el, value) => {
if (!el) return;
try {
el.value = value;
} catch {}
};
const _safeSetChecked = (el, checked) => {
if (!el) return;
try {
el.checked = !!checked;
} catch {}
};
export function createContextController({
state,
gridContainer,
filterBtn,
sortBtn,
collectionsBtn,
searchInputEl,
kindSelect,
wfCheckbox,
ratingSelect,
dateRangeSelect,
dateExactInput,
scopeController,
sortController,
updateSummaryBar,
reloadGrid
} = {}) {
const actions = {
clearQuery: async () => {
try {
_safeSetValue(searchInputEl, "");
state.searchQuery = "";
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearCollection: async () => {
try {
state.collectionId = "";
state.collectionName = "";
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearScope: async () => {
try {
state.scope = "output";
state.customRootId = "";
scopeController?.setActiveTabStyles?.();
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearCustomRoot: async () => {
try {
state.customRootId = "";
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearFolder: async () => {
try {
// Ensure state is cleared so it doesn't get restored
state.subfolder = "";
delete gridContainer?.dataset?.mjrSubfolder;
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearKind: async () => {
try {
state.kindFilter = "";
_safeSetValue(kindSelect, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearMinRating: async () => {
try {
state.minRating = 0;
_safeSetValue(ratingSelect, "0");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearWorkflowOnly: async () => {
try {
state.workflowOnly = false;
_safeSetChecked(wfCheckbox, false);
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearDateRange: async () => {
try {
state.dateRangeFilter = "";
_safeSetValue(dateRangeSelect, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearDateExact: async () => {
try {
state.dateExactFilter = "";
_safeSetValue(dateExactInput, "");
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearSort: async () => {
try {
state.sort = "mtime_desc";
sortController?.setSortIcon?.(state.sort);
sortController?.renderSortMenu?.();
} catch {}
try {
await reloadGrid?.();
} catch {}
},
clearAll: async () => {
try {
_safeSetValue(searchInputEl, "");
} catch {}
try {
state.collectionId = "";
state.collectionName = "";
state.kindFilter = "";
state.workflowOnly = false;
state.minRating = 0;
state.dateRangeFilter = "";
state.dateExactFilter = "";
state.sort = "mtime_desc";
state.customRootId = "";
state.scope = "output";
scopeController?.setActiveTabStyles?.();
} catch {}
try {
_safeSetValue(kindSelect, "");
_safeSetChecked(wfCheckbox, false);
_safeSetValue(ratingSelect, "0");
_safeSetValue(dateRangeSelect, "");
_safeSetValue(dateExactInput, "");
} catch {}
try {
sortController?.setSortIcon?.(state.sort);
sortController?.renderSortMenu?.();
} catch {}
try {
await reloadGrid?.();
} catch {}
}
};
const update = () => {
const rawQuery = String(searchInputEl?.value || "").trim();
const normalizedQuery = normalizeQuery(searchInputEl);
const filterActive = !!(
(state?.kindFilter || "")
|| state?.workflowOnly
|| (Number(state?.minRating || 0) || 0) > 0
|| (state?.dateRangeFilter || "")
|| (state?.dateExactFilter || "")
);
const sortActive = String(state?.sort || "mtime_desc") !== "mtime_desc";
const collectionsActive = !!(state?.collectionId || "");
try {
filterBtn?.classList?.toggle?.("mjr-context-active", filterActive);
sortBtn?.classList?.toggle?.("mjr-context-active", sortActive);
collectionsBtn?.classList?.toggle?.("mjr-context-active", collectionsActive);
} catch {}
try {
updateSummaryBar?.({
state,
gridContainer,
context: { rawQuery: rawQuery || normalizedQuery },
actions
});
} catch {}
};
return { update, actions };
}