From 95043d8ceec5cf42f579f44fce0f2f012d5571c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karlo=20Miku=C5=A1?= Date: Wed, 11 Oct 2023 14:17:08 +0200 Subject: [PATCH] Fix unit conversion #120 --- CHANGELOG.md | 7 ++++++ src/components/Cocktail/CocktailForm.vue | 29 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b206f93..d9940016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v2.0.4 +- Fix substitute units conversion #120 + +# v2.0.3 +- Fix meta theme color +- Fix link to shelf ingredients from shelf + # v2.0.2 - Fix missing version info in footer diff --git a/src/components/Cocktail/CocktailForm.vue b/src/components/Cocktail/CocktailForm.vue index b3128b33..285809d1 100644 --- a/src/components/Cocktail/CocktailForm.vue +++ b/src/components/Cocktail/CocktailForm.vue @@ -394,17 +394,42 @@ export default { .map((cIngredient) => { // Convert oz to ml if (cIngredient.units == 'oz') { - cIngredient.amount = Unitz.parse(`${cIngredient.amount}${cIngredient.units}`).value * 30 + cIngredient.amount = UnitHandler.oz2ml(cIngredient.amount); + if (cIngredient.amount_max) { + cIngredient.amount_max = UnitHandler.oz2ml(cIngredient.amount_max); + } cIngredient.units = 'ml' } // Convert cl to ml if (cIngredient.units == 'cl') { - cIngredient.amount = cIngredient.amount * 10 + cIngredient.amount = UnitHandler.cl2ml(cIngredient.amount); + if (cIngredient.amount_max) { + cIngredient.amount_max = UnitHandler.cl2ml(cIngredient.amount_max); + } cIngredient.units = 'ml' } cIngredient.sort = sortedIngredientList.findIndex(sortedId => sortedId == cIngredient.ingredient_id) + 1 + // Handle substitutes + cIngredient.substitutes.filter(sub => sub.units).map(sub => { + if (sub.units == 'oz') { + sub.amount = UnitHandler.oz2ml(sub.amount); + if (sub.amount_max) { + sub.amount_max = UnitHandler.oz2ml(sub.amount_max); + } + sub.units = 'ml' + } + + if (sub.units == 'cl') { + sub.amount = UnitHandler.cl2ml(sub.amount); + if (sub.amount_max) { + sub.amount_max = UnitHandler.cl2ml(sub.amount_max); + } + sub.units = 'ml' + } + }) + return cIngredient }) }