mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 13:35:23 +02:00
feat: Remove "Is Food" and "Disable Amounts" Flags (#5684)
Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
efc0d31724
commit
245ca5fe3b
49 changed files with 173 additions and 364 deletions
|
@ -79,11 +79,6 @@ const recipePreferences: Preference[] = [
|
|||
label: i18n.t("group.disable-users-from-commenting-on-recipes"),
|
||||
description: i18n.t("group.disable-users-from-commenting-on-recipes-description"),
|
||||
},
|
||||
{
|
||||
key: "recipeDisableAmount",
|
||||
label: i18n.t("group.disable-organizing-recipe-ingredients-by-units-and-food"),
|
||||
description: i18n.t("group.disable-organizing-recipe-ingredients-by-units-and-food-description"),
|
||||
},
|
||||
];
|
||||
|
||||
const allDays = [
|
||||
|
|
|
@ -130,20 +130,23 @@
|
|||
.ingredients[i]
|
||||
.checked"
|
||||
>
|
||||
<v-checkbox
|
||||
hide-details
|
||||
:model-value="ingredientData.checked"
|
||||
class="pt-0 my-auto py-auto"
|
||||
color="secondary"
|
||||
density="compact"
|
||||
/>
|
||||
<div :key="`${ingredientData.ingredient.quantity || 'no-qty'}-${i}`">
|
||||
<RecipeIngredientListItem
|
||||
:ingredient="ingredientData.ingredient"
|
||||
:disable-amount="ingredientData.disableAmount"
|
||||
:scale="recipeSection.recipeScale"
|
||||
/>
|
||||
</div>
|
||||
<v-container class="pa-0 ma-0">
|
||||
<v-row no-gutters>
|
||||
<v-checkbox
|
||||
hide-details
|
||||
:model-value="ingredientData.checked"
|
||||
class="pt-0 my-auto py-auto mr-2"
|
||||
color="secondary"
|
||||
density="compact"
|
||||
/>
|
||||
<div :key="`${ingredientData.ingredient.quantity || 'no-qty'}-${i}`" class="pa-auto my-auto">
|
||||
<RecipeIngredientListItem
|
||||
:ingredient="ingredientData.ingredient"
|
||||
:scale="recipeSection.recipeScale"
|
||||
/>
|
||||
</div>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</v-list-item>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -188,7 +191,6 @@ export interface RecipeWithScale extends Recipe {
|
|||
export interface ShoppingListIngredient {
|
||||
checked: boolean;
|
||||
ingredient: RecipeIngredient;
|
||||
disableAmount: boolean;
|
||||
}
|
||||
|
||||
export interface ShoppingListIngredientSection {
|
||||
|
@ -290,7 +292,6 @@ async function consolidateRecipesIntoSections(recipes: RecipeWithScale[]) {
|
|||
return {
|
||||
checked: !householdsWithFood.includes(userHousehold.value),
|
||||
ingredient: ing,
|
||||
disableAmount: recipe.settings?.disableAmount || false,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
class="d-flex flex-wrap my-1"
|
||||
>
|
||||
<v-col
|
||||
v-if="!disableAmount"
|
||||
sm="12"
|
||||
md="2"
|
||||
cols="12"
|
||||
|
@ -42,7 +41,6 @@
|
|||
</v-text-field>
|
||||
</v-col>
|
||||
<v-col
|
||||
v-if="!disableAmount"
|
||||
sm="12"
|
||||
md="3"
|
||||
cols="12"
|
||||
|
@ -98,7 +96,6 @@
|
|||
|
||||
<!-- Foods Input -->
|
||||
<v-col
|
||||
v-if="!disableAmount"
|
||||
m="12"
|
||||
md="3"
|
||||
cols="12"
|
||||
|
@ -166,16 +163,7 @@
|
|||
:placeholder="$t('recipe.notes')"
|
||||
class="mb-auto"
|
||||
@click="$emit('clickIngredientField', 'note')"
|
||||
>
|
||||
<template #prepend>
|
||||
<v-icon
|
||||
v-if="disableAmount && $attrs && $attrs.delete"
|
||||
class="mr-n1 handle"
|
||||
>
|
||||
{{ $globals.icons.arrowUpDown }}
|
||||
</v-icon>
|
||||
</template>
|
||||
</v-text-field>
|
||||
/>
|
||||
<BaseButtonGroup
|
||||
hover
|
||||
:large="false"
|
||||
|
@ -216,10 +204,6 @@ import type { RecipeIngredient } from "~/lib/api/types/recipe";
|
|||
const model = defineModel<RecipeIngredient>({ required: true });
|
||||
|
||||
defineProps({
|
||||
disableAmount: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
unitError: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
|
|
|
@ -34,16 +34,14 @@ import { useParsedIngredientText } from "~/composables/recipes";
|
|||
|
||||
interface Props {
|
||||
ingredient: RecipeIngredient;
|
||||
disableAmount?: boolean;
|
||||
scale?: number;
|
||||
}
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disableAmount: false,
|
||||
scale: 1,
|
||||
});
|
||||
|
||||
const parsedIng = computed(() => {
|
||||
return useParsedIngredientText(props.ingredient, props.disableAmount, props.scale);
|
||||
return useParsedIngredientText(props.ingredient, props.scale);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
<v-list-item-title>
|
||||
<RecipeIngredientListItem
|
||||
:ingredient="ingredient"
|
||||
:disable-amount="disableAmount"
|
||||
:scale="scale"
|
||||
/>
|
||||
</v-list-item-title>
|
||||
|
@ -60,13 +59,11 @@ import type { RecipeIngredient } from "~/lib/api/types/recipe";
|
|||
|
||||
interface Props {
|
||||
value?: RecipeIngredient[];
|
||||
disableAmount?: boolean;
|
||||
scale?: number;
|
||||
isCookMode?: boolean;
|
||||
}
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
value: () => [],
|
||||
disableAmount: false,
|
||||
scale: 1,
|
||||
isCookMode: false,
|
||||
});
|
||||
|
@ -89,7 +86,7 @@ const ingredientCopyText = computed(() => {
|
|||
components.push(`[${ingredient.title}]`);
|
||||
}
|
||||
|
||||
components.push(parseIngredientText(ingredient, props.disableAmount, props.scale, false));
|
||||
components.push(parseIngredientText(ingredient, props.scale, false));
|
||||
});
|
||||
|
||||
return components.join("\n");
|
||||
|
|
|
@ -141,7 +141,6 @@
|
|||
<RecipeIngredients
|
||||
:value="notLinkedIngredients"
|
||||
:scale="scale"
|
||||
:disable-amount="recipe.settings.disableAmount"
|
||||
:is-cook-mode="isCookMode"
|
||||
/>
|
||||
</v-card>
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
<!-- eslint-disable vue/no-mutating-props -->
|
||||
<template>
|
||||
<div>
|
||||
<h2 class="mb-4 text-h5 font-weight-medium opacity-80">
|
||||
{{ $t("recipe.ingredients") }}
|
||||
</h2>
|
||||
<div class="mb-4">
|
||||
<h2 class="mb-4 text-h5 font-weight-medium opacity-80">
|
||||
{{ $t("recipe.ingredients") }}
|
||||
</h2>
|
||||
<BannerWarning v-if="!hasFoodOrUnit">
|
||||
{{ $t("recipe.ingredients-not-parsed-description", { parse: $t('recipe.parse') }) }}
|
||||
</BannerWarning>
|
||||
</div>
|
||||
<VueDraggable
|
||||
v-if="recipe.recipeIngredient.length > 0"
|
||||
v-model="recipe.recipeIngredient"
|
||||
|
@ -27,7 +32,6 @@
|
|||
:key="ingredient.referenceId"
|
||||
v-model="recipe.recipeIngredient[index]"
|
||||
class="list-group-item"
|
||||
:disable-amount="recipe.settings.disableAmount"
|
||||
@delete="recipe.recipeIngredient.splice(index, 1)"
|
||||
@insert-above="insertNewIngredient(index)"
|
||||
@insert-below="insertNewIngredient(index + 1)"
|
||||
|
@ -49,7 +53,7 @@
|
|||
<span>
|
||||
<BaseButton
|
||||
class="mb-1"
|
||||
:disabled="recipe.settings.disableAmount || hasFoodOrUnit"
|
||||
:disabled="hasFoodOrUnit"
|
||||
color="accent"
|
||||
:to="`/g/${groupSlug}/r/${recipe.slug}/ingredient-parser`"
|
||||
v-bind="props"
|
||||
|
@ -109,10 +113,7 @@ const hasFoodOrUnit = computed(() => {
|
|||
});
|
||||
|
||||
const parserToolTip = computed(() => {
|
||||
if (recipe.value.settings.disableAmount) {
|
||||
return i18n.t("recipe.enable-ingredient-amounts-to-use-this-feature");
|
||||
}
|
||||
else if (hasFoodOrUnit.value) {
|
||||
if (hasFoodOrUnit.value) {
|
||||
return i18n.t("recipe.recipes-with-units-or-foods-defined-cannot-be-parsed");
|
||||
}
|
||||
return i18n.t("recipe.parse-ingredients");
|
||||
|
@ -127,7 +128,6 @@ function addIngredient(ingredients: Array<string> | null = null) {
|
|||
note: x,
|
||||
unit: undefined,
|
||||
food: undefined,
|
||||
disableAmount: true,
|
||||
quantity: 1,
|
||||
};
|
||||
});
|
||||
|
@ -146,7 +146,6 @@ function addIngredient(ingredients: Array<string> | null = null) {
|
|||
unit: undefined,
|
||||
// @ts-expect-error - prop can be null-type by NoUndefinedField type forces it to be set
|
||||
food: undefined,
|
||||
disableAmount: true,
|
||||
quantity: 1,
|
||||
});
|
||||
}
|
||||
|
@ -161,7 +160,6 @@ function insertNewIngredient(dest: number) {
|
|||
unit: undefined,
|
||||
// @ts-expect-error - prop can be null-type by NoUndefinedField type forces it to be set
|
||||
food: undefined,
|
||||
disableAmount: true,
|
||||
quantity: 1,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
<RecipeIngredients
|
||||
:value="recipe.recipeIngredient"
|
||||
:scale="scale"
|
||||
:disable-amount="recipe.settings.disableAmount"
|
||||
:is-cook-mode="isCookMode"
|
||||
/>
|
||||
<div v-if="!isEditMode && recipe.tools && recipe.tools.length > 0">
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
:value="ing.referenceId"
|
||||
>
|
||||
<template #label>
|
||||
<RecipeIngredientHtml :markup="parseIngredientText(ing, recipe.settings.disableAmount)" />
|
||||
<RecipeIngredientHtml :markup="parseIngredientText(ing)" />
|
||||
</template>
|
||||
</v-checkbox-btn>
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
|||
:value="ing.referenceId"
|
||||
>
|
||||
<template #label>
|
||||
<RecipeIngredientHtml :markup="parseIngredientText(ing, recipe.settings.disableAmount)" />
|
||||
<RecipeIngredientHtml :markup="parseIngredientText(ing)" />
|
||||
</template>
|
||||
</v-checkbox-btn>
|
||||
</template>
|
||||
|
@ -323,7 +323,6 @@
|
|||
return step.ingredientReferences.map((ref) => ref.referenceId).includes(ing.referenceId || '')
|
||||
})"
|
||||
:scale="scale"
|
||||
:disable-amount="recipe.settings.disableAmount"
|
||||
:is-cook-mode="isCookMode"
|
||||
/>
|
||||
</div>
|
||||
|
@ -552,7 +551,6 @@ function autoSetReferences() {
|
|||
props.recipe.recipeIngredient,
|
||||
activeRefs.value,
|
||||
activeText.value,
|
||||
props.recipe.settings.disableAmount,
|
||||
).forEach((ingredient: string) => activeRefs.value.push(ingredient));
|
||||
}
|
||||
|
||||
|
@ -574,7 +572,7 @@ function getIngredientByRefId(refId: string | undefined) {
|
|||
|
||||
const ing = ingredientLookup.value[refId];
|
||||
if (!ing) return "";
|
||||
return parseIngredientText(ing, props.recipe.settings.disableAmount, props.scale);
|
||||
return parseIngredientText(ing, props.scale);
|
||||
}
|
||||
|
||||
// ===============================================================
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
v-if="!isEditMode"
|
||||
v-model.number="scale"
|
||||
:recipe-servings="recipeServings"
|
||||
:edit-scale="!recipe.settings.disableAmount && !isEditMode"
|
||||
:edit-scale="hasFoodOrUnit && !isEditMode"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -24,4 +24,15 @@ const { isEditMode } = usePageState(props.recipe.slug);
|
|||
const recipeServings = computed<number>(() => {
|
||||
return props.recipe.recipeServings || props.recipe.recipeYieldQuantity || 1;
|
||||
});
|
||||
|
||||
const hasFoodOrUnit = computed(() => {
|
||||
if (props.recipe.recipeIngredient) {
|
||||
for (const ingredient of props.recipe.recipeIngredient) {
|
||||
if (ingredient.food || ingredient.unit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -321,7 +321,7 @@ const hasNotes = computed(() => {
|
|||
});
|
||||
|
||||
function parseText(ingredient: RecipeIngredient) {
|
||||
return parseIngredientText(ingredient, props.recipe.settings?.disableAmount || false, props.scale);
|
||||
return parseIngredientText(ingredient, props.scale);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ const labels: Record<keyof RecipeSettings, string> = {
|
|||
showAssets: i18n.t("asset.show-assets"),
|
||||
landscapeView: i18n.t("recipe.landscape-view-coming-soon"),
|
||||
disableComments: i18n.t("recipe.disable-comments"),
|
||||
disableAmount: i18n.t("recipe.disable-amount"),
|
||||
locked: i18n.t("recipe.locked"),
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
:class="listItem.checked ? 'strike-through' : ''"
|
||||
style="min-width: 0;"
|
||||
>
|
||||
<RecipeIngredientListItem
|
||||
:ingredient="listItem"
|
||||
:disable-amount="!(listItem.isFood || listItem.quantity !== 1)"
|
||||
/>
|
||||
<RecipeIngredientListItem :ingredient="listItem" />
|
||||
</div>
|
||||
</div>
|
||||
</v-col>
|
||||
|
@ -172,7 +169,6 @@
|
|||
@save="save"
|
||||
@cancel="toggleEdit(false)"
|
||||
@delete="$emit('delete')"
|
||||
@toggle-foods="localListItem.isFood = !localListItem.isFood"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<div>
|
||||
<v-card variant="outlined">
|
||||
<v-card-text class="pb-3 pt-1">
|
||||
<div v-if="listItem.isFood" class="d-md-flex align-center mb-2" style="gap: 20px">
|
||||
<div class="d-md-flex align-center mb-2" style="gap: 20px">
|
||||
<div>
|
||||
<InputQuantity v-model="listItem.quantity" />
|
||||
</div>
|
||||
|
@ -26,9 +26,6 @@
|
|||
/>
|
||||
</div>
|
||||
<div class="d-md-flex align-center" style="gap: 20px">
|
||||
<div v-if="!listItem.isFood">
|
||||
<InputQuantity v-model="listItem.quantity" />
|
||||
</div>
|
||||
<v-textarea
|
||||
v-model="listItem.note"
|
||||
hide-details
|
||||
|
@ -99,11 +96,6 @@
|
|||
text: $t('general.cancel'),
|
||||
event: 'cancel',
|
||||
},
|
||||
{
|
||||
icon: $globals.icons.foods,
|
||||
text: $t('shopping-list.toggle-food'),
|
||||
event: 'toggle-foods',
|
||||
},
|
||||
{
|
||||
icon: $globals.icons.save,
|
||||
text: $t('general.save'),
|
||||
|
@ -113,7 +105,6 @@
|
|||
@save="$emit('save')"
|
||||
@cancel="$emit('cancel')"
|
||||
@delete="$emit('delete')"
|
||||
@toggle-foods="listItem.isFood = !listItem.isFood"
|
||||
/>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
|
|
|
@ -18,8 +18,8 @@ function removeStartingPunctuation(word: string): string {
|
|||
return word.replace(punctuationAtBeginning, "");
|
||||
}
|
||||
|
||||
function ingredientMatchesWord(ingredient: RecipeIngredient, word: string, recipeIngredientAmountsDisabled: boolean) {
|
||||
const searchText = parseIngredientText(ingredient, recipeIngredientAmountsDisabled);
|
||||
function ingredientMatchesWord(ingredient: RecipeIngredient, word: string) {
|
||||
const searchText = parseIngredientText(ingredient);
|
||||
return searchText.toLowerCase().includes(word.toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ function isBlackListedWord(word: string) {
|
|||
return blackListedText.includes(word) || word.match(blackListedRegexMatch);
|
||||
}
|
||||
|
||||
export function useExtractIngredientReferences(recipeIngredients: RecipeIngredient[], activeRefs: string[], text: string, recipeIngredientAmountsDisabled: boolean): Set<string> {
|
||||
export function useExtractIngredientReferences(recipeIngredients: RecipeIngredient[], activeRefs: string[], text: string): Set<string> {
|
||||
const availableIngredients = recipeIngredients
|
||||
.filter(ingredient => ingredient.referenceId !== undefined)
|
||||
.filter(ingredient => !activeRefs.includes(ingredient.referenceId as string));
|
||||
|
@ -50,7 +50,7 @@ export function useExtractIngredientReferences(recipeIngredients: RecipeIngredie
|
|||
.map(normalize)
|
||||
.filter(word => word.length > 2)
|
||||
.filter(word => !isBlackListedWord(word))
|
||||
.flatMap(word => availableIngredients.filter(ingredient => ingredientMatchesWord(ingredient, word, recipeIngredientAmountsDisabled)))
|
||||
.flatMap(word => availableIngredients.filter(ingredient => ingredientMatchesWord(ingredient, word)))
|
||||
.map(ingredient => ingredient.referenceId as string);
|
||||
// deduplicate
|
||||
|
||||
|
|
|
@ -16,33 +16,27 @@ describe(parseIngredientText.name, () => {
|
|||
...overrides,
|
||||
});
|
||||
|
||||
test("uses ingredient note if disableAmount: true", () => {
|
||||
const ingredient = createRecipeIngredient({ note: "foo" });
|
||||
|
||||
expect(parseIngredientText(ingredient, true)).toEqual("foo");
|
||||
});
|
||||
|
||||
test("adds note section if note present", () => {
|
||||
const ingredient = createRecipeIngredient({ note: "custom note" });
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toContain("custom note");
|
||||
expect(parseIngredientText(ingredient)).toContain("custom note");
|
||||
});
|
||||
|
||||
test("ingredient text with fraction", () => {
|
||||
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
|
||||
|
||||
expect(parseIngredientText(ingredient, false, 1, true)).contain("1<sup>1</sup>").and.to.contain("<sub>2</sub>");
|
||||
expect(parseIngredientText(ingredient, 1, true)).contain("1<sup>1</sup>").and.to.contain("<sub>2</sub>");
|
||||
});
|
||||
|
||||
test("ingredient text with fraction when unit is null", () => {
|
||||
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: undefined });
|
||||
|
||||
expect(parseIngredientText(ingredient, false, 1, true)).contain("1<sup>1</sup>").and.to.contain("<sub>2</sub>");
|
||||
expect(parseIngredientText(ingredient, 1, true)).contain("1<sup>1</sup>").and.to.contain("<sub>2</sub>");
|
||||
});
|
||||
|
||||
test("ingredient text with fraction no formatting", () => {
|
||||
const ingredient = createRecipeIngredient({ quantity: 1.5, unit: { fraction: true, id: "1", name: "cup" } });
|
||||
const result = parseIngredientText(ingredient, false, 1, false);
|
||||
const result = parseIngredientText(ingredient, 1, false);
|
||||
|
||||
expect(result).not.contain("<");
|
||||
expect(result).not.contain(">");
|
||||
|
@ -52,7 +46,7 @@ describe(parseIngredientText.name, () => {
|
|||
test("sanitizes html", () => {
|
||||
const ingredient = createRecipeIngredient({ note: "<script>alert('foo')</script>" });
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).not.toContain("<script>");
|
||||
expect(parseIngredientText(ingredient)).not.toContain("<script>");
|
||||
});
|
||||
|
||||
test("plural test : plural qty : use abbreviation", () => {
|
||||
|
@ -62,7 +56,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("2 tbsps diced onions");
|
||||
expect(parseIngredientText(ingredient)).toEqual("2 tbsps diced onions");
|
||||
});
|
||||
|
||||
test("plural test : plural qty : not abbreviation", () => {
|
||||
|
@ -72,7 +66,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("2 tablespoons diced onions");
|
||||
expect(parseIngredientText(ingredient)).toEqual("2 tablespoons diced onions");
|
||||
});
|
||||
|
||||
test("plural test : single qty : use abbreviation", () => {
|
||||
|
@ -82,7 +76,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("1 tbsp diced onion");
|
||||
expect(parseIngredientText(ingredient)).toEqual("1 tbsp diced onion");
|
||||
});
|
||||
|
||||
test("plural test : single qty : not abbreviation", () => {
|
||||
|
@ -92,7 +86,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("1 tablespoon diced onion");
|
||||
expect(parseIngredientText(ingredient)).toEqual("1 tablespoon diced onion");
|
||||
});
|
||||
|
||||
test("plural test : small qty : use abbreviation", () => {
|
||||
|
@ -102,7 +96,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("0.5 tbsp diced onion");
|
||||
expect(parseIngredientText(ingredient)).toEqual("0.5 tbsp diced onion");
|
||||
});
|
||||
|
||||
test("plural test : small qty : not abbreviation", () => {
|
||||
|
@ -112,7 +106,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("0.5 tablespoon diced onion");
|
||||
expect(parseIngredientText(ingredient)).toEqual("0.5 tablespoon diced onion");
|
||||
});
|
||||
|
||||
test("plural test : zero qty", () => {
|
||||
|
@ -122,7 +116,7 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false)).toEqual("diced onions");
|
||||
expect(parseIngredientText(ingredient)).toEqual("diced onions");
|
||||
});
|
||||
|
||||
test("plural test : single qty, scaled", () => {
|
||||
|
@ -132,6 +126,6 @@ describe(parseIngredientText.name, () => {
|
|||
food: { id: "1", name: "diced onion", pluralName: "diced onions" },
|
||||
});
|
||||
|
||||
expect(parseIngredientText(ingredient, false, 2)).toEqual("2 tablespoons diced onions");
|
||||
expect(parseIngredientText(ingredient, 2)).toEqual("2 tablespoons diced onions");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -36,16 +36,7 @@ function useUnitName(unit: CreateIngredientUnit | IngredientUnit | undefined, us
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1, includeFormating = true) {
|
||||
if (disableAmount) {
|
||||
return {
|
||||
name: ingredient.note ? sanitizeIngredientHTML(ingredient.note) : undefined,
|
||||
quantity: undefined,
|
||||
unit: undefined,
|
||||
note: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function useParsedIngredientText(ingredient: RecipeIngredient, scale = 1, includeFormating = true) {
|
||||
const { quantity, food, unit, note } = ingredient;
|
||||
const usePluralUnit = quantity !== undefined && ((quantity || 0) * scale > 1 || (quantity || 0) * scale === 0);
|
||||
const usePluralFood = (!quantity) || quantity * scale > 1;
|
||||
|
@ -82,8 +73,8 @@ export function useParsedIngredientText(ingredient: RecipeIngredient, disableAmo
|
|||
};
|
||||
}
|
||||
|
||||
export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: boolean, scale = 1, includeFormating = true): string {
|
||||
const { quantity, unit, name, note } = useParsedIngredientText(ingredient, disableAmount, scale, includeFormating);
|
||||
export function parseIngredientText(ingredient: RecipeIngredient, scale = 1, includeFormating = true): string {
|
||||
const { quantity, unit, name, note } = useParsedIngredientText(ingredient, scale, includeFormating);
|
||||
|
||||
const text = `${quantity || ""} ${unit || ""} ${name || ""} ${note || ""}`.replace(/ {2,}/g, " ").trim();
|
||||
return sanitizeIngredientHTML(text);
|
||||
|
|
|
@ -587,6 +587,7 @@
|
|||
"api-extras-description": "Recipes extras are a key feature of the Mealie API. They allow you to create custom JSON key/value pairs within a recipe, to reference from 3rd party applications. You can use these keys to provide information, for example to trigger automations or custom messages to relay to your desired device.",
|
||||
"message-key": "Message Key",
|
||||
"parse": "Parse",
|
||||
"ingredients-not-parsed-description": "It looks like your ingredients aren't parsed yet. Click the \"{parse}\" button below to parse your ingredients into structured foods.",
|
||||
"attach-images-hint": "Attach images by dragging & dropping them into the editor",
|
||||
"drop-image": "Drop image",
|
||||
"enable-ingredient-amounts-to-use-this-feature": "Enable ingredient amounts to use this feature",
|
||||
|
|
|
@ -22,7 +22,6 @@ export interface CreateHouseholdPreferences {
|
|||
recipeShowAssets?: boolean;
|
||||
recipeLandscapeView?: boolean;
|
||||
recipeDisableComments?: boolean;
|
||||
recipeDisableAmount?: boolean;
|
||||
}
|
||||
export interface CreateInviteToken {
|
||||
uses: number;
|
||||
|
@ -191,7 +190,6 @@ export interface ReadHouseholdPreferences {
|
|||
recipeShowAssets?: boolean;
|
||||
recipeLandscapeView?: boolean;
|
||||
recipeDisableComments?: boolean;
|
||||
recipeDisableAmount?: boolean;
|
||||
id: string;
|
||||
}
|
||||
export interface HouseholdUserSummary {
|
||||
|
@ -269,7 +267,6 @@ export interface SaveHouseholdPreferences {
|
|||
recipeShowAssets?: boolean;
|
||||
recipeLandscapeView?: boolean;
|
||||
recipeDisableComments?: boolean;
|
||||
recipeDisableAmount?: boolean;
|
||||
householdId: string;
|
||||
}
|
||||
export interface SaveInviteToken {
|
||||
|
@ -303,8 +300,6 @@ export interface RecipeIngredient {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean | null;
|
||||
disableAmount?: boolean;
|
||||
display?: string;
|
||||
title?: string | null;
|
||||
originalText?: string | null;
|
||||
|
@ -409,8 +404,6 @@ export interface ShoppingListItemBase {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
shoppingListId: string;
|
||||
checked?: boolean;
|
||||
|
@ -427,8 +420,6 @@ export interface ShoppingListItemCreate {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
shoppingListId: string;
|
||||
checked?: boolean;
|
||||
|
@ -453,8 +444,6 @@ export interface ShoppingListItemOut {
|
|||
unit?: IngredientUnit | null;
|
||||
food?: IngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
shoppingListId: string;
|
||||
checked?: boolean;
|
||||
|
@ -494,8 +483,6 @@ export interface ShoppingListItemUpdate {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
shoppingListId: string;
|
||||
checked?: boolean;
|
||||
|
@ -513,8 +500,6 @@ export interface ShoppingListItemUpdateBulk {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
shoppingListId: string;
|
||||
checked?: boolean;
|
||||
|
@ -679,14 +664,11 @@ export interface UpdateHouseholdPreferences {
|
|||
recipeShowAssets?: boolean;
|
||||
recipeLandscapeView?: boolean;
|
||||
recipeDisableComments?: boolean;
|
||||
recipeDisableAmount?: boolean;
|
||||
}
|
||||
export interface RecipeIngredientBase {
|
||||
quantity?: number | null;
|
||||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean | null;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ export interface RecipeSettings {
|
|||
showAssets?: boolean;
|
||||
landscapeView?: boolean;
|
||||
disableComments?: boolean;
|
||||
disableAmount?: boolean;
|
||||
locked?: boolean;
|
||||
}
|
||||
export interface AssignTags {
|
||||
|
@ -212,8 +211,6 @@ export interface RecipeIngredient {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean | null;
|
||||
disableAmount?: boolean;
|
||||
display?: string;
|
||||
title?: string | null;
|
||||
originalText?: string | null;
|
||||
|
@ -347,8 +344,6 @@ export interface RecipeIngredientBase {
|
|||
unit?: IngredientUnit | CreateIngredientUnit | null;
|
||||
food?: IngredientFood | CreateIngredientFood | null;
|
||||
note?: string | null;
|
||||
isFood?: boolean | null;
|
||||
disableAmount?: boolean | null;
|
||||
display?: string;
|
||||
}
|
||||
export interface RecipeLastMade {
|
||||
|
|
|
@ -364,7 +364,6 @@ export default defineNuxtComponent({
|
|||
confidence: {},
|
||||
ingredient: {
|
||||
quantity: 1.0,
|
||||
disableAmount: false,
|
||||
referenceId: uuid4(),
|
||||
},
|
||||
} as ParsedIngredient;
|
||||
|
@ -409,10 +408,6 @@ export default defineNuxtComponent({
|
|||
}
|
||||
|
||||
recipe.value.recipeIngredient = ingredients;
|
||||
if (recipe.value.settings) {
|
||||
recipe.value.settings.disableAmount = false;
|
||||
}
|
||||
|
||||
const { response } = await api.recipes.updateOne(recipe.value.slug, recipe.value);
|
||||
|
||||
if (response?.status === 200) {
|
||||
|
|
|
@ -415,7 +415,6 @@ export default defineNuxtComponent({
|
|||
showAssets: false,
|
||||
landscapeView: false,
|
||||
disableComments: false,
|
||||
disableAmount: false,
|
||||
locked: false,
|
||||
});
|
||||
|
||||
|
|
|
@ -95,12 +95,6 @@ export default defineNuxtComponent({
|
|||
label: i18n.t("group.disable-users-from-commenting-on-recipes"),
|
||||
description: i18n.t("group.disable-users-from-commenting-on-recipes-description"),
|
||||
} as Preference,
|
||||
{
|
||||
key: "recipeDisableAmount",
|
||||
value: household.value.preferences.recipeDisableAmount || false,
|
||||
label: i18n.t("group.disable-organizing-recipe-ingredients-by-units-and-food"),
|
||||
description: i18n.t("group.disable-organizing-recipe-ingredients-by-units-and-food-description"),
|
||||
} as Preference,
|
||||
];
|
||||
});
|
||||
|
||||
|
|
|
@ -762,31 +762,12 @@ export default defineNuxtComponent({
|
|||
|
||||
const contextActions = {
|
||||
delete: "delete",
|
||||
setIngredient: "setIngredient",
|
||||
};
|
||||
|
||||
const contextMenu = [
|
||||
{ title: i18n.t("general.delete"), action: contextActions.delete },
|
||||
{ title: i18n.t("recipe.ingredient"), action: contextActions.setIngredient },
|
||||
];
|
||||
|
||||
function contextMenuAction(action: string, item: ShoppingListItemOut, idx: number) {
|
||||
if (!shoppingList.value?.listItems) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (action) {
|
||||
case contextActions.delete:
|
||||
shoppingList.value.listItems = shoppingList.value?.listItems.filter(itm => itm.id !== item.id);
|
||||
break;
|
||||
case contextActions.setIngredient:
|
||||
shoppingList.value.listItems[idx].isFood = !shoppingList.value.listItems[idx].isFood;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================
|
||||
// Labels, Units, Foods
|
||||
// TODO: Extract to Composable
|
||||
|
@ -901,7 +882,7 @@ export default defineNuxtComponent({
|
|||
shoppingList.value.listItems.forEach((item) => {
|
||||
const key = item.checked
|
||||
? checkedItemKey
|
||||
: item.isFood && item.food?.name
|
||||
: item.food?.name
|
||||
? item.food.name
|
||||
: item.note || "";
|
||||
|
||||
|
@ -1087,13 +1068,12 @@ export default defineNuxtComponent({
|
|||
const createEditorOpen = ref(false);
|
||||
const createListItemData = ref<ShoppingListItemOut>(listItemFactory());
|
||||
|
||||
function listItemFactory(isFood = false): ShoppingListItemOut {
|
||||
function listItemFactory(): ShoppingListItemOut {
|
||||
return {
|
||||
id: uuid4(),
|
||||
shoppingListId: id,
|
||||
checked: false,
|
||||
position: shoppingList.value?.listItems?.length || 1,
|
||||
isFood,
|
||||
quantity: 0,
|
||||
note: "",
|
||||
labelId: undefined,
|
||||
|
@ -1144,7 +1124,7 @@ export default defineNuxtComponent({
|
|||
shoppingList.value.listItems.push(createListItemData.value);
|
||||
updateListItemOrder();
|
||||
}
|
||||
createListItemData.value = listItemFactory(createListItemData.value.isFood || false);
|
||||
createListItemData.value = listItemFactory();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
@ -1217,7 +1197,6 @@ export default defineNuxtComponent({
|
|||
addRecipeReferenceToList,
|
||||
allLabels,
|
||||
contextMenu,
|
||||
contextMenuAction,
|
||||
copyListItems,
|
||||
createEditorOpen,
|
||||
createListItem,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue