|
|
|
@ -10,6 +10,7 @@ import java.util.Set; |
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
|
|
|
|
|
import javax.faces.event.AjaxBehaviorEvent; |
|
|
|
|
import javax.faces.event.ValueChangeEvent; |
|
|
|
|
import javax.faces.model.DataModel; |
|
|
|
|
import javax.faces.model.ListDataModel; |
|
|
|
|
import javax.faces.view.ViewScoped; |
|
|
|
@ -203,6 +204,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
ingredients |
|
|
|
|
.setWrappedData(new ArrayList<IngredientUI>(1)); |
|
|
|
|
} |
|
|
|
|
log.info("Ingredient size="+ingredients.getRowCount()); |
|
|
|
|
return ingredients; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -224,7 +226,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
*/ |
|
|
|
|
if (this.recipe == null) { |
|
|
|
|
Long rid = |
|
|
|
|
//(Long) JSFUtils.getFlash("recipeID");
|
|
|
|
|
// (Long) JSFUtils.getFlash("recipeID");
|
|
|
|
|
userSession.getLastEdit(); |
|
|
|
|
if (rid != null) { |
|
|
|
|
this.recipe = loadRecipe(rid); |
|
|
|
@ -357,6 +359,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
public String doAddIngredient() { |
|
|
|
|
this.addIngredientList(this.getIngredientText()); |
|
|
|
|
setIngredientText(""); // clear for next entry
|
|
|
|
|
updateSelectionStatus(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -376,7 +379,67 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
doAddIngredient(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void ajaxMoveUp(AjaxBehaviorEvent event) { |
|
|
|
|
// ===
|
|
|
|
|
/** |
|
|
|
|
* Listen to the SELECT checkboxes on Ingredients and update |
|
|
|
|
* the action button statuses. |
|
|
|
|
* |
|
|
|
|
* @param event notused |
|
|
|
|
*/ |
|
|
|
|
public void ajaxSelectionListener(AjaxBehaviorEvent event) { |
|
|
|
|
updateSelectionStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateSelectionStatus() { |
|
|
|
|
List<IngredientUI> ingList = getWrappedIngredients(); |
|
|
|
|
final int ingCount = ingList.size(); |
|
|
|
|
|
|
|
|
|
boolean moveUpable = true; |
|
|
|
|
boolean moveDownable = true; |
|
|
|
|
boolean selectable = false; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < ingCount; i++) { |
|
|
|
|
boolean selected = ingList.get(i).isSelected(); |
|
|
|
|
if ((i == 0) && selected) { |
|
|
|
|
moveUpable = false; |
|
|
|
|
} |
|
|
|
|
if ((i == (ingCount - 1)) && selected) { |
|
|
|
|
moveDownable = false; |
|
|
|
|
} |
|
|
|
|
selectable |= selected; |
|
|
|
|
} |
|
|
|
|
this.setMoveUpAble(moveUpable && selectable); |
|
|
|
|
this.setMoveDownAble(moveDownable && selectable); |
|
|
|
|
this.setSelectable(selectable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
public void setMoveUpAble(boolean moveUpable) { |
|
|
|
|
this.moveUpable = moveUpable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setMoveDownAble(boolean moveDownable) { |
|
|
|
|
this.moveDownable = moveDownable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setSelectable(boolean selectable) { |
|
|
|
|
this.selectable = selectable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveUpAble() { |
|
|
|
|
return this.moveUpable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveDownAble() { |
|
|
|
|
return this.moveDownable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isSelectable() { |
|
|
|
|
return this.selectable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
public void ajaxMoveUp() { |
|
|
|
|
if (!isMoveUpAble()) { |
|
|
|
|
JSFUtils.addErrorMessage("Cannot move up."); |
|
|
|
|
return; |
|
|
|
@ -393,6 +456,15 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.setDirty(); |
|
|
|
|
auditRows(rows); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void auditRows(List<IngredientUI> rows) { |
|
|
|
|
log.info("=== AUDIT ROWS ==="); |
|
|
|
|
for ( IngredientUI row : rows ) { |
|
|
|
|
log.info((row.isSelected() ? "[X]" : "[ ]" ) +" ROW="+row); |
|
|
|
|
} |
|
|
|
|
log.info("=== DONE ==="); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -400,7 +472,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
* |
|
|
|
|
* @param eventUnused |
|
|
|
|
*/ |
|
|
|
|
public void ajaxMoveDown(AjaxBehaviorEvent event) { |
|
|
|
|
public void ajaxMoveDown() { |
|
|
|
|
if (!isMoveDownAble()) { |
|
|
|
|
JSFUtils.addErrorMessage("Cannot move down."); |
|
|
|
|
return; |
|
|
|
@ -416,9 +488,10 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
rows.add(i, r); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
auditRows(rows); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void ajaxDeleteItems(AjaxBehaviorEvent event) { |
|
|
|
|
public void ajaxDeleteItems() { |
|
|
|
|
final List<IngredientUI> rows = getWrappedIngredients(); |
|
|
|
|
List<IngredientUI> selectedRows = |
|
|
|
|
new ArrayList<IngredientUI>(); |
|
|
|
@ -433,61 +506,81 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
for (IngredientUI row : selectedRows) { |
|
|
|
|
rows.remove(row); |
|
|
|
|
} |
|
|
|
|
auditRows(rows); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// =====
|
|
|
|
|
@Inject |
|
|
|
|
EditShopcatBean editShopcatBean; |
|
|
|
|
|
|
|
|
|
private boolean moveUpable; |
|
|
|
|
|
|
|
|
|
private boolean moveDownable; |
|
|
|
|
|
|
|
|
|
private boolean selectable; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Invoked when the "E"(dit" button for Ingkey shopping |
|
|
|
|
* category has been clicked. |
|
|
|
|
* |
|
|
|
|
* @param item The item whose ingredient key will |
|
|
|
|
* have its shopping category edited. Resets the dialog |
|
|
|
|
* backing bean internal state. |
|
|
|
|
*/ |
|
|
|
|
public void ajaxEditShopcat(IngredientUI item) { |
|
|
|
|
// Map<String, Object> options = new HashMap<>();
|
|
|
|
|
// options.put("resizable", false);
|
|
|
|
|
// TODO: Reject if ingkey is empty/null
|
|
|
|
|
editShopcatBean.setIngkey(item.getIngkey()); |
|
|
|
|
editShopcatBean.setShopcatName(item.getShopCat()); |
|
|
|
|
// if ( ! StringUtils.isBlank(key) ) {
|
|
|
|
|
// PrimeFaces.current().dialog().openDynamic("editShopcat");
|
|
|
|
|
// }
|
|
|
|
|
editShopcatBean.beginEdit(item.getIngkey(), |
|
|
|
|
item.getShopCat()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* On "OK" for edit shopcat where shopcat has changed, |
|
|
|
|
* update the shopcat Entity and the ingredients. |
|
|
|
|
*/ |
|
|
|
|
public void doUpdateShopcat() { |
|
|
|
|
|
|
|
|
|
final String key = editShopcatBean.getIngkey(); |
|
|
|
|
if ( StringUtils.isBlank(key)) { |
|
|
|
|
if (StringUtils.isBlank(key)) { |
|
|
|
|
return; // Do not set category if no ingKey
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final String catname = editShopcatBean.getShopcatName(); |
|
|
|
|
|
|
|
|
|
Shopcat sc = this.recipeService |
|
|
|
|
.findShopcatForIngredientKey(catname); |
|
|
|
|
.findShopcatForIngredientKey(key); |
|
|
|
|
if (sc == null) { |
|
|
|
|
sc = new Shopcat(); |
|
|
|
|
sc.setIngkey(key); |
|
|
|
|
sc.setShopcategory(catname); |
|
|
|
|
} else { |
|
|
|
|
if (catname.equals(sc.getShopcategory())) { |
|
|
|
|
// No change. Do nothing.
|
|
|
|
|
return; |
|
|
|
|
if ( StringUtils.equals(sc.getShopcategory(), catname) ) { |
|
|
|
|
return; // No change
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sc.setShopcategory(catname); |
|
|
|
|
|
|
|
|
|
if ( StringUtils.isBlank(catname)) { |
|
|
|
|
this.recipeService.deleteShopcat(sc); |
|
|
|
|
} else { |
|
|
|
|
/* |
|
|
|
|
* Because the database does not have a UNIQUE |
|
|
|
|
* constraint on ingkeys, we must delete old |
|
|
|
|
* shopcat(s) for this key before adding (updating) |
|
|
|
|
* the new shopcat. |
|
|
|
|
*/ |
|
|
|
|
this.recipeService.deleteShopcatByIngKey(key); |
|
|
|
|
if (! StringUtils.isBlank(catname)) { |
|
|
|
|
this.recipeService.saveShopcat(sc); |
|
|
|
|
} |
|
|
|
|
updateDisplayedShopcats(key, sc); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* When Shopcat name changes, update the Ingredients. |
|
|
|
|
* In detailEdit, an AJAX "render" will then update |
|
|
|
|
* the display. In recipeDetails, nothing actually shows. |
|
|
|
|
* When Shopcat name changes, update the Ingredients. In |
|
|
|
|
* detailEdit, an AJAX "render" will then update the display. |
|
|
|
|
* In recipeDetails, nothing actually shows. |
|
|
|
|
*/ |
|
|
|
|
private void updateDisplayedShopcats(String key, Shopcat sc) { |
|
|
|
|
List<IngredientUI> ingList = this.getWrappedIngredients(); |
|
|
|
|
for (IngredientUI ingUI: ingList ) { |
|
|
|
|
if ( key.equals(ingUI.getIngkey())) { |
|
|
|
|
private void updateDisplayedShopcats(String key, |
|
|
|
|
Shopcat sc) { |
|
|
|
|
List<IngredientUI> ingList = |
|
|
|
|
this.getWrappedIngredients(); |
|
|
|
|
for (IngredientUI ingUI : ingList) { |
|
|
|
|
if (key.equals(ingUI.getIngkey())) { |
|
|
|
|
ingUI.setShopCat(sc); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -521,6 +614,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
addIngredient(line); |
|
|
|
|
} |
|
|
|
|
updateSelectionStatus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -541,43 +635,6 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
ingredients.add(new IngredientUI(ing)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isSelectionActive() { |
|
|
|
|
List<IngredientUI> rows = getWrappedIngredients(); |
|
|
|
|
for (IngredientUI row : rows) { |
|
|
|
|
if (row.isSelected()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setSelectionActive(boolean value) { |
|
|
|
|
// This is required by JBoss JSF, but the property is
|
|
|
|
|
// read-only.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setMoveUpAble() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setMoveDownAble() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveUpAble() { |
|
|
|
|
return true; |
|
|
|
|
// TODO:
|
|
|
|
|
// if (isSelectionActive()) {
|
|
|
|
|
// List<IngredientUI> rows = getWrappedIngredients();
|
|
|
|
|
// return !rows.get(0).isSelected();
|
|
|
|
|
// }
|
|
|
|
|
// return false;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean isMoveDownAble() { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ===
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -695,11 +752,10 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
Shopcat scat = recipeService |
|
|
|
|
.findShopcatForIngredientKey(ingKey); |
|
|
|
|
if (scat == null) { |
|
|
|
|
JSFUtils.addErrorMessage( |
|
|
|
|
log.debug( |
|
|
|
|
"No Shopping Category is defined for Ingredient Key " |
|
|
|
|
+ ingKey); |
|
|
|
|
//return false;
|
|
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
} |
|
|
|
|
ing.setShopCat(scat); |
|
|
|
|
return true; |
|
|
|
@ -865,7 +921,6 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
public void ajaxUpdateShopcat(IngredientUI item) { |
|
|
|
|
log.warn("SHOPCAT2 "); |
|
|
|
|
updateShopcat(item); |
|
|
|
|
; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ***
|
|
|
|
@ -1003,7 +1058,7 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
return String.valueOf(now); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//*** Add Group
|
|
|
|
|
// *** Add Group
|
|
|
|
|
|
|
|
|
|
private String newGroupName; |
|
|
|
|
|
|
|
|
@ -1023,13 +1078,15 @@ public class RecipeDetailBean implements Serializable { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Add new group to bottom of model as AJAX operation. |
|
|
|
|
* |
|
|
|
|
* @return null |
|
|
|
|
*/ |
|
|
|
|
public void doAddGroup() { |
|
|
|
|
IngredientUI iui = new IngredientUI(null); |
|
|
|
|
iui.setIngGroup(true); |
|
|
|
|
iui.setItem(this.getNewGroupName()); |
|
|
|
|
List<IngredientUI> ingUIList = this.getWrappedIngredients(); |
|
|
|
|
List<IngredientUI> ingUIList = |
|
|
|
|
this.getWrappedIngredients(); |
|
|
|
|
ingUIList.add(iui); |
|
|
|
|
this.setNewGroupName(""); // Clear for next time!
|
|
|
|
|
} |
|
|
|
|