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.jsf.project-stage=development
joinfaces.primefaces.theme=bluesky 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.url=jdbc:sqlite:/home/timh/foo/bazz/recipes.db
#spring.datasource.username=dbuser #spring.datasource.username=dbuser

View File

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

View File

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

View File

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

View File

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

View File

@ -17,6 +17,9 @@ import javax.persistence.*;
@NamedQueries({ @NamedQueries({
@NamedQuery(name = "Recipe.findAll", query = "SELECT r FROM Recipe r"), @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,'%')") }) @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 = { @NamedEntityGraph(name = "Recipe.findWorkingSet", attributeNodes = {
@NamedAttributeNode(value = "categories"), @NamedAttributeNode(value = "categories"),
@NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.shopcat") }, subgraphs = { @NamedAttributeNode(value = "ingredientHash", subgraph = "subgraph.shopcat") }, subgraphs = {
@ -89,8 +92,7 @@ public class Recipe implements Serializable {
private Double yields; private Double yields;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(fetch = FetchType.EAGER, mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<Category> categories = private Set<Category> categories = new HashSet<Category>();
new HashSet<Category>();
/** /**
* @param categories the categories to set * @param categories the categories to set

View File

@ -8,6 +8,7 @@ import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.persistence.NamedEntityGraph; import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedNativeQuery;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -51,9 +52,17 @@ public class RecipeService implements Serializable {
return recipeRepository.findDetailsById(recipeId); 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() { public List<String> findCuisines() {
// TODO Auto-generated method stub return recipeRepository.FindCuisinesNative();
return null;
} }

View File

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

View File

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