|
|
|
@ -62,7 +62,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Persistency service for Recipes |
|
|
|
|
* Persistency service for Recipes, Shopcats and Categories |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@ -257,7 +257,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
if (recipe == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Category> cList = recipe.getCategories(); |
|
|
|
|
StringBuffer sb = new StringBuffer(35); |
|
|
|
|
boolean first = true; |
|
|
|
@ -308,7 +308,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
// Shopcat is an eager fetch on Ingredient
|
|
|
|
|
Shopcat shopCat = ing.getShopCat(); |
|
|
|
|
if (shopCat != null) { |
|
|
|
|
ingUi.setShopCat(shopCat.getShopcategory()); |
|
|
|
|
ingUi.setShopCat(shopCat); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return list; |
|
|
|
@ -510,11 +510,13 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveUpAble() { |
|
|
|
|
if (isSelectionActive()) { |
|
|
|
|
List<IngredientUI> rows = getWrappedIngredients(); |
|
|
|
|
return !rows.get(0).isSelected(); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
return true; |
|
|
|
|
// TODO:
|
|
|
|
|
// if (isSelectionActive()) {
|
|
|
|
|
// List<IngredientUI> rows = getWrappedIngredients();
|
|
|
|
|
// return !rows.get(0).isSelected();
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveDownAble() { |
|
|
|
@ -572,24 +574,6 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
return "main"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Apply ingredient group IDs (optional) to individual |
|
|
|
|
* ingredients. |
|
|
|
|
* |
|
|
|
|
* @param wrappedIngredients The wrapped ingredient facade. |
|
|
|
|
*/ |
|
|
|
|
private void updateRecipeGroups( |
|
|
|
|
List<IngredientUI> wrappedIngredients) { |
|
|
|
|
String ingGroup = null; |
|
|
|
|
for (IngredientUI ingUI : wrappedIngredients) { |
|
|
|
|
if (ingUI.isIngGroup()) { |
|
|
|
|
ingGroup = ingUI.getItem(); |
|
|
|
|
} else { |
|
|
|
|
ingUI.getIngredient().setInggroup(ingGroup); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update ingredients and shopcat from UI model |
|
|
|
|
* |
|
|
|
@ -612,34 +596,58 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
iList.clear(); |
|
|
|
|
for (IngredientUI iui : saveIng) { |
|
|
|
|
Ingredient ing = iui.getIngredient(); |
|
|
|
|
ing.setRecipe(recipe); |
|
|
|
|
String ingKey = iui.getIngkey(); |
|
|
|
|
String shopCatName = iui.getShopCat(); |
|
|
|
|
Shopcat scat = ing.getShopCat(); |
|
|
|
|
if (scat == null) { |
|
|
|
|
if ((ingKey != null) && !ingKey.isBlank()) { |
|
|
|
|
scat = new Shopcat(); |
|
|
|
|
// scat.setIngkey(ingKey);
|
|
|
|
|
scat.setShopcategory(shopCatName); |
|
|
|
|
ing.setShopCat(scat); |
|
|
|
|
} else { |
|
|
|
|
JSFUtils.addErrorMessage( |
|
|
|
|
"Shopping Category requires an Ingredient Key"); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if ((ingKey == null) || ingKey.isBlank()) { |
|
|
|
|
ing.setShopCat(null); |
|
|
|
|
} else { |
|
|
|
|
ing.getShopCat() |
|
|
|
|
.setShopcategory(shopCatName); |
|
|
|
|
} |
|
|
|
|
ing.setRecipe(recipe); |
|
|
|
|
if ( ! updateShopcat(ing) ) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
iList.add(ing); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Apply ingredient group IDs (optional) to individual |
|
|
|
|
* ingredients. |
|
|
|
|
* |
|
|
|
|
* @param wrappedIngredients The wrapped ingredient facade. |
|
|
|
|
*/ |
|
|
|
|
private void updateRecipeGroups( |
|
|
|
|
List<IngredientUI> wrappedIngredients) { |
|
|
|
|
String ingGroup = null; |
|
|
|
|
for (IngredientUI ingUI : wrappedIngredients) { |
|
|
|
|
if (ingUI.isIngGroup()) { |
|
|
|
|
ingGroup = ingUI.getItem(); |
|
|
|
|
} else { |
|
|
|
|
ingUI.getIngredient().setInggroup(ingGroup); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update shopcat for Ingredient. |
|
|
|
|
* |
|
|
|
|
* @param ing Ingredient to update |
|
|
|
|
* @return true if update succeeded. |
|
|
|
|
*/ |
|
|
|
|
private boolean updateShopcat(Ingredient ing) { |
|
|
|
|
final String ingKey = ing.getIngkey(); |
|
|
|
|
if ( (ingKey == null) || (ingKey.isBlank())) { |
|
|
|
|
ing.setIngkey(null); |
|
|
|
|
ing.setShopCat(null); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
Shopcat scat = recipeService.findShopcatForIngredientKey(ingKey); |
|
|
|
|
if ( scat == null ) { |
|
|
|
|
JSFUtils.addErrorMessage( |
|
|
|
|
"No Shopping Category is defined for Ingredient Key "+ ingKey); |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
ing.setShopCat(scat); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Parse out the comma-separated category text control and |
|
|
|
|
* post the results as children of the recipe |
|
|
|
@ -797,8 +805,10 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
return shopcatList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void ajaxShopcat(AjaxBehaviorEvent event) { |
|
|
|
|
public void ajaxUpdateShopcat(AjaxBehaviorEvent event) { |
|
|
|
|
log.warn("SHOPCAT "); |
|
|
|
|
// Shopcat scat = recipeService.findShopcatForIngredientKey(ssss);
|
|
|
|
|
// ing.setShopcat(scat);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ***
|
|
|
|
|