2021-12-28 20:59:40 +00:00
|
|
|
package com.mousetech.gourmetj;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
|
|
import javax.enterprise.context.SessionScoped;
|
|
|
|
import javax.inject.Named;
|
|
|
|
|
2022-01-03 21:48:15 +00:00
|
|
|
import com.mousetech.gourmetj.persistence.model.Category;
|
2021-12-28 20:59:40 +00:00
|
|
|
import com.mousetech.gourmetj.persistence.model.Recipe;
|
|
|
|
|
|
|
|
@Named
|
|
|
|
@SessionScoped
|
|
|
|
public class UserSession implements Serializable {
|
|
|
|
|
|
|
|
/**
|
2021-12-29 19:30:25 +00:00
|
|
|
* Serial version for session save/restore
|
2021-12-28 20:59:40 +00:00
|
|
|
*/
|
|
|
|
private static final long serialVersionUID =
|
|
|
|
7449440266704831598L;
|
2021-12-29 19:30:25 +00:00
|
|
|
|
2021-12-28 20:59:40 +00:00
|
|
|
private String lastSearch = "";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the lastSearch
|
|
|
|
*/
|
|
|
|
public String getLastSearch() {
|
|
|
|
return lastSearch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param lastSearch the lastSearch to set
|
|
|
|
*/
|
|
|
|
public void setLastSearch(String lastSearch) {
|
|
|
|
this.lastSearch = lastSearch;
|
|
|
|
}
|
2021-12-29 19:30:25 +00:00
|
|
|
|
2021-12-28 20:59:40 +00:00
|
|
|
private Long lastEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the lastEdit
|
|
|
|
*/
|
|
|
|
public Long getLastEdit() {
|
|
|
|
return lastEdit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param lastEdit the lastEdit to set
|
|
|
|
*/
|
|
|
|
public void setLastEdit(Long lastEdit) {
|
|
|
|
this.lastEdit = lastEdit;
|
|
|
|
}
|
2021-12-29 19:30:25 +00:00
|
|
|
|
|
|
|
// ***
|
2021-12-28 20:59:40 +00:00
|
|
|
/**
|
2021-12-29 19:30:25 +00:00
|
|
|
* Tab index to select when presenting editDetails. First tab
|
|
|
|
* is 0.
|
2021-12-28 20:59:40 +00:00
|
|
|
*/
|
|
|
|
private int detailTab;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the detailTab
|
|
|
|
*/
|
|
|
|
public int getDetailTab() {
|
|
|
|
return detailTab;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param detailTab the detailTab to set
|
|
|
|
*/
|
|
|
|
public void setDetailTab(int detailTab) {
|
|
|
|
this.detailTab = detailTab;
|
|
|
|
}
|
|
|
|
|
2021-12-29 19:30:25 +00:00
|
|
|
// ***
|
2021-12-28 20:59:40 +00:00
|
|
|
private Recipe recipe;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recipe is set by the mainpage bean to a blank recipe
|
2021-12-29 19:30:25 +00:00
|
|
|
* before dispatching to the detailEdit page (new recipe). It
|
|
|
|
* is also set by the detail view page so that the detail
|
|
|
|
* view can be edited.
|
2021-12-28 20:59:40 +00:00
|
|
|
*
|
|
|
|
* In addition to detail editing, it's also used by the
|
2021-12-29 19:30:25 +00:00
|
|
|
*
|
2021-12-28 20:59:40 +00:00
|
|
|
* @see PictureController.
|
|
|
|
*
|
|
|
|
* @return Recipe selected.
|
|
|
|
*/
|
|
|
|
public Recipe getRecipe() {
|
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param recipe the recipe to set
|
|
|
|
*/
|
|
|
|
public void setRecipe(Recipe recipe) {
|
|
|
|
this.recipe = recipe;
|
|
|
|
}
|
2021-12-29 19:30:25 +00:00
|
|
|
|
|
|
|
// ====
|
2022-01-03 21:48:15 +00:00
|
|
|
|
|
|
|
public String formatCategories(Recipe r) {
|
|
|
|
StringBuffer sb = new StringBuffer(30);
|
|
|
|
boolean first = true;
|
|
|
|
for (Category cat : r.getCategories()) {
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
sb.append(", ");
|
|
|
|
}
|
|
|
|
sb.append(cat.getCategory());
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
2021-12-29 19:30:25 +00:00
|
|
|
public String formatTime(Long ltime) {
|
|
|
|
if (ltime == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
int time = ltime.intValue();
|
|
|
|
int dd, hh, mm, ss;
|
|
|
|
ss = time % 60;
|
|
|
|
time /= 60;
|
|
|
|
mm = time % 60;
|
|
|
|
time /= 60;
|
|
|
|
hh = time % 24;
|
|
|
|
dd = time / 24;
|
|
|
|
StringBuffer sb = new StringBuffer(20);
|
|
|
|
if (dd > 0) {
|
|
|
|
sb.append(dd).append("d ");
|
|
|
|
}
|
|
|
|
if (hh > 0) {
|
|
|
|
sb.append(hh).append("h ");
|
|
|
|
}
|
|
|
|
if (mm > 0) {
|
|
|
|
sb.append(mm);
|
|
|
|
if ((ss == 0) && (hh == 0)) {
|
|
|
|
sb.append(" minutes");
|
|
|
|
} else {
|
|
|
|
sb.append("min. ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ss > 0) {
|
|
|
|
sb.append(dd).append("sec. ");
|
|
|
|
}
|
|
|
|
return sb.toString().trim();
|
|
|
|
}
|
2021-12-28 20:59:40 +00:00
|
|
|
}
|