Files
JaredTherriault-ComfyUI-JNodes/web/js/ImageDrawer/BasicOptionManagerButtons/BatchDeletionManager.js
T
JaredTherriault f0338b0c5f Batch selection, batch deletion, classifying some scripts, module manager
-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
-
2024-05-07 20:39:40 -07:00

104 lines
3.3 KiB
JavaScript

import { $el } from "/scripts/ui.js";
import { BatchOptionManagerButton } from "./BatchOptionManagerButton.js";
import { utilitiesInstance } from "../../common/Utilities.js";
import { ClassInstanceFactory, imageDrawerComponentManagerInstance } from "../Core/ImageDrawerModule.js";
class BatchDeletionManager extends BatchOptionManagerButton {
constructor(args) {
super(args);
this.bConfirmState = false;
this.confirmText = null;
}
makeWidget() {
const superWidget = super.makeWidget();
{
const recycleIcon = $el("label", {
textContent: "♻️",
style: {
color: "white",
fontWeight: "bolder",
pointerEvents: "none"
}
});
superWidget.button.appendChild(recycleIcon);
}
{
this.confirmText = $el("label", {
textContent: "Confirm?",
style: {
color: "white",
pointerEvents: "none",
display: "none"
}
});
superWidget.button.appendChild(this.confirmText);
}
// Subscribe to when the selection manager's count is updated
const batchSelectionManagerInstance = imageDrawerComponentManagerInstance.getComponentByName("BatchSelectionManager");
batchSelectionManagerInstance.registerCheckedItemCountUpdatedMulticastFunction(() => {
const batchSelectionManagerInstance = imageDrawerComponentManagerInstance.getComponentByName("BatchSelectionManager");
let lastCheckedItemCount = batchSelectionManagerInstance.lastCheckedItemCount;
if (Object.keys(lastCheckedItemCount).length == 0) {
lastCheckedItemCount = batchSelectionManagerInstance.countCheckedItems();
}
this.setWidgetVisible(lastCheckedItemCount.selectedCount > 0);
});
this.setWidgetVisible();
return superWidget;
}
onClickButton() {
if (!this.bConfirmState) {
this.setConfirmState(true);
} else {
const imageDrawerListInstance = imageDrawerComponentManagerInstance.getComponentByName("ImageDrawerList");
for (const child of imageDrawerListInstance.getImageListChildren()) {
if (child.bIsCheckboxSelectorChecked && child.bIsCheckboxSelectorChecked == true && child.deleteItem) {
child.deleteItem();
}
}
this.setWidgetVisible(false);
const batchSelectionManagerInstance = imageDrawerComponentManagerInstance.getComponentByName("BatchSelectionManager");
batchSelectionManagerInstance.updateWidget();
}
}
setWidgetVisible(bNewVisibile) {
this.setConfirmState(false);
super.setWidgetVisible(bNewVisibile);
}
setConfirmState(bNewConfirmState) {
this.bConfirmState = bNewConfirmState;
utilitiesInstance.setElementVisible(this.confirmText, this.bConfirmState);
}
}
const factoryInstance = new ClassInstanceFactory(BatchDeletionManager, {
tooltipText: "Trash, recycle or delete all selected images and videos", buttonClass: "JNodes-image-drawer-menu-delete-selected-button"
});