|
|
|
@ -218,6 +218,8 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
private void init() { |
|
|
|
|
this.recipe = userSession.getRecipe(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("Using recipe: " + this.recipe ); |
|
|
|
|
/** |
|
|
|
|
* For "create new, this recipe is a blank constructed |
|
|
|
|
* and passed from main page. For Detail display, it's |
|
|
|
@ -241,6 +243,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
|
|
|
|
|
getIngredients().setWrappedData( |
|
|
|
|
buildIngredientFacade(recipe.getIngredientHash())); |
|
|
|
|
log.info("Set recipe: " + this.recipe ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -367,8 +370,8 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
* |
|
|
|
|
* Note: In the original Tobago port of this app, the input |
|
|
|
|
* was an inputText. In PrimeFaces, this did not preserve |
|
|
|
|
* line separation characters, so an inputTextArea was |
|
|
|
|
* used instead. |
|
|
|
|
* line separation characters, so an inputTextArea was used |
|
|
|
|
* instead. |
|
|
|
|
* |
|
|
|
|
* @param event Unused |
|
|
|
|
*/ |
|
|
|
@ -450,7 +453,8 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Otherwise, try for split.
|
|
|
|
|
String[] lineArray = ingredientTextLines.split(RE_INGSPLIT); |
|
|
|
|
String[] lineArray = |
|
|
|
|
ingredientTextLines.split(RE_INGSPLIT); |
|
|
|
|
for (String line : lineArray) { |
|
|
|
|
if (line.isBlank()) { |
|
|
|
|
continue; // actually should discard any above
|
|
|
|
@ -538,16 +542,22 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
* save ingredients. |
|
|
|
|
*/ |
|
|
|
|
public String doSave() { |
|
|
|
|
// if ! isDirty()...
|
|
|
|
|
// Update recipe object based on UI:
|
|
|
|
|
|
|
|
|
|
if (!saveIngredients()) { |
|
|
|
|
JSFUtils |
|
|
|
|
.addErrorMessage("Could not save Ingredients"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (recipeService.save(this.getRecipe())) { |
|
|
|
|
userSession.setRecipe(null); |
|
|
|
|
return "main"; |
|
|
|
|
} else { |
|
|
|
|
JSFUtils.addErrorMessage("Save recipe failed"); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
updateRecipeCategories(recipe, category); |
|
|
|
|
// Rebuild ingredients list with groups applied
|
|
|
|
|
updateRecipeGroups(getWrappedIngredients()); |
|
|
|
|
recipeService.save(recipe); |
|
|
|
|
userSession.setRecipe(null); |
|
|
|
|
setDirty(false); |
|
|
|
|
return "main"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -587,6 +597,16 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
* it. |
|
|
|
|
*/ |
|
|
|
|
private boolean saveIngredients() { |
|
|
|
|
if ( ! updateIngredientList()) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
updateRecipeCategories(recipe, category); |
|
|
|
|
// Rebuild ingredients list with groups applied
|
|
|
|
|
updateRecipeGroups(getWrappedIngredients()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean updateIngredientList() { |
|
|
|
|
List<IngredientUI> saveIng = getWrappedIngredients(); |
|
|
|
|
List<Ingredient> iList = recipe.getIngredientHash(); |
|
|
|
|
iList.clear(); |
|
|
|
@ -599,7 +619,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
if (scat == null) { |
|
|
|
|
if ((ingKey != null) && !ingKey.isBlank()) { |
|
|
|
|
scat = new Shopcat(); |
|
|
|
|
scat.setIngkey(ingKey); |
|
|
|
|
// scat.setIngkey(ingKey);
|
|
|
|
|
scat.setShopcategory(shopCatName); |
|
|
|
|
ing.setShopCat(scat); |
|
|
|
|
} else { |
|
|
|
@ -766,7 +786,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
this.cuisineList = cuisineList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//***
|
|
|
|
|
// ***
|
|
|
|
|
// Shopcat for IngredientUI
|
|
|
|
|
private List<String> shopcatList; |
|
|
|
|
|
|
|
|
@ -780,7 +800,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
public void ajaxShopcat(AjaxBehaviorEvent event) { |
|
|
|
|
log.warn("SHOPCAT "); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ***
|
|
|
|
|
|
|
|
|
|
public String editDescription() { |
|
|
|
@ -889,11 +909,12 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
* |
|
|
|
|
* @param event PrimeFaces file upload event object |
|
|
|
|
*/ |
|
|
|
|
public void ajaxUploadImage(FileUploadEvent event) { |
|
|
|
|
UploadedFile foo = event.getFile(); |
|
|
|
|
|
|
|
|
|
public void ajaxUploadImage(FileUploadEvent event) { |
|
|
|
|
UploadedFile foo = event.getFile(); |
|
|
|
|
|
|
|
|
|
PictureController.importImage(recipe, foo.getContents()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Remove images from recipe |
|
|
|
|
* |
|
|
|
|