checkpoint

This commit is contained in:
Will Miao
2025-03-16 16:56:33 +08:00
parent 50babfd471
commit 406284a045
14 changed files with 1145 additions and 300 deletions

View File

@@ -3,6 +3,8 @@ import { showToast } from './utils/uiHelpers.js';
import { state } from './state/index.js';
import { initializeCommonComponents } from './common.js';
import { ImportManager } from './managers/ImportManager.js';
import { RecipeCard } from './components/RecipeCard.js';
import { RecipeModal } from './components/RecipeModal.js';
class RecipeManager {
constructor() {
@@ -14,6 +16,9 @@ class RecipeManager {
// Initialize ImportManager
this.importManager = new ImportManager();
// Initialize RecipeModal
this.recipeModal = new RecipeModal();
this.init();
}
@@ -121,97 +126,15 @@ class RecipeManager {
// Create recipe cards
data.items.forEach(recipe => {
const card = this.createRecipeCard(recipe);
grid.appendChild(card);
const recipeCard = new RecipeCard(recipe, (recipe) => this.showRecipeDetails(recipe));
grid.appendChild(recipeCard.element);
});
}
createRecipeCard(recipe) {
const card = document.createElement('div');
card.className = 'recipe-card';
card.dataset.filePath = recipe.file_path;
card.dataset.title = recipe.title;
card.dataset.created = recipe.created_date;
console.log(recipe);
// 获取 base model
const baseModel = recipe.base_model || '';
// 确保 loras 数组存在
const lorasCount = recipe.loras ? recipe.loras.length : 0;
// Ensure file_url exists, fallback to file_path if needed
const imageUrl = recipe.file_url ||
(recipe.file_path ? `/loras_static/root1/preview/${recipe.file_path.split('/').pop()}` :
'/loras_static/images/no-preview.png');
card.innerHTML = `
<div class="recipe-indicator" title="Recipe">R</div>
<div class="card-preview">
<img src="${imageUrl}" alt="${recipe.title}">
<div class="card-header">
<div class="base-model-wrapper">
${baseModel ? `<span class="base-model-label" title="${baseModel}">${baseModel}</span>` : ''}
</div>
<div class="card-actions">
<i class="fas fa-share-alt" title="Share Recipe"></i>
<i class="fas fa-copy" title="Copy Recipe"></i>
<i class="fas fa-trash" title="Delete Recipe"></i>
</div>
</div>
<div class="card-footer">
<div class="model-info">
<span class="model-name">${recipe.title}</span>
</div>
<div class="lora-count" title="Number of LoRAs in this recipe">
<i class="fas fa-layer-group"></i> ${lorasCount}
</div>
</div>
</div>
`;
// Recipe card click event
card.addEventListener('click', () => {
this.showRecipeDetails(recipe);
});
// Share button click event - prevent propagation to card
card.querySelector('.fa-share-alt')?.addEventListener('click', (e) => {
e.stopPropagation();
// TODO: Implement share functionality
showToast('Share functionality will be implemented later', 'info');
});
// Copy button click event - prevent propagation to card
card.querySelector('.fa-copy')?.addEventListener('click', (e) => {
e.stopPropagation();
// TODO: Implement copy functionality
showToast('Copy functionality will be implemented later', 'info');
});
// Delete button click event - prevent propagation to card
card.querySelector('.fa-trash')?.addEventListener('click', (e) => {
e.stopPropagation();
// TODO: Implement delete functionality
showToast('Delete functionality will be implemented later', 'info');
});
return card;
}
// Add a placeholder for recipe details method
showRecipeDetails(recipe) {
// TODO: Implement recipe details view
console.log('Recipe details:', recipe);
showToast(`Viewing ${recipe.title}`, 'info');
this.recipeModal.showRecipeDetails(recipe);
}
// Will be implemented later:
// - Recipe details view
// - Recipe tag filtering
// - Recipe search and filters
// Add a method to handle recipe import
importRecipes() {
this.importManager.showImportModal();