Suggestion list for cuisine type re-activated

This commit is contained in:
Tim Holloway 2021-12-31 08:22:01 -05:00
parent e5984e5d6f
commit 3b0342429f
9 changed files with 84 additions and 45 deletions

View File

@ -2,7 +2,8 @@
joinfaces.jsf.project-stage=development
joinfaces.primefaces.theme=bluesky
#spring.thymeleaf.enabled=false
spring.thymeleaf.enabled=false
server.error.whitelabel.enabled=false
spring.datasource.url=jdbc:sqlite:/home/timh/foo/bazz/recipes.db
#spring.datasource.username=dbuser

View File

@ -131,12 +131,21 @@ public class AdminMainBean implements Serializable {
/**
* Remove images from recipe
* Search, driven by AJAX
* @param event Notused
*/
public void ajaxUpdateList(AjaxBehaviorEvent event) {
this.doFind();
}
/**
* Reset search and display
*/
public void ajaxClearList() {
this.setSearchText("");
this.doFind();
}
/**
* Finder

View File

@ -225,16 +225,17 @@ public class RecipeDetailBean implements Serializable {
if (rid != null) {
this.recipe = loadRecipe(rid);
} else {
// alternative (and probably dead) version of "new
// alternative (and probably dead) version of
// "new
// recipe".
this.recipe = new Recipe();
return;
}
}
userSession.setRecipe(this.recipe);
getIngredients().setWrappedData(
buildIngredientFacade(recipe.getIngredientHash()));
buildIngredientFacade(recipe.getIngredientHash()));
}
/**
@ -245,7 +246,7 @@ public class RecipeDetailBean implements Serializable {
*/
private Recipe loadRecipe(Long recipeId) {
Recipe recipe = recipeService.findDetails(recipeId);
if ( recipe == null ) {
if (recipe == null) {
return null;
}
@ -658,7 +659,7 @@ public class RecipeDetailBean implements Serializable {
*
* Use this to assemble the suggestion list.
*/
private String cuisinePartial;
private String cuisinePartial = "";
/**
* @return the cuisinePartial
@ -667,13 +668,22 @@ public class RecipeDetailBean implements Serializable {
return cuisinePartial;
}
public List<String> cuisineSuggestions(String query) {
if (!query.equals(cuisinePartial)) {
setCuisinePartial(query);
}
return getCuisineList();
}
/**
* Set query for eligibility, force list to rebuild.
*
* @param cuisinePartial the cuisinePartial to set
*/
public void setCuisinePartial(String cuisinePartial) {
this.cuisinePartial = cuisinePartial;
this.cuisineList = null; // trigger construction of new
// list.
// trigger construction of new list.
this.cuisineList = null;
}
private List<String> masterCuisineList = null;
@ -701,7 +711,7 @@ public class RecipeDetailBean implements Serializable {
/**
* @return the cuisineList built by matching the master list
* agaist the partial cuisine names.
* against the partial cuisine names.
*/
public List<String> getCuisineList() {
if (this.cuisineList == null) {
@ -856,7 +866,7 @@ public class RecipeDetailBean implements Serializable {
this.category += catToAdd;
catToAdd = "";
}
// ***
Part imageFile = null;
@ -877,6 +887,7 @@ public class RecipeDetailBean implements Serializable {
/**
* Load/replace images. Computes thumbnail.
*
* @param event Notused
*/
public void ajaxUploadImage(AjaxBehaviorEvent event) {
@ -886,16 +897,17 @@ public class RecipeDetailBean implements Serializable {
/**
* Remove images from recipe
*
* @param event Notused
*/
public void ajaxDeleteImage(AjaxBehaviorEvent event) {
this.recipe.setImage(null);
this.recipe.setThumb(null);
}
/**
* Return marker for image. Unlike normal JSF, I don't
* care if it gets multiple times and returns different values.
* Return marker for image. Unlike normal JSF, I don't care
* if it gets multiple times and returns different values.
*
* @return "random" string
*/

View File

@ -29,6 +29,9 @@ public interface RecipeRepository
@EntityGraph(value="Recipe.findWorkingSet")
public Recipe findDetailsById(Long recipeId);
@Query(name = "Recipe.findCusines", nativeQuery = true)
List<String> FindCuisinesNative();
// final static String SQL_FIND_CATEGORIES =
// "SELECT DISTINCT category from categories"

View File

@ -2,6 +2,7 @@ package com.mousetech.gourmetj.persistence.model;
import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
/**
* The persistent class for the "ingredients" database table.
@ -55,6 +56,7 @@ public class Ingredient implements Serializable, IngredientIF {
private String item;
@Column(name = "optional")
@NotNull
private Integer optional;
@Column(name = "position")

View File

@ -17,6 +17,9 @@ import javax.persistence.*;
@NamedQueries({
@NamedQuery(name = "Recipe.findAll", query = "SELECT r FROM Recipe r"),
@NamedQuery(name = "Recipe.findByTitle", query = "SELECT r FROM Recipe r WHERE r.title LIKE concat('%', :searchText,'%')") })
@NamedNativeQuery(name = "Recipe.findCusines", query = "SELECT DISTINCT cuisine from recipe"
+ " where cuisine is not null and cuisine <> ''"
+ " ORDER BY cuisine ASC")
@NamedEntityGraph(name = "Recipe.findWorkingSet", attributeNodes = {
@NamedAttributeNode(value = "categories"),
@NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.shopcat") }, subgraphs = {
@ -89,8 +92,7 @@ public class Recipe implements Serializable {
private Double yields;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Category> categories =
new HashSet<Category>();
private Set<Category> categories = new HashSet<Category>();
/**
* @param categories the categories to set

View File

@ -8,6 +8,7 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedNativeQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -34,7 +35,7 @@ public class RecipeService implements Serializable {
@Inject
private RecipeRepository recipeRepository;
public List<Recipe> findAll() {
return recipeRepository.findAll();
}
@ -51,9 +52,17 @@ public class RecipeService implements Serializable {
return recipeRepository.findDetailsById(recipeId);
}
/**
* final String sql = "SELECT DISTINCT cuisine from recipe"
+ " where cuisine is not null and cuisine <> ''"
+ " ORDER BY cuisine ASC";
* @return
*/
public List<String> findCuisines() {
// TODO Auto-generated method stub
return null;
return recipeRepository.FindCuisinesNative();
}

View File

@ -73,7 +73,7 @@
/>
<p:autoComplete id="rcuisine"
value="#{recipeDetailBean.recipe.cuisine}"
autocomplete="#{recipeDetailBean.cuisinePartial}"
completeMethod="#{recipeDetailBean.cuisineSuggestions}"
/>
<p:outputLabel for="@next"
value="Rating"

View File

@ -8,32 +8,33 @@
<ui:define name="title">Gourmet Recipe Manager</ui:define>
<ui:define name="content">
<h:form id="form1">
<p:panelGrid label="Find a Recipe" columns="1">
<p:panelGrid columns="3">
<span class="ui-input-icon-left"> <i
class="pi pi-search"
/> <p:inputText id="searchFor" width="45"
placeholder="Recipe title (todo) cuisine, etc."
styleClass="redBox" accesskey="f"
value="#{adminMainBean.searchText}"
>
<f:ajax event="change"
execute="@this" render="@form"
listener="#{adminMainBean.ajaxUpdateList}"
/>
</p:inputText>
</span>
<p:button id="find" value="Find"
defaultCommand="true"
action="#{adminMainBean.doFind}"
<div>
<span class="ui-input-icon-left"> <i
class="pi pi-search"
/> <p:inputText id="searchFor" size="45"
placeholder="Recipe title, (todo cuisine, etc.)"
value="#{adminMainBean.searchText}"
>
</p:button>
<p:button value="New Recipe"
action="#{adminMainBean.doNewRecipe}"
>
</p:button>
</p:panelGrid>
</p:panelGrid>
<f:ajax event="change" execute="@this"
render="form2:table1"
listener="#{adminMainBean.ajaxUpdateList}"
/>
</p:inputText>
</span>
<p:commandButton id="find" value="Find"
defaultCommand="true"
action="#{adminMainBean.doFind}"
/>
<p:commandButton id="ctlClear" value="Clear"
immediate="true"
update="form1:searchFor form2:table1"
action="#{adminMainBean.ajaxClearList}"
/>
<p:commandButton value="New Recipe"
action="#{adminMainBean.doNewRecipe}"
/>
<p:defaultCommand target="find" />
</div>
</h:form>
<h:form id="form2">
<p:dataTable id="table1" rows="30"