From 8836a258bdb86c56de8a3d124bedf587cc20d19e Mon Sep 17 00:00:00 2001 From: Benjamin Pabst Date: Thu, 9 Jun 2022 18:01:25 +0200 Subject: [PATCH] feat: add custom scaling option (#1345) * Added custom scaling option * Allow custom scaling with no yield set * Made edit-scale translated * fixed merge conflict * Refactored scale editor to use menu * replaced vslot with # * linter issues * fixed linter issues * fixed one more linter issue * format files + minor UI changes * remove console.log * move buttons into component and setup v-model * drop servings text Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com> --- .../Domain/Recipe/RecipeScaleEditButton.vue | 102 ++++++++++++++++++ .../recipes/use-recipe-ingredients.ts | 1 - frontend/lang/messages/de-DE.json | 1 + frontend/lang/messages/en-US.json | 1 + frontend/pages/recipe/_slug/index.vue | 62 ++++++----- frontend/utils/icons/icon-type.ts | 1 + frontend/utils/icons/icons.ts | 2 + 7 files changed, 141 insertions(+), 29 deletions(-) create mode 100644 frontend/components/Domain/Recipe/RecipeScaleEditButton.vue diff --git a/frontend/components/Domain/Recipe/RecipeScaleEditButton.vue b/frontend/components/Domain/Recipe/RecipeScaleEditButton.vue new file mode 100644 index 000000000000..eb8b6f8188c0 --- /dev/null +++ b/frontend/components/Domain/Recipe/RecipeScaleEditButton.vue @@ -0,0 +1,102 @@ + + + diff --git a/frontend/composables/recipes/use-recipe-ingredients.ts b/frontend/composables/recipes/use-recipe-ingredients.ts index f3600548720e..4ee1cfd3a058 100644 --- a/frontend/composables/recipes/use-recipe-ingredients.ts +++ b/frontend/composables/recipes/use-recipe-ingredients.ts @@ -23,7 +23,6 @@ export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: // casting to number is required as sometimes quantity is a string if (quantity && Number(quantity) !== 0) { - console.log("Using Quantity", quantity, typeof quantity); if (unit?.fraction) { const fraction = frac(quantity * scale, 10, true); if (fraction[0] !== undefined && fraction[0] > 0) { diff --git a/frontend/lang/messages/de-DE.json b/frontend/lang/messages/de-DE.json index 8d3c04627c83..194f859c40ef 100644 --- a/frontend/lang/messages/de-DE.json +++ b/frontend/lang/messages/de-DE.json @@ -248,6 +248,7 @@ "description": "Beschreibung", "disable-amount": "Zutatenmenge deaktivieren", "disable-comments": "Kommentare deaktivieren", + "edit-scale": "Skalierung bearbeiten", "fat-content": "Fett", "fiber-content": "Ballaststoffe", "grams": "g", diff --git a/frontend/lang/messages/en-US.json b/frontend/lang/messages/en-US.json index c41c0cd02d4f..1b2a102ec126 100644 --- a/frontend/lang/messages/en-US.json +++ b/frontend/lang/messages/en-US.json @@ -248,6 +248,7 @@ "description": "Description", "disable-amount": "Disable Ingredient Amounts", "disable-comments": "Disable Comments", + "edit-scale": "Edit Scale", "fat-content": "Fat", "fiber-content": "Fiber", "grams": "grams", diff --git a/frontend/pages/recipe/_slug/index.vue b/frontend/pages/recipe/_slug/index.vue index 1004ba85bf14..c52d5bfec7df 100644 --- a/frontend/pages/recipe/_slug/index.vue +++ b/frontend/pages/recipe/_slug/index.vue @@ -178,38 +178,18 @@
- Reset Scale + {{ $t("recipe.edit-scale") }} - - { + const regMatchNum = /\d+/; + const yieldString = recipe.value?.recipeYield; + const num = yieldString?.match(regMatchNum); + + if (num && num?.length > 0) { + const yieldAsInt = parseInt(num[0]); + return yieldString?.replace(num[0], String(yieldAsInt)); + } + + return recipe.value?.recipeYield; + }); + async function uploadImage(fileObject: File) { if (!recipe.value || !recipe.value.slug) { return; @@ -830,6 +827,13 @@ export default defineComponent({ const drag = ref(false); + // =============================================================== + // Scale + + const setScale = (newScale: number) => { + state.scale = newScale; + }; + return { // Wake Lock drag, @@ -847,12 +851,14 @@ export default defineComponent({ enableLandscape, imageHeight, scaledYield, + basicYield, toggleJson, ...toRefs(state), recipe, api, loading, addStep, + setScale, deleteRecipe, printRecipe, closeEditor, diff --git a/frontend/utils/icons/icon-type.ts b/frontend/utils/icons/icon-type.ts index 5646cab3479f..e34a677858d0 100644 --- a/frontend/utils/icons/icon-type.ts +++ b/frontend/utils/icons/icon-type.ts @@ -90,6 +90,7 @@ export interface Icon { webhook: string; windowClose: string; zip: string; + undo: string; // Crud backArrow: string; diff --git a/frontend/utils/icons/icons.ts b/frontend/utils/icons/icons.ts index 0d1b2001afe9..afee11b860e0 100644 --- a/frontend/utils/icons/icons.ts +++ b/frontend/utils/icons/icons.ts @@ -109,6 +109,7 @@ import { mdiChartLine, mdiHelpCircleOutline, mdiDocker, + mdiUndo, } from "@mdi/js"; export const icons = { @@ -206,6 +207,7 @@ export const icons = { webhook: mdiWebhook, windowClose: mdiWindowClose, zip: mdiFolderZipOutline, + undo: mdiUndo, // Crud backArrow: mdiArrowLeftBoldOutline,