-Added new batch selection and batch deletion features. All imageElements now have a checkbox and each selected element is tracked within a context or folder. When you've selected all you want to delete, click the recycle button on the toolbar, then again to confirm. All checked items will be recylced/deleted. You can also click on the selection widget next to the batch delete button to toggle select/deselect all. -Renamed ImageDrawer.js to ImageDrawerMain.js -Separated ImageListAndSearch out into separate scripts and classes named ImageDrawerList and ImageDrawerSearch -Changed order of some initialized functions and variables in imageElements to better accommodate batch selection - -Moved some scripts over to a classy architecture. More scripts will be moved over time. This will eventually allow for multiple image drawer instances in the same window. -Added a new module script that manages all class instances. See ImageDrawerModule.js for an explanation of the new architecture. Basically, it makes cyclical dependencies impossible. -Updated imports -Updated various scripts to use class instances where applicable -Updated some outdated comments -Added option to prepend or append labels to Labeled widgets -Parameter optimizations -
111 lines
3.7 KiB
JavaScript
111 lines
3.7 KiB
JavaScript
import { $el } from "/scripts/ui.js";
|
|
|
|
import * as Contexts from "./Contexts.js";
|
|
import * as Sorting from "./Sorting.js";
|
|
|
|
import { imageDrawerComponentManagerInstance } from "./Core/ImageDrawerModule.js";
|
|
|
|
let ContextSelector;
|
|
|
|
let lastSelectedContextOption;
|
|
|
|
export function getCurrentContextName() {
|
|
return ContextSelector.value;
|
|
}
|
|
|
|
export function getCurrentContextObject() {
|
|
return Contexts.getContextObjectFromName(ContextSelector.value);
|
|
}
|
|
|
|
export function getCacheForContext(contextName) {
|
|
return Contexts.getContextObjectFromName(contextName).cache;
|
|
}
|
|
|
|
export function reverseItemsInCaches() {
|
|
for (const context in Contexts.getContexts()) {
|
|
Contexts.getContexts()[context]?.reverseItemsInCache();
|
|
}
|
|
|
|
const bSkipRestore = true;
|
|
getCurrentContextObject()?.switchToContext(bSkipRestore);
|
|
}
|
|
|
|
export function setOptionSelected(option) {
|
|
ContextSelector.value = option;
|
|
onOptionSelected(option);
|
|
}
|
|
|
|
export async function onOptionSelected(selectedValue) {
|
|
// console.log("ContextSelector selectedValue:" + selectedValue);
|
|
|
|
const imageDrawerSearchInstance = imageDrawerComponentManagerInstance.getComponentByName("ImageDrawerSearch");
|
|
|
|
// Create cache for previously selected option
|
|
if (lastSelectedContextOption) {
|
|
const imageDrawerListInstance = imageDrawerComponentManagerInstance.getComponentByName("ImageDrawerList");
|
|
const childNodesArray = Array.from(imageDrawerListInstance.getImageListChildren());
|
|
|
|
const imageDrawerMainInstance = imageDrawerComponentManagerInstance.getComponentByName("ImageDrawerMain");
|
|
|
|
const newCache =
|
|
new Contexts.ImageDrawerContextCache(
|
|
imageDrawerListInstance.getImageListScrollLevel(), imageDrawerSearchInstance.getSearchText(),
|
|
imageDrawerMainInstance.getColumnCount(), imageDrawerMainInstance.getDrawerWidth(), imageDrawerMainInstance.getDrawerHeight(),
|
|
childNodesArray, Sorting.getCurrentSortTypeName());
|
|
Contexts.getContextObjectFromName(lastSelectedContextOption)?.setCache(newCache);
|
|
}
|
|
|
|
const NewContext = Contexts.getContextObjectFromName(selectedValue);
|
|
await NewContext.switchToContext();
|
|
|
|
// Set up lastSelectedContextOption to accommodate future context switching
|
|
lastSelectedContextOption = selectedValue;
|
|
|
|
// Setup sorting
|
|
Sorting.setSortingOptionsFromSortTypeArray(NewContext.getSupportedSortTypes());
|
|
|
|
const sortType = NewContext.getDesiredSortType();
|
|
if (sortType && typeof sortType === 'object') {
|
|
Sorting.setOptionSelectedFromSortType(sortType.type, sortType.bIsAscending);
|
|
} else if (sortType && typeof sortType === 'string') {
|
|
Sorting.setOptionSelectedFromOptionName(sortType);
|
|
}
|
|
|
|
const batchSelectionManagerInstance = imageDrawerComponentManagerInstance.getComponentByName("BatchSelectionManager");
|
|
batchSelectionManagerInstance.updateWidget();
|
|
|
|
// Automatically focus search bar and select text to save user a click
|
|
imageDrawerSearchInstance.focusAndSelectSearchText();
|
|
}
|
|
|
|
export function createContextSelector() {
|
|
|
|
ContextSelector = $el("select");
|
|
|
|
Contexts.initializeContexts();
|
|
|
|
lastSelectedContextOption = Contexts.getContexts().feed.name;
|
|
|
|
for (const contextKey in Contexts.getContexts()) {
|
|
const context = Contexts.getContexts()[contextKey];
|
|
const option = document.createElement("option");
|
|
option.value = context.name;
|
|
option.textContent = context.name;
|
|
option.title = context.tooltip;
|
|
ContextSelector.appendChild(option);
|
|
}
|
|
|
|
// Add an event listener for the "change" event
|
|
ContextSelector.addEventListener("change", async function () {
|
|
const selectedValue = ContextSelector.value;
|
|
onOptionSelected(selectedValue);
|
|
// await api.fetchApi(
|
|
// '/jnodes_request_task_cancellation', { method: "POST"}); // Cancel any outstanding python task
|
|
});
|
|
|
|
// Initialize
|
|
setOptionSelected(lastSelectedContextOption);
|
|
|
|
return ContextSelector;
|
|
};
|