Added Save/Discard warning for model notes.
This commit is contained in:
@@ -1693,6 +1693,7 @@ class ModelInfoView {
|
|||||||
|
|
||||||
elements = {
|
elements = {
|
||||||
/** @type {HTMLDivElement} */ info: null,
|
/** @type {HTMLDivElement} */ info: null,
|
||||||
|
/** @type {HTMLTextAreaElement} */ notes: null,
|
||||||
/** @type {HTMLButtonElement} */ setPreviewButton: null,
|
/** @type {HTMLButtonElement} */ setPreviewButton: null,
|
||||||
/** @type {HTMLInputElement} */ moveDestinationInput: null,
|
/** @type {HTMLInputElement} */ moveDestinationInput: null,
|
||||||
};
|
};
|
||||||
@@ -1700,6 +1701,9 @@ class ModelInfoView {
|
|||||||
/** @type {ImageSelect} */
|
/** @type {ImageSelect} */
|
||||||
previewSelect = null;
|
previewSelect = null;
|
||||||
|
|
||||||
|
/** @type {string} */
|
||||||
|
#savedNotesValue = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {ModelData} modelData
|
* @param {ModelData} modelData
|
||||||
* @param {() => Promise<void>} updateModels
|
* @param {() => Promise<void>} updateModels
|
||||||
@@ -1892,11 +1896,60 @@ class ModelInfoView {
|
|||||||
this.element.removeAttribute("style");
|
this.element.removeAttribute("style");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {void} */
|
/** @returns {Promise<void>} */
|
||||||
hide() {
|
async hide() {
|
||||||
|
const notes = this.elements.notes;
|
||||||
|
if (notes !== undefined && notes !== null) {
|
||||||
|
const noteValue = this.elements.notes.value;
|
||||||
|
const savedNotesValue = this.#savedNotesValue;
|
||||||
|
if (noteValue.trim() !== savedNotesValue.trim()) {
|
||||||
|
const saveChanges = window.confirm("Save notes?");
|
||||||
|
if (saveChanges) {
|
||||||
|
const saved = await this.#saveNotes(noteValue);
|
||||||
|
if (!saved) {
|
||||||
|
window.alert("Failed to save notes!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.#savedNotesValue = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const discardChanges = window.confirm("Discard changes?");
|
||||||
|
if (!discardChanges) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.element.style.display = "none";
|
this.element.style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} newValue
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
async #saveNotes(newValue) {
|
||||||
|
return request(
|
||||||
|
"/model-manager/notes/save",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
"path": this.elements.info.dataset.path,
|
||||||
|
"notes": newValue,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
).then((result) => {
|
||||||
|
const success = result["success"];
|
||||||
|
if (success) {
|
||||||
|
this.#savedNotesValue = newValue;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} searchPath
|
* @param {string} searchPath
|
||||||
* @param {() => Promise<void>} updateModels
|
* @param {() => Promise<void>} updateModels
|
||||||
@@ -2043,30 +2096,18 @@ class ModelInfoView {
|
|||||||
else {
|
else {
|
||||||
if (key === "Notes") {
|
if (key === "Notes") {
|
||||||
elements.push($el("h2", [key + ":"]));
|
elements.push($el("h2", [key + ":"]));
|
||||||
const noteArea = $el("textarea.comfy-multiline-input", {
|
const notes = $el("textarea.comfy-multiline-input", {
|
||||||
name: "model notes",
|
name: "model notes",
|
||||||
value: value,
|
value: value,
|
||||||
rows: 10,
|
rows: 10,
|
||||||
});
|
});
|
||||||
elements.push(noteArea);
|
this.elements.notes = notes;
|
||||||
|
this.#savedNotesValue = value;
|
||||||
|
elements.push(notes);
|
||||||
elements.push($el("button", {
|
elements.push($el("button", {
|
||||||
textContent: "Save Notes",
|
textContent: "Save Notes",
|
||||||
onclick: (e) => {
|
onclick: async (e) => {
|
||||||
const saved = request(
|
const saved = await this.#saveNotes(notes.value);
|
||||||
"/model-manager/notes/save",
|
|
||||||
{
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
"path": this.elements.info.dataset.path,
|
|
||||||
"notes": noteArea.value,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
).then((result) => {
|
|
||||||
return result["success"];
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
buttonAlert(e.target, saved);
|
buttonAlert(e.target, saved);
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
@@ -3230,12 +3271,12 @@ class ModelManager extends ComfyDialog {
|
|||||||
sidebarButtons.element,
|
sidebarButtons.element,
|
||||||
$el("button.icon-button", {
|
$el("button.icon-button", {
|
||||||
textContent: "✖",
|
textContent: "✖",
|
||||||
onclick: () => {
|
onclick: async() => {
|
||||||
if (modelInfoView.isVisible()) { // TODO: decouple back and close
|
if (modelInfoView.isVisible()) { // TODO: decouple back and close
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
modelInfoView.hide();
|
await modelInfoView.hide();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user