mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-09-21 03:01:27 -03:00
04485e384f
The option only existed in the LoRA page menu. Move updateEnrichMenuItem and enrichWithAgent into ModelContextMenuMixin so both pages share the implementation, and add the menu item to the checkpoints template.
89 lines
3.4 KiB
JavaScript
89 lines
3.4 KiB
JavaScript
import { BaseContextMenu } from './BaseContextMenu.js';
|
|
import { ModelContextMenuMixin } from './ModelContextMenuMixin.js';
|
|
import { getModelApiClient, resetAndReload } from '../../api/modelApiFactory.js';
|
|
import { copyLoraSyntax, sendLoraToWorkflow, buildLoraSyntax } from '../../utils/uiHelpers.js';
|
|
import { showExcludeModal, showDeleteModal } from '../../utils/modalUtils.js';
|
|
import { moveManager } from '../../managers/MoveManager.js';
|
|
|
|
export class LoraContextMenu extends BaseContextMenu {
|
|
constructor() {
|
|
super('loraContextMenu', '.model-card');
|
|
this.nsfwSelector = document.getElementById('nsfwLevelSelector');
|
|
this.modelType = 'lora';
|
|
this.resetAndReload = resetAndReload;
|
|
|
|
this.initNSFWSelector();
|
|
}
|
|
|
|
// Use the saveModelMetadata implementation from loraApi
|
|
async saveModelMetadata(filePath, data) {
|
|
return getModelApiClient().saveModelMetadata(filePath, data);
|
|
}
|
|
|
|
showMenu(x, y, card) {
|
|
super.showMenu(x, y, card);
|
|
this.updateExcludeMenuItem();
|
|
this.updateEnrichMenuItem(card);
|
|
}
|
|
|
|
handleMenuAction(action, menuItem) {
|
|
// First try to handle with common actions
|
|
if (ModelContextMenuMixin.handleCommonMenuActions.call(this, action)) {
|
|
return;
|
|
}
|
|
|
|
// Otherwise handle lora-specific actions
|
|
switch(action) {
|
|
case 'detail':
|
|
// Trigger the main card click which shows the modal
|
|
this.currentCard.click();
|
|
break;
|
|
case 'copyname':
|
|
// Generate and copy LoRA syntax
|
|
copyLoraSyntax(this.currentCard);
|
|
break;
|
|
case 'sendappend':
|
|
// Send LoRA to workflow (append mode)
|
|
this.sendLoraToWorkflow(false);
|
|
break;
|
|
case 'sendreplace':
|
|
// Send LoRA to workflow (replace mode)
|
|
this.sendLoraToWorkflow(true);
|
|
break;
|
|
case 'replace-preview':
|
|
// Add a new action for replacing preview images
|
|
getModelApiClient().replaceModelPreview(this.currentCard.dataset.filepath);
|
|
break;
|
|
case 'delete':
|
|
// Call showDeleteModal directly instead of clicking the trash button
|
|
showDeleteModal(this.currentCard.dataset.filepath);
|
|
break;
|
|
case 'move':
|
|
moveManager.showMoveModal(this.currentCard.dataset.filepath);
|
|
break;
|
|
case 'refresh-metadata':
|
|
getModelApiClient().refreshSingleModelMetadata(this.currentCard.dataset.filepath);
|
|
break;
|
|
case 'exclude':
|
|
showExcludeModal(this.currentCard.dataset.filepath);
|
|
break;
|
|
case 'restore':
|
|
this.restoreExcludedModel(this.currentCard.dataset.filepath);
|
|
break;
|
|
}
|
|
}
|
|
|
|
sendLoraToWorkflow(replaceMode) {
|
|
const card = this.currentCard;
|
|
const usageTips = JSON.parse(card.dataset.usage_tips || '{}');
|
|
const folder = card.dataset.folder || '';
|
|
const loraName = folder ? `${folder}/${card.dataset.file_name}` : card.dataset.file_name;
|
|
const loraSyntax = buildLoraSyntax(loraName, usageTips);
|
|
|
|
sendLoraToWorkflow(loraSyntax, replaceMode, 'lora');
|
|
}
|
|
}
|
|
|
|
// Mix in shared methods
|
|
Object.assign(LoraContextMenu.prototype, ModelContextMenuMixin);
|