|
|
|
@ -6,6 +6,7 @@ import javax.annotation.PostConstruct; |
|
|
|
|
import javax.faces.event.AjaxBehaviorEvent; |
|
|
|
|
import javax.faces.model.DataModel; |
|
|
|
|
import javax.faces.model.ListDataModel; |
|
|
|
|
import javax.faces.model.SelectItem; |
|
|
|
|
import javax.faces.view.ViewScoped; |
|
|
|
|
import javax.inject.Inject; |
|
|
|
|
import javax.inject.Named; |
|
|
|
@ -13,6 +14,7 @@ import javax.inject.Named; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import com.mousetech.gourmetj.UserSession; |
|
|
|
@ -42,8 +44,8 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
|
|
|
|
|
/* Logger */ |
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(AdminMainBean.class); |
|
|
|
|
|
|
|
|
|
private static final Logger log = |
|
|
|
|
LoggerFactory.getLogger(AdminMainBean.class); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Persistency service for Recipes |
|
|
|
@ -119,8 +121,8 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return to last search, if any |
|
|
|
|
* No longer broken (required Maven include for annotation). |
|
|
|
|
* Return to last search, if any No longer broken (required |
|
|
|
|
* Maven include for annotation). |
|
|
|
|
*/ |
|
|
|
|
@PostConstruct |
|
|
|
|
void init() { |
|
|
|
@ -131,9 +133,9 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
doFind(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Search, driven by AJAX |
|
|
|
|
* |
|
|
|
|
* @param event Notused |
|
|
|
|
*/ |
|
|
|
|
public void ajaxUpdateList(AjaxBehaviorEvent event) { |
|
|
|
@ -148,15 +150,31 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
this.doFind(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Finder |
|
|
|
|
* |
|
|
|
|
* @return Navigation string |
|
|
|
|
*/ |
|
|
|
|
public String doFind() { |
|
|
|
|
List<Recipe> recipes = |
|
|
|
|
recipeService.findByTitle(searchText); |
|
|
|
|
List<Recipe> recipes = null; |
|
|
|
|
|
|
|
|
|
switch (this.getSearchType()) { |
|
|
|
|
case rst_BY_NAME: |
|
|
|
|
recipes = recipeService.findByTitle(searchText); |
|
|
|
|
break; |
|
|
|
|
case rst_BY_CATEGORY: |
|
|
|
|
recipes = recipeService.findByCategoryLike(searchText); |
|
|
|
|
break; |
|
|
|
|
case rst_BY_CUISINE: |
|
|
|
|
recipes = recipeService.findByCuisineLike(searchText); |
|
|
|
|
break; |
|
|
|
|
case rst_BY_INGREDIENT: |
|
|
|
|
recipes = recipeService.findByIngredientLike(searchText); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
log.error("Invalid recipe search type: " + this.getSearchType()); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getSearchResults().setWrappedData(recipes); |
|
|
|
|
this.userSession.setLastSearch(this.getSearchText()); |
|
|
|
@ -183,7 +201,8 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
*/ |
|
|
|
|
public String showRecipe() { |
|
|
|
|
long recipeId = getSearchResults().getRowData().getId(); |
|
|
|
|
// Flash Scope is buggy under Mojarra plus now using session
|
|
|
|
|
// Flash Scope is buggy under Mojarra plus now using
|
|
|
|
|
// session
|
|
|
|
|
// JSFUtils.flashScope().put("recipeID",
|
|
|
|
|
// Long.valueOf(recipeId));
|
|
|
|
|
userSession.setLastEdit(recipeId); |
|
|
|
@ -194,6 +213,7 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get printable preptime. Database version is in seconds. |
|
|
|
|
* |
|
|
|
|
* @deprecated User {@link UserSession#formatTime(Long)} |
|
|
|
|
* |
|
|
|
|
* @return Formatted time. Called from EL on main page. |
|
|
|
@ -214,4 +234,48 @@ public class AdminMainBean implements Serializable { |
|
|
|
|
return sb.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// ***
|
|
|
|
|
|
|
|
|
|
private RecipeSearchType searchType = |
|
|
|
|
RecipeSearchType.rst_BY_NAME; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the searchType |
|
|
|
|
*/ |
|
|
|
|
public RecipeSearchType getSearchType() { |
|
|
|
|
return searchType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param searchType the searchType to set |
|
|
|
|
*/ |
|
|
|
|
public void setSearchType(RecipeSearchType searchType) { |
|
|
|
|
this.searchType = searchType; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<SelectItem> searchTypeList; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return the searchTypeList |
|
|
|
|
*/ |
|
|
|
|
public List<SelectItem> getSearchTypeList() { |
|
|
|
|
if (searchTypeList == null) { |
|
|
|
|
searchTypeList = loadSearchTypeList(); |
|
|
|
|
} |
|
|
|
|
return searchTypeList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<SelectItem> loadSearchTypeList() { |
|
|
|
|
List<SelectItem> list = new ArrayList<SelectItem>(5); |
|
|
|
|
list.add(new SelectItem(RecipeSearchType.rst_BY_NAME, |
|
|
|
|
"Title")); |
|
|
|
|
list.add(new SelectItem(RecipeSearchType.rst_BY_CATEGORY, |
|
|
|
|
"Category")); |
|
|
|
|
list.add(new SelectItem(RecipeSearchType.rst_BY_CUISINE, |
|
|
|
|
"Cuisine")); |
|
|
|
|
list.add( |
|
|
|
|
new SelectItem(RecipeSearchType.rst_BY_INGREDIENT, |
|
|
|
|
"Ingredient")); |
|
|
|
|
return list; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|