|
|
|
@ -16,16 +16,19 @@ import org.primefaces.model.StreamedContent; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import com.mousetech.gourmetj.persistence.dao.PantryRepository; |
|
|
|
|
import com.mousetech.gourmetj.persistence.dao.ShopcatRepository; |
|
|
|
|
import com.mousetech.gourmetj.persistence.model.Ingredient; |
|
|
|
|
import com.mousetech.gourmetj.persistence.model.Pantry; |
|
|
|
|
import com.mousetech.gourmetj.persistence.model.Recipe; |
|
|
|
|
import com.mousetech.gourmetj.persistence.model.Shopcat; |
|
|
|
|
import com.mousetech.gourmetj.persistence.service.RecipeService; |
|
|
|
|
import com.mousetech.gourmetj.utils.YamlShoppingList; |
|
|
|
|
|
|
|
|
|
/** Backing bean for the Shopping List tab of the "More..." |
|
|
|
|
* page. |
|
|
|
|
/** |
|
|
|
|
* Backing bean for the Shopping List tab of the "More..." page. |
|
|
|
|
* _TestedBy ShoppingListBeanTest |
|
|
|
|
* |
|
|
|
|
* @author timh |
|
|
|
|
* @since Jan 16, 2022 |
|
|
|
|
*/ |
|
|
|
@ -104,6 +107,11 @@ public class ShoppingListBean implements Serializable { |
|
|
|
|
buildMaps(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void clearRecipeList() { |
|
|
|
|
this.userSession.getShoppingList().clear(); |
|
|
|
|
getRecipeList().clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List<RecipeReference> getRecipeList() { |
|
|
|
|
if (this.recipeList == null) { |
|
|
|
|
this.recipeList = loadRecipeList(); |
|
|
|
@ -111,14 +119,29 @@ public class ShoppingListBean implements Serializable { |
|
|
|
|
return this.recipeList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
|
RecipeService recipeService; |
|
|
|
|
|
|
|
|
|
private List<RecipeReference> loadRecipeList() { |
|
|
|
|
List<RecipeReference> list = |
|
|
|
|
userSession.getShoppingList().stream() |
|
|
|
|
.map(r -> new RecipeReference(r)) |
|
|
|
|
.map(r -> new RecipeReference(fetchRecipe(r))) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Fetch the current version of a recipe. The reference |
|
|
|
|
* version may be out of date if the recipe was edited or |
|
|
|
|
* the Pantry status of one or more Ingredients changed. |
|
|
|
|
* @param r reference recipe |
|
|
|
|
* @return current version of reference recipe |
|
|
|
|
*/ |
|
|
|
|
private Recipe fetchRecipe(Recipe r) { |
|
|
|
|
Recipe rnew = this.recipeService.findDetails(r.getId()); |
|
|
|
|
return rnew; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public List<ShopIngredient> getIngredientList() { |
|
|
|
|
return this.siList; |
|
|
|
|
} |
|
|
|
@ -165,7 +188,7 @@ public class ShoppingListBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
boolean inPantry = false; |
|
|
|
|
Pantry pantry = ing.getPantry(); |
|
|
|
|
if ( (pantry != null) && pantry.getPantry()) { |
|
|
|
|
if ((pantry != null) && pantry.getPantry()) { |
|
|
|
|
inPantry = true; |
|
|
|
|
} |
|
|
|
|
sing = new ShopIngredient(amt, ing.getUnit(), |
|
|
|
@ -242,6 +265,28 @@ public class ShoppingListBean implements Serializable { |
|
|
|
|
.createDownload(getIngredientList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
|
PantryRepository pantryRepository; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Listener for when Pantry checkbox is checked/unchecked |
|
|
|
|
* @param ing Ingredient to update |
|
|
|
|
*/ |
|
|
|
|
public void updatePantry(ShopIngredient ing) { |
|
|
|
|
String ingKey = ing.getIngkey(); |
|
|
|
|
boolean checked = ing.isInPantry(); |
|
|
|
|
Pantry pantry = pantryRepository.findPantryByIngkey(ingKey); |
|
|
|
|
if ( pantry == null ) { |
|
|
|
|
pantry = new Pantry(ingKey, checked); |
|
|
|
|
} else { |
|
|
|
|
pantry.setPantry(checked); |
|
|
|
|
} |
|
|
|
|
pantryRepository.save(pantry); |
|
|
|
|
// Reset recipes to cover ingredient change
|
|
|
|
|
this.recipeList = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// =============================================
|
|
|
|
|
private List<String> shopcatList; |
|
|
|
|
|
|
|
|
|