Refactor metadata handling by removing direct UI updates from saveModelMetadata and related functions

This commit is contained in:
Will Miao
2025-06-17 20:25:39 +08:00
parent 8764998e8c
commit 71df8ba3e2
15 changed files with 7 additions and 111 deletions

View File

@@ -115,16 +115,6 @@ export function setupModelNameEditing(filePath) {
await saveModelMetadata(filePath, { model_name: newModelName });
// Update the corresponding lora card's dataset and display
updateModelCard(filePath, { model_name: newModelName });
// BUGFIX: Directly update the card's dataset.name attribute to ensure
// it's correctly read when reopening the modal
const loraCard = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
if (loraCard) {
loraCard.dataset.name = newModelName;
}
showToast('Model name updated successfully', 'success');
} catch (error) {
console.error('Error updating model name:', error);
@@ -304,9 +294,6 @@ async function saveBaseModel(filePath, originalValue) {
try {
await saveModelMetadata(filePath, { base_model: newBaseModel });
// Update the corresponding lora card's dataset
updateModelCard(filePath, { base_model: newBaseModel });
showToast('Base model updated successfully', 'success');
} catch (error) {
showToast('Failed to update base model', 'error');

View File

@@ -463,15 +463,6 @@ async function saveTags() {
// Exit edit mode
editBtn.click();
// Update the LoRA card's dataset
const loraCard = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
if (loraCard) {
loraCard.dataset.tags = JSON.stringify(tags);
// Also update the card in the DOM
// updateLoraCard(loraCard, { tags: tags });
}
showToast('Tags updated successfully', 'success');
} catch (error) {
console.error('Error saving tags:', error);

View File

@@ -62,6 +62,5 @@ window.removePreset = async function(key) {
usage_tips: newPresetsJson
});
loraCard.dataset.usage_tips = newPresetsJson;
document.querySelector('.preset-tags').innerHTML = renderPresetTags(currentPresets);
};

View File

@@ -620,28 +620,6 @@ async function saveTriggerWords() {
// Exit edit mode without restoring original trigger words
editBtn.click();
// Update the LoRA card's dataset
const loraCard = document.querySelector(`.lora-card[data-filepath="${filePath}"]`);
if (loraCard) {
try {
// Create a proper structure for civitai data
let civitaiData = {};
// Parse existing data if available
if (loraCard.dataset.meta) {
civitaiData = JSON.parse(loraCard.dataset.meta);
}
// Update trainedWords property
civitaiData.trainedWords = words;
// Update the meta dataset attribute with the full civitai data
loraCard.dataset.meta = JSON.stringify(civitaiData);
} catch (e) {
console.error('Error updating civitai data:', e);
}
}
// If we saved an empty array and there's a no-trigger-words element, show it
const noTriggerWords = triggerWordsSection.querySelector('.no-trigger-words');
const tagsContainer = triggerWordsSection.querySelector('.trigger-words-tags');

View File

@@ -272,9 +272,6 @@ window.saveNotes = async function(filePath) {
try {
await saveModelMetadata(filePath, { notes: content });
// Update the corresponding lora card's dataset
updateModelCard(filePath, { notes: content });
showToast('Notes saved successfully', 'success');
} catch (error) {
showToast('Failed to save notes', 'error');
@@ -339,9 +336,6 @@ function setupEditableFields(filePath) {
usage_tips: newPresetsJson
});
// Update the card with the new usage tips
updateModelCard(filePath, { usage_tips: newPresetsJson });
presetTags.innerHTML = renderPresetTags(currentPresets);
presetSelector.value = '';