Handle Ingredient Group display and save, shopcat finals

This commit is contained in:
Tim Holloway 2022-01-10 12:40:25 -05:00
parent 200317d177
commit 7d9ee67a86
6 changed files with 31 additions and 21 deletions

View File

@ -123,13 +123,4 @@ public class EditShopcatBean implements Serializable {
public void ajaxShopcatSuggest(AjaxBehaviorEvent event) { public void ajaxShopcatSuggest(AjaxBehaviorEvent event) {
this.shopcatName = this.shopcatSuggestion; this.shopcatName = this.shopcatSuggestion;
} }
/**
* ValueChangeListener for shopcat editor.
*
* @param e Event, with new name in it.
*/
public void shopcatNameChanged(ValueChangeEvent e) {
this.changed = true;
}
} }

View File

@ -204,7 +204,6 @@ public class RecipeDetailBean implements Serializable {
ingredients ingredients
.setWrappedData(new ArrayList<IngredientUI>(1)); .setWrappedData(new ArrayList<IngredientUI>(1));
} }
log.info("Ingredient size="+ingredients.getRowCount());
return ingredients; return ingredients;
} }
@ -390,6 +389,9 @@ public class RecipeDetailBean implements Serializable {
updateSelectionStatus(); updateSelectionStatus();
} }
/**
* Manage the ability buttons based on selections.
*/
private void updateSelectionStatus() { private void updateSelectionStatus() {
List<IngredientUI> ingList = getWrappedIngredients(); List<IngredientUI> ingList = getWrappedIngredients();
final int ingCount = ingList.size(); final int ingCount = ingList.size();
@ -411,6 +413,8 @@ public class RecipeDetailBean implements Serializable {
this.setMoveUpAble(moveUpable && selectable); this.setMoveUpAble(moveUpable && selectable);
this.setMoveDownAble(moveDownable && selectable); this.setMoveDownAble(moveDownable && selectable);
this.setSelectable(selectable); this.setSelectable(selectable);
auditRows(ingList);
} }
// --- // ---
@ -456,7 +460,7 @@ public class RecipeDetailBean implements Serializable {
} }
} }
this.setDirty(); this.setDirty();
auditRows(rows); updateSelectionStatus();
} }
private void auditRows(List<IngredientUI> rows) { private void auditRows(List<IngredientUI> rows) {
@ -488,7 +492,7 @@ public class RecipeDetailBean implements Serializable {
rows.add(i, r); rows.add(i, r);
} }
} }
auditRows(rows); updateSelectionStatus();
} }
public void ajaxDeleteItems() { public void ajaxDeleteItems() {
@ -506,7 +510,7 @@ public class RecipeDetailBean implements Serializable {
for (IngredientUI row : selectedRows) { for (IngredientUI row : selectedRows) {
rows.remove(row); rows.remove(row);
} }
auditRows(rows); updateSelectionStatus();
} }
// ===== // =====
@ -707,9 +711,14 @@ public class RecipeDetailBean implements Serializable {
List<Ingredient> iList = recipe.getIngredientHash(); List<Ingredient> iList = recipe.getIngredientHash();
iList.clear(); iList.clear();
for (IngredientUI iui : saveIng) { for (IngredientUI iui : saveIng) {
if ( iui.isIngGroup() ) {
// Ing group is an attribute of ingredients.
continue;
}
Ingredient ing = iui.getIngredient(); Ingredient ing = iui.getIngredient();
ing.setRecipe(recipe); ing.setRecipe(recipe);
if (!updateShopcat(iui)) { if (!updateShopcat(iui)) { // Obsolete???
log.info("Shopcat has not been updated" +iui);
return false; return false;
} }
iList.add(ing); iList.add(ing);

View File

@ -2,3 +2,11 @@
color: red; color: red;
background-color: blue; background-color: blue;
} }
.editIngGroupRow {
background-color: aqua;
font-weight: bold;
}
.displayIngGroupRow {
background-color: aqua;
font-weight: bold;
}

View File

@ -177,7 +177,7 @@
disabled="#{not recipeDetailBean.moveUpAble}" disabled="#{not recipeDetailBean.moveUpAble}"
id="ctlUp" id="ctlUp"
actionListener="#{recipeDetailBean.ajaxMoveUp}" actionListener="#{recipeDetailBean.ajaxMoveUp}"
update="ingredientTable" update="@this:@parent:@parent"
onerror="PF('opError').show()" onerror="PF('opError').show()"
/> />
<p:commandButton value="Down" <p:commandButton value="Down"
@ -185,7 +185,7 @@
id="ctlDown" id="ctlDown"
onerror="PF('opError').show()" onerror="PF('opError').show()"
actionListener="#{recipeDetailBean.ajaxMoveDown}" actionListener="#{recipeDetailBean.ajaxMoveDown}"
update="ingredientTable" update="@this:@parent:@parent"
/> />
<p:commandButton <p:commandButton
value="Add Group" value="Add Group"
@ -206,7 +206,7 @@
disabled="#{not recipeDetailBean.selectable}" disabled="#{not recipeDetailBean.selectable}"
onerror="PF('opError').show()" onerror="PF('opError').show()"
actionListener="#{recipeDetailBean.ajaxDeleteItems}" actionListener="#{recipeDetailBean.ajaxDeleteItems}"
update="ingredientTable" update="@this:@parent:@parent"
/> />
</h:panelGroup> </h:panelGroup>
<p:dataTable id="ingredientTable" <p:dataTable id="ingredientTable"
@ -214,6 +214,7 @@
value="#{recipeDetailBean.ingredients}" value="#{recipeDetailBean.ingredients}"
scrollable="true" scrollable="true"
scrollHeight="380" var="item" scrollHeight="380" var="item"
rowStyleClass="#{item.ingGroup ? 'editIngGroupRow' : null}"
> >
<p:column label="Sel." <p:column label="Sel."
align="center" align="center"
@ -223,9 +224,10 @@
id="selected" id="selected"
value="#{item.selected}" value="#{item.selected}"
> >
<f:ajax <p:ajax
listener="#{recipeDetailBean.ajaxSelectionListener}" listener="#{recipeDetailBean.ajaxSelectionListener}"
render=":form1:tabGroupClient:ingButtons" update=":form1:tabGroupClient:ingButtons"
onerror="PF('opError').show()"
/> />
</p:selectBooleanCheckbox> </p:selectBooleanCheckbox>
</p:column> </p:column>
@ -292,7 +294,7 @@
<f:ajax <f:ajax
event="change" event="change"
listener="#{recipeDetailBean.ajaxUpdateShopcat(item)}" listener="#{recipeDetailBean.ajaxUpdateShopcat(item)}"
render="shopCat" render="eShopcat shopCat"
/> />
</p:inputText> </p:inputText>
</p:column> </p:column>

View File

@ -26,7 +26,6 @@
value="Category Name" /> value="Category Name" />
<p:inputText id="ctlShopcat" <p:inputText id="ctlShopcat"
value="#{editShopcatBean.shopcatName}" value="#{editShopcatBean.shopcatName}"
valueChangeListener="#{editShopcatBean.shopcatNameChanged}"
> >
</p:inputText> </p:inputText>
<h:outputText <h:outputText

View File

@ -147,6 +147,7 @@
showDirectLinksArrows="true" showDirectLinksArrows="true"
value="#{recipeDetailBean.ingredients}" value="#{recipeDetailBean.ingredients}"
var="ingredient" var="ingredient"
rowStyleClass="#{item.ingGroup ? 'displayIngGroupRow' : null}"
> >
<f:facet name="header"> <f:facet name="header">
<h:outputText <h:outputText