feat: Implement recipe copy and delete functionality
Backend changes (C#): - Add CopyRecipe method to MachineBridge - Generates new GUID for copied recipe - Returns new recipe with current timestamp - Add DeleteRecipe method to MachineBridge - Prevents deletion of currently selected recipe - Returns success/failure status - Add COPY_RECIPE and DELETE_RECIPE handlers in WebSocketServer Frontend changes (React/TypeScript): - Add CopyRecipe and DeleteRecipe to Window interface types - Add copyRecipe and deleteRecipe methods to communication layer - Implement handleCopy in RecipePage - Prompts user for new name - Adds copied recipe to list - Selects newly copied recipe - Implement handleDelete in RecipePage - Shows confirmation dialog - Removes recipe from list - Selects next available recipe - Connect Copy and Delete buttons with handlers - Disable buttons when no recipe is selected 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -153,5 +153,58 @@ namespace HMIWeb
|
||||
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(recipes);
|
||||
}
|
||||
|
||||
public string CopyRecipe(string recipeId, string newName)
|
||||
{
|
||||
Console.WriteLine($"[C#] Copying Recipe: {recipeId} as {newName}");
|
||||
|
||||
try
|
||||
{
|
||||
// In real app, copy recipe data from database/file
|
||||
// Generate new ID
|
||||
string newId = System.Guid.NewGuid().ToString().Substring(0, 8);
|
||||
string timestamp = System.DateTime.Now.ToString("yyyy-MM-dd");
|
||||
|
||||
var response = new {
|
||||
success = true,
|
||||
message = "Recipe copied successfully",
|
||||
newRecipe = new {
|
||||
id = newId,
|
||||
name = newName,
|
||||
lastModified = timestamp
|
||||
}
|
||||
};
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = new { success = false, message = ex.Message };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
}
|
||||
|
||||
public string DeleteRecipe(string recipeId)
|
||||
{
|
||||
Console.WriteLine($"[C#] Deleting Recipe: {recipeId}");
|
||||
|
||||
try
|
||||
{
|
||||
// In real app, delete recipe from database/file
|
||||
// Check if recipe is in use
|
||||
if (recipeId == _host.GetCurrentRecipe())
|
||||
{
|
||||
var response = new { success = false, message = "Cannot delete currently selected recipe" };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
|
||||
var response = new { success = true, message = "Recipe deleted successfully", recipeId = recipeId };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = new { success = false, message = ex.Message };
|
||||
return JsonConvert.SerializeObject(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user