Skip to content

Commit

Permalink
Fix unit conversion #120
Browse files Browse the repository at this point in the history
  • Loading branch information
karlomikus committed Oct 11, 2023
1 parent d43cdcd commit 95043d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
29 changes: 27 additions & 2 deletions src/components/Cocktail/CocktailForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down

0 comments on commit 95043d8

Please sign in to comment.