UI Improvements

This commit is contained in:
tim holloway 2024-09-21 13:06:32 -04:00
parent 550c4aafaf
commit e4bc1f9b7e
10 changed files with 142 additions and 38 deletions

View File

@ -25,13 +25,6 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>

11
pom.xml
View File

@ -7,7 +7,7 @@
<groupId>com.mousetech.gourmet</groupId>
<artifactId>gourmetj</artifactId>
<version>2.0.4</version>
<version>2.0.18</version>
<packaging>jar</packaging>
<name>GourmetJ</name>
@ -172,6 +172,15 @@
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>

View File

@ -1,7 +1,6 @@
package com.mousetech.gourmetj;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@ -67,14 +66,6 @@ public class AdminMainBean implements Serializable {
return cookieBean;
}
/**
* @param cookieBean the cookieBean to set.
* @deprecated Not invoked by @Inject
*/
public void setCookieBean(CookieBean cookieBean) {
this.cookieBean = cookieBean;
}
// **
@Inject
private UserSession userSession;
@ -248,6 +239,7 @@ public class AdminMainBean implements Serializable {
this.userSession.setLastEdit(null);
// Construct a blank recipe to be created.
this.userSession.setRecipe(new Recipe());
this.userSession.setDetailTab(0); // title tab
return "detailEdit?faces-redirect=true";
}

View File

@ -124,7 +124,7 @@ public class CookieBean {
// **
public Integer getDisplayListSize() {
if (!cookieMap.containsKey(KEY_DISPLAY_ROWS)) {
cookieMap.put(KEY_DISPLAY_ROWS, "30");
cookieMap.put(KEY_DISPLAY_ROWS, "0");
}
String st = cookieMap.get(KEY_DISPLAY_ROWS);
return Integer.valueOf(String.valueOf(st));

View File

@ -243,7 +243,7 @@ public class RecipeDetailBean implements Serializable {
this.shop = this.getUserSession().getShoppingList()
.contains(recipe);
log.info("Set recipe: " + this.recipe);
log.debug("Set recipe: " + this.recipe);
}
/**
@ -358,8 +358,8 @@ public class RecipeDetailBean implements Serializable {
return "";
}
String s = instructions.replace("\r\n", "<p/>")
.replace("\n\n", "<p/>");
s = s.replace("\n", "<br/>");
.replace("\n\n", "<p/>")
.replace("\n", "<br/>");
return s;
}
@ -643,7 +643,7 @@ public class RecipeDetailBean implements Serializable {
* @see #addIngredientList(String)
*/
public void addIngredient(String ingredientText) {
log.info("Ingredient line: \"" + ingredientText + "\"");
log.debug("Ingredient line: \"" + ingredientText + "\"");
Ingredient ing =
IngredientDigester.digest(ingredientText);
@ -977,7 +977,7 @@ public class RecipeDetailBean implements Serializable {
}
public void ajaxUpdateShopcat(IngredientUI item) {
log.warn("SHOPCAT2 ");
log.debug("SHOPCAT2 ");
updateShopcat(item);
}

View File

@ -1,6 +1,10 @@
package com.mousetech.gourmetj;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@ -144,6 +148,54 @@ public class UserSession implements Serializable {
return sb.toString();
}
/**
* Display source. If no "source" and there's a URL,
* use that.
*
* @param ltime
* @return
*/
public String formatSource(Recipe r) {
String s = r.getSource();
if ( s != null && ! s.isBlank()) {
return s;
}
s = r.getLink();
return urlToSource(s);
}
/**
* Take a URL and strip it of everything but
* the base domain name (including ".com")
* @param s URL string.
* @return Processed domain name.
* TestedBy: UserSessionTest
*/
String urlToSource(String s) {
if ( s == null || s.isBlank()) {
return ""; // no source, no URL
}
try {
if ( ! s.startsWith("http")) {
s = "http://" + s; // Convert to absolute URI
}
URL u = new URI(s).toURL();
String s1 = u.getHost();
if ( s1.startsWith("www.")) {
s1 = s1.substring("www.".length());
}
if ( s1.endsWith(".com")) {
// mousetech.com
s1 = s1.substring(0, s1.length() - ".com".length());
}
return s1;
} catch (MalformedURLException e) {
return s;
} catch (URISyntaxException e) {
return s;
}
}
/*
* @Deprecated Using TimeConverter.
*/

View File

@ -42,6 +42,10 @@
font-weight: bold;
background-color: green;
}
.noBorders .noBorders tr, .noBorders td {
background: none !important;
border: none !important;
}
</style>
<h:messages id="messages" />
<p:panel id="editorPanel"
@ -72,9 +76,16 @@
render="editorPanel"
/>
</p:inputText>
<p:outputLabel for="@next"
<!-- -->
<p:panel id="catPanel"
styleClass="noBorders"
style="display: flex; flex-direction: row; align-items: center;"
>
<p:outputLabel for="rcategory"
value="Category"
/>
</p:panel>
<p:panel id="catEdit" styleClass="noBorders">
<p:inputText id="rcategory"
label="Category"
value="#{recipeDetailBean.category}"
@ -97,6 +108,8 @@
value="#{recipeDetailBean.suggestCategory}"
/>
</p:selectOneMenu>
</p:panel>
<!-- -->
<p:outputLabel for="@next"
value="Cuisine"
/>
@ -126,6 +139,13 @@
converterId="com.mousetech.gourmetj.utils.TimeConverter"
/>
</p:inputText>
<p:outputLabel for="@next"
value="Servings"
/>
<p:inputText id="rserves"
max="10"
value="#{recipeDetailBean.recipe.servings}"
/>
<p:outputLabel for="@next"
value="Rating"
/>

View File

@ -98,7 +98,7 @@
/>
</p:column>
<p:column headerText="Source">
<h:outputText value="#{row.source}" />
<h:outputText value="#{userSession.formatSource(row)}" />
</p:column>
<p:column headerText="Prep Time">
<h:outputText value="#{row.preptime}"

View File

@ -45,9 +45,9 @@
columns="2" style="width: 220px;"
>
<!-- TODO: ask if we should save -->
<p:commandButton value="Back"
<p:commandButton value="Home"
ajax="false"
icon="ui-icon-arrowthick-1-w"
icon="ui-icon-home"
action="home"
immediate="true"
/>
@ -65,7 +65,11 @@
action="#{recipeDetailBean.doShop}"
update="ctlShop"
/>
<h:outputText value="" />
<p:commandButton
icon="ui-icon-wrench"
value="Edit"
action="#{recipeDetailBean.editDescription}"
/>
<p:outputLabel for="@next"
value="Categories:"
/>
@ -92,14 +96,23 @@
value="#{recipeDetailBean.recipe.cooktime}"
converter="com.mousetech.gourmetj.utils.TimeConverter"
/>
<h:outputText value="" />
<p:commandButton
icon="ui-icon-wrench"
value="Edit"
action="#{recipeDetailBean.editDescription}"
<p:outputLabel for="@next"
value="Servings:"
/>
<h:outputText
value="#{recipeDetailBean.recipe.servings}"
/>
</p:panelGrid>
</p:panelGrid>
<p:panel id="sources">
<h:outputText value="#{recipeDetailBean.recipe.source}"/>
<br/>
<h:outputLink value="#{recipeDetailBean.recipe.link}"
rendered="#{not empty recipeDetailBean.recipe.link}"
>
#{recipeDetailBean.recipe.link}
</h:outputLink>
</p:panel>
</p:panelGrid>
<!-- -->
<p:panel id="pnlInstr">

View File

@ -0,0 +1,25 @@
package com.mousetech.gourmetj;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class UserSessionTest {
@Test
void testformatSource() {
UserSession us = new UserSession();
assertEquals("mousetech",
us.urlToSource("www.mousetech.com"));
assertEquals("google",
us.urlToSource("google.com"));
assertEquals("foobar",
us.urlToSource("foobar"));
assertEquals("",
us.urlToSource("\t"));
assertEquals("",
us.urlToSource(null));
}
}