Option to overwrite downloads.

- Added overwrite to GUI.
- Factored out wrapper for creation $checkbox.
This commit is contained in:
Christian Bastian
2024-02-19 23:38:34 -05:00
parent 48d5757d2b
commit b3f00dd60f
2 changed files with 68 additions and 56 deletions

View File

@@ -420,11 +420,13 @@
} }
/* model manager settings */ /* model manager settings */
.model-manager .model-manager-settings > div { .model-manager .model-manager-settings > div,
.model-manager .model-manager-settings > label {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
gap: 8px; gap: 8px;
margin: 16px 0;
} }
.model-manager .model-manager-settings button { .model-manager .model-manager-settings button {

View File

@@ -869,6 +869,25 @@ function $tab(name, el) {
return $el("div", { dataset: { name } }, el); return $el("div", { dataset: { name } }, el);
} }
/**
* @returns {HTMLLabelElement}
*/
function $checkbox(x = { $: (el) => {}, textContent: "", checked: false }) {
const text = x.textContent;
const input = $el("input", {
type: "checkbox",
checked: x.checked ?? false,
});
const label = $el("label", [
input,
text === "" || text === undefined || text === null ? "" : " " + text,
]);
if (x.$ !== undefined){
x.$(input);
}
return label;
}
class ModelGrid { class ModelGrid {
/** /**
* @param {Array} list * @param {Array} list
@@ -1279,6 +1298,7 @@ class ModelManager extends ComfyDialog {
/** @type {HTMLDivElement} */ modelInfoView: null, /** @type {HTMLDivElement} */ modelInfoView: null,
/** @type {HTMLDivElement} */ modelInfoContainer: null, /** @type {HTMLDivElement} */ modelInfoContainer: null,
/** @type {HTMLDivElement} */ modelInfoUrl: null, /** @type {HTMLDivElement} */ modelInfoUrl: null,
/** @type {HTMLDivElement} */ modelInfoOverwrite: null,
/** @type {HTMLDivElement} */ modelInfos: null, /** @type {HTMLDivElement} */ modelInfos: null,
/** @type {HTMLDivElement} */ modelGrid: null, /** @type {HTMLDivElement} */ modelGrid: null,
@@ -1666,7 +1686,9 @@ class ModelManager extends ComfyDialog {
const el = this.#el.settings; const el = this.#el.settings;
for (const [key, value] of Object.entries(settings)) { for (const [key, value] of Object.entries(settings)) {
const setting = el[key]; const setting = el[key];
if (setting) { if (setting === undefined || setting === null) {
continue;
}
const type = setting.type; const type = setting.type;
switch (type) { switch (type) {
case "checkbox": setting.checked = Boolean(value); break; case "checkbox": setting.checked = Boolean(value); break;
@@ -1676,7 +1698,6 @@ class ModelManager extends ComfyDialog {
default: console.warn("Unknown settings input type!"); default: console.warn("Unknown settings input type!");
} }
} }
}
if (reloadData) { if (reloadData) {
// Is this slow? // Is this slow?
@@ -1783,49 +1804,31 @@ class ModelManager extends ComfyDialog {
}), }),
]), ]),
]), ]),
$el("div", [ $checkbox({
$el("input", {
$: (el) => (this.#el.settings["model-persistent-search"] = el), $: (el) => (this.#el.settings["model-persistent-search"] = el),
type: "checkbox", textContent: "Persistent search text across model types",
}), }),
$el("p", ["Persistent search text across model types"]), $checkbox({
]),
$el("div", [
$el("input", {
$: (el) => (this.#el.settings["model-show-label-extensions"] = el), $: (el) => (this.#el.settings["model-show-label-extensions"] = el),
type: "checkbox", textContent: "Show model file extension in labels",
}), }),
$el("p", ["Show model file extension in labels"]), $checkbox({
]),
$el("div", [
$el("input", {
$: (el) => (this.#el.settings["model-show-add-button"] = el), $: (el) => (this.#el.settings["model-show-add-button"] = el),
type: "checkbox", textContent: "Show add button",
}), }),
$el("p", ["Show add button"]), $checkbox({
]),
$el("div", [
$el("input", {
$: (el) => (this.#el.settings["model-show-copy-button"] = el), $: (el) => (this.#el.settings["model-show-copy-button"] = el),
type: "checkbox", textContent: "Show copy button",
}), }),
$el("p", ["Show copy button"]),
]),
$el("h2", ["Model Add"]), $el("h2", ["Model Add"]),
$el("div", [ $checkbox({
$el("input", {
$: (el) => (this.#el.settings["model-add-embedding-extension"] = el), $: (el) => (this.#el.settings["model-add-embedding-extension"] = el),
type: "checkbox", textContent: "Add extension to embedding",
}), }),
$el("p", ["Add extension to embedding"]), $checkbox({
]),
$el("div", [
$el("input", {
$: (el) => (this.#el.settings["model-add-drag-strict-on-field"] = el), $: (el) => (this.#el.settings["model-add-drag-strict-on-field"] = el),
type: "checkbox", textContent: "Strict dragging model onto a node's model field to add",
}), }),
$el("p", ["Strict dragging model onto a node's model field to add"]),
]),
$el("div", [ $el("div", [
$el("input", { $el("input", {
$: (el) => (this.#el.settings["model-add-offset"] = el), $: (el) => (this.#el.settings["model-add-offset"] = el),
@@ -2101,7 +2104,7 @@ class ModelManager extends ComfyDialog {
} }
return ""; return "";
})(); })();
record["overwrite"] = false; // TODO: add to UI record["overwrite"] = this.#el.modelInfoOverwrite.checked;
e.target.disabled = true; e.target.disabled = true;
let success = true; let success = true;
let resultText = "✔"; let resultText = "✔";
@@ -2283,9 +2286,16 @@ class ModelManager extends ComfyDialog {
if (modelInfos.length === 0) { if (modelInfos.length === 0) {
modelInfosHtml.push($el("div", ["No results found."])); modelInfosHtml.push($el("div", ["No results found."]));
} }
else if (modelInfos.length === 1) { else {
if (modelInfos.length === 1) {
modelInfosHtml[0].open = true; modelInfosHtml[0].open = true;
} }
const label = $checkbox({
$: (el) => { this.#el.modelInfoOverwrite = el; },
textContent: "Overwrite Existing Files",
});
modelInfosHtml.unshift(label);
}
infosHtml.append.apply(infosHtml, modelInfosHtml); infosHtml.append.apply(infosHtml, modelInfosHtml);
} }