From d4d31790176a4a6ab2cc9bd4abe9e99ac6579873 Mon Sep 17 00:00:00 2001 From: Tim Holloway Date: Mon, 10 Jan 2022 19:43:10 -0500 Subject: [PATCH] misc mainpage and detail edit cleanup --- .../com/mousetech/gourmetj/AdminMainBean.java | 1 + .../mousetech/gourmetj/RecipeDetailBean.java | 73 +++++++++++-------- .../resources/WEB-INF/layout/layout.xhtml | 3 - .../META-INF/resources/css/style.css | 13 +++- .../META-INF/resources/detailEdit.xhtml | 14 +++- .../resources/META-INF/resources/main.xhtml | 34 ++++----- 6 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java index 00595f4..386fd72 100644 --- a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java +++ b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java @@ -92,6 +92,7 @@ public class AdminMainBean implements Serializable { */ public void setSearchText(String searchText) { this.searchText = searchText; + userSession.setLastSearch(searchText); } /**/ diff --git a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java index e77eef9..9e56c69 100644 --- a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java +++ b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java @@ -159,6 +159,7 @@ public class RecipeDetailBean implements Serializable { /** * @return the category as a comma-separated list. + * @see #stringifyCategories(Recipe) */ public String getCategory() { return category; @@ -241,6 +242,8 @@ public class RecipeDetailBean implements Serializable { getIngredients().setWrappedData( buildIngredientFacade(recipe.getIngredientHash())); + stringifyCategories(recipe); + log.info("Set recipe: " + this.recipe); } @@ -255,7 +258,19 @@ public class RecipeDetailBean implements Serializable { if (recipe == null) { return null; } + stringifyCategories(recipe); + return recipe; + } + /** + * Categories are a Set attached to recipe. Build + * a displayable comma-separated list of them. + * + * @param recipe Recipe to get categories from. + * + * @see #getCategory() + */ + private void stringifyCategories(Recipe recipe) { Set cList = recipe.getCategories(); StringBuffer sb = new StringBuffer(35); boolean first = true; @@ -268,7 +283,6 @@ public class RecipeDetailBean implements Serializable { sb.append(cat.getCategory()); } this.category = sb.toString(); - return recipe; } /** @@ -344,7 +358,8 @@ public class RecipeDetailBean implements Serializable { if (instructions == null) { return ""; } - String s = instructions.replace("\n\n", "

"); + String s = instructions.replace("\r\n", "

") + .replace("\n\n", "

"); s = s.replace("\n", "
"); return s; } @@ -413,11 +428,11 @@ public class RecipeDetailBean implements Serializable { this.setMoveUpAble(moveUpable && selectable); this.setMoveDownAble(moveDownable && selectable); this.setSelectable(selectable); - + auditRows(ingList); } - // --- + // --- public void setMoveUpAble(boolean moveUpable) { this.moveUpable = moveUpable; } @@ -464,11 +479,11 @@ public class RecipeDetailBean implements Serializable { } private void auditRows(List rows) { - log.info("=== AUDIT ROWS ==="); - for ( IngredientUI row : rows ) { - log.info((row.isSelected() ? "[X]" : "[ ]" ) +" ROW="+row); - } - log.info("=== DONE ==="); +// log.info("=== AUDIT ROWS ==="); +// for ( IngredientUI row : rows ) { +// log.info((row.isSelected() ? "[X]" : "[ ]" ) +" ROW="+row); +// } +// log.info("=== DONE ==="); } /** @@ -527,21 +542,21 @@ public class RecipeDetailBean implements Serializable { * 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. + * @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) { - editShopcatBean.beginEdit(item.getIngkey(), + editShopcatBean.beginEdit(item.getIngkey(), item.getShopCat()); } /** - * On "OK" for edit shopcat where shopcat has changed, - * update the shopcat Entity and the ingredients. + * 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)) { return; // Do not set category if no ingKey @@ -555,20 +570,20 @@ public class RecipeDetailBean implements Serializable { sc = new Shopcat(); sc.setIngkey(key); } else { - if ( StringUtils.equals(sc.getShopcategory(), catname) ) { + if (StringUtils.equals(sc.getShopcategory(), + catname)) { return; // No change - } + } } sc.setShopcategory(catname); - /* - * 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. + /* + * 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)) { + if (!StringUtils.isBlank(catname)) { this.recipeService.saveShopcat(sc); } updateDisplayedShopcats(key, sc); @@ -711,14 +726,14 @@ public class RecipeDetailBean implements Serializable { List iList = recipe.getIngredientHash(); iList.clear(); for (IngredientUI iui : saveIng) { - if ( iui.isIngGroup() ) { + if (iui.isIngGroup()) { // Ing group is an attribute of ingredients. continue; } Ingredient ing = iui.getIngredient(); ing.setRecipe(recipe); if (!updateShopcat(iui)) { // Obsolete??? - log.info("Shopcat has not been updated" +iui); + log.info("Shopcat has not been updated" + iui); return false; } iList.add(ing); @@ -769,7 +784,7 @@ public class RecipeDetailBean implements Serializable { ing.setShopCat(scat); return true; } - + /** * Parse out the comma-separated category text control and * post the results as children of the recipe @@ -798,7 +813,7 @@ public class RecipeDetailBean implements Serializable { cat.setId(ocat.getId()); } } - recipe.setCategories(new HashSet(newList)); + recipe.setCategories(new HashSet(newList)); } private Category searchCategory(Set oldList, @@ -978,7 +993,7 @@ public class RecipeDetailBean implements Serializable { } /** - * @return the suggestCategory + * @return the suggestCategory List */ public List getSuggestCategory() { if (suggestCategory == null) { diff --git a/src/main/resources/META-INF/resources/WEB-INF/layout/layout.xhtml b/src/main/resources/META-INF/resources/WEB-INF/layout/layout.xhtml index 2abefbc..5f66996 100644 --- a/src/main/resources/META-INF/resources/WEB-INF/layout/layout.xhtml +++ b/src/main/resources/META-INF/resources/WEB-INF/layout/layout.xhtml @@ -54,9 +54,6 @@ -

- @@ -370,8 +370,9 @@ - @@ -386,6 +387,11 @@ ajax="false" immediate="true" action="recipeDetails.jsf" /> + diff --git a/src/main/resources/META-INF/resources/main.xhtml b/src/main/resources/META-INF/resources/main.xhtml index da12a61..d1d208c 100644 --- a/src/main/resources/META-INF/resources/main.xhtml +++ b/src/main/resources/META-INF/resources/main.xhtml @@ -7,24 +7,23 @@ > Gourmet Recipe Manager - +
- - - - + + + + - + -