quantities are now option and can also be fractions

This commit is contained in:
durn
2026-04-23 11:02:03 -06:00
parent ff3137c4b6
commit 6bafcd6f63
4 changed files with 29 additions and 17 deletions
@@ -109,9 +109,9 @@ public class RecipeUploadController {
} }
String quantityString = getListValue(form.getIngredientQuantity(), i); String quantityString = getListValue(form.getIngredientQuantity(), i);
BigDecimal quantity = null; String quantity = null;
if (quantityString != null && !quantityString.isBlank()) { if (quantityString != null && !quantityString.isBlank()) {
quantity = new BigDecimal(quantityString.trim()); quantity = new String(quantityString.trim());
} }
String unit = getListValue(form.getIngredientUnit(), i); String unit = getListValue(form.getIngredientUnit(), i);
@@ -119,7 +119,7 @@ public class RecipeUploadController {
ingredientDtos.add(new RecipeIngredientDto( ingredientDtos.add(new RecipeIngredientDto(
ingredientName.trim(), ingredientName.trim(),
quantity, quantity != null ? quantity.trim() : "",
unit != null ? unit.trim() : "", unit != null ? unit.trim() : "",
notes != null ? notes.trim() : "")); notes != null ? notes.trim() : ""));
} }
@@ -4,7 +4,7 @@ import java.math.BigDecimal;
public class RecipeIngredientDto { public class RecipeIngredientDto {
private String ingredientName; private String ingredientName;
private BigDecimal quantity; private String quantity;
private String unit; private String unit;
private String notes; private String notes;
@@ -12,7 +12,7 @@ public class RecipeIngredientDto {
super(); super();
} }
public RecipeIngredientDto(String ingredientName, BigDecimal quantity, String unit, String notes) { public RecipeIngredientDto(String ingredientName, String quantity, String unit, String notes) {
super(); super();
this.ingredientName = ingredientName; this.ingredientName = ingredientName;
this.quantity = quantity; this.quantity = quantity;
@@ -29,11 +29,11 @@ public class RecipeIngredientDto {
this.ingredientName = ingredientName; this.ingredientName = ingredientName;
} }
public BigDecimal getQuantity() { public String getQuantity() {
return quantity; return quantity;
} }
public void setQuantity(BigDecimal quantity) { public void setQuantity(String quantity) {
this.quantity = quantity; this.quantity = quantity;
} }
@@ -28,9 +28,9 @@ public class RecipeIngredient {
@EqualsAndHashCode.Include @EqualsAndHashCode.Include
private Ingredient ingredient; private Ingredient ingredient;
@NotNull(message = "Please Provide a Quantity") //@NotNull(message = "Please Provide a Quantity")
@Positive(message = "Quantity cannot be negative") //@Positive(message = "Quantity cannot be negative")
private BigDecimal quantity; private String quantity;
@Column(columnDefinition = "TEXT") @Column(columnDefinition = "TEXT")
@Size(max = 32, message = "Unit cannot be longer than 32 characters") @Size(max = 32, message = "Unit cannot be longer than 32 characters")
@@ -47,7 +47,7 @@ public class RecipeIngredient {
public RecipeIngredient() { public RecipeIngredient() {
} }
public RecipeIngredient(Recipe recipe, Ingredient ingredient, BigDecimal quantity, String unit, String notes) { public RecipeIngredient(Recipe recipe, Ingredient ingredient, String quantity, String unit, String notes) {
this.recipe = recipe; this.recipe = recipe;
this.ingredient = ingredient; this.ingredient = ingredient;
this.quantity = quantity; this.quantity = quantity;
@@ -80,11 +80,11 @@ public class RecipeIngredient {
this.ingredient = ingredient; this.ingredient = ingredient;
} }
public BigDecimal getQuantity() { public String getQuantity() {
return quantity; return quantity;
} }
public void setQuantity(BigDecimal quantity) { public void setQuantity(String quantity) {
this.quantity = quantity; this.quantity = quantity;
} }
@@ -60,12 +60,12 @@
</div> </div>
<div class="field"> <div class="field">
<label for="prep">Preparation Time: <span class="required">*</span></label> <label for="prep">Preparation Time in Minutes: <span class="required">*</span></label>
<input type="text" id="prep" placeholder="0"> <input type="text" id="prep" placeholder="0">
</div> </div>
<div class="field"> <div class="field">
<label for="cooking">Cooking Time: <span class="required">*</span></label> <label for="cooking">Cooking Time in Minutes: <span class="required">*</span></label>
<input type="text" id="cooking" placeholder="0"> <input type="text" id="cooking" placeholder="0">
</div> </div>
@@ -379,10 +379,22 @@ function validateForm() {
valid = false; valid = false;
} }
if (!qtyInput.value.trim() || isNaN(Number(qtyInput.value)) || Number(qtyInput.value) <= 0) { const qtyVal = qtyInput.value.trim();
showError(qtyInput, 'Enter a valid quantity'); if (!isValidQuantity(qtyVal)) {
showError(qtyInput, 'Enter a valid quantity (e.g. 2, 1.5, 1/2, 1 1/2) or leave blank');
valid = false; valid = false;
} }
function isValidQuantity(val) {
if (val === '') return true;
if (!isNaN(Number(val))) return true;
if (/^\d+\/\d+$/.test(val)) return true;
if (/^\d+\s+\d+\/\d+$/.test(val)) return true;
return false;
}
}); });
const stepAreas = [...document.querySelectorAll('#steps-container textarea')]; const stepAreas = [...document.querySelectorAll('#steps-container textarea')];