mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
quantities are now option and can also be fractions
This commit is contained in:
@@ -109,9 +109,9 @@ public class RecipeUploadController {
|
||||
}
|
||||
|
||||
String quantityString = getListValue(form.getIngredientQuantity(), i);
|
||||
BigDecimal quantity = null;
|
||||
String quantity = null;
|
||||
if (quantityString != null && !quantityString.isBlank()) {
|
||||
quantity = new BigDecimal(quantityString.trim());
|
||||
quantity = new String(quantityString.trim());
|
||||
}
|
||||
|
||||
String unit = getListValue(form.getIngredientUnit(), i);
|
||||
@@ -119,7 +119,7 @@ public class RecipeUploadController {
|
||||
|
||||
ingredientDtos.add(new RecipeIngredientDto(
|
||||
ingredientName.trim(),
|
||||
quantity,
|
||||
quantity != null ? quantity.trim() : "",
|
||||
unit != null ? unit.trim() : "",
|
||||
notes != null ? notes.trim() : ""));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.math.BigDecimal;
|
||||
|
||||
public class RecipeIngredientDto {
|
||||
private String ingredientName;
|
||||
private BigDecimal quantity;
|
||||
private String quantity;
|
||||
private String unit;
|
||||
private String notes;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class RecipeIngredientDto {
|
||||
super();
|
||||
}
|
||||
|
||||
public RecipeIngredientDto(String ingredientName, BigDecimal quantity, String unit, String notes) {
|
||||
public RecipeIngredientDto(String ingredientName, String quantity, String unit, String notes) {
|
||||
super();
|
||||
this.ingredientName = ingredientName;
|
||||
this.quantity = quantity;
|
||||
@@ -29,11 +29,11 @@ public class RecipeIngredientDto {
|
||||
this.ingredientName = ingredientName;
|
||||
}
|
||||
|
||||
public BigDecimal getQuantity() {
|
||||
public String getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(BigDecimal quantity) {
|
||||
public void setQuantity(String quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ public class RecipeIngredient {
|
||||
@EqualsAndHashCode.Include
|
||||
private Ingredient ingredient;
|
||||
|
||||
@NotNull(message = "Please Provide a Quantity")
|
||||
@Positive(message = "Quantity cannot be negative")
|
||||
private BigDecimal quantity;
|
||||
//@NotNull(message = "Please Provide a Quantity")
|
||||
//@Positive(message = "Quantity cannot be negative")
|
||||
private String quantity;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
@Size(max = 32, message = "Unit cannot be longer than 32 characters")
|
||||
@@ -47,7 +47,7 @@ public class 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.ingredient = ingredient;
|
||||
this.quantity = quantity;
|
||||
@@ -80,11 +80,11 @@ public class RecipeIngredient {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
public BigDecimal getQuantity() {
|
||||
public String getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(BigDecimal quantity) {
|
||||
public void setQuantity(String quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,12 +60,12 @@
|
||||
</div>
|
||||
|
||||
<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">
|
||||
</div>
|
||||
|
||||
<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">
|
||||
</div>
|
||||
|
||||
@@ -379,10 +379,22 @@ function validateForm() {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!qtyInput.value.trim() || isNaN(Number(qtyInput.value)) || Number(qtyInput.value) <= 0) {
|
||||
showError(qtyInput, 'Enter a valid quantity');
|
||||
const qtyVal = qtyInput.value.trim();
|
||||
if (!isValidQuantity(qtyVal)) {
|
||||
showError(qtyInput, 'Enter a valid quantity (e.g. 2, 1.5, 1/2, 1 1/2) or leave blank');
|
||||
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')];
|
||||
|
||||
Reference in New Issue
Block a user