diff --git a/alembic/versions/2022-06-01-11.12.06_ab0bae02578f_add_use_abbreviation_column_to_.py b/alembic/versions/2022-06-01-11.12.06_ab0bae02578f_add_use_abbreviation_column_to_.py new file mode 100644 index 000000000000..3f39ef0ddcba --- /dev/null +++ b/alembic/versions/2022-06-01-11.12.06_ab0bae02578f_add_use_abbreviation_column_to_.py @@ -0,0 +1,30 @@ +"""Add use_abbreviation column to ingredients + +Revision ID: ab0bae02578f +Revises: 09dfc897ad62 +Create Date: 2022-06-01 11:12:06.748383 + +""" +import sqlalchemy as sa + +from alembic import op + +# revision identifiers, used by Alembic. +revision = "ab0bae02578f" +down_revision = "09dfc897ad62" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("ingredient_units", sa.Column("use_abbreviation", sa.Boolean(), nullable=True)) + + op.execute("UPDATE ingredient_units SET use_abbreviation = FALSE WHERE use_abbreviation IS NULL") + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("ingredient_units", "use_abbreviation") + # ### end Alembic commands ### diff --git a/frontend/composables/recipes/use-recipe-ingredients.ts b/frontend/composables/recipes/use-recipe-ingredients.ts index 9d2bd06d65c3..f3600548720e 100644 --- a/frontend/composables/recipes/use-recipe-ingredients.ts +++ b/frontend/composables/recipes/use-recipe-ingredients.ts @@ -19,6 +19,8 @@ export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: let returnQty = ""; + let unitDisplay = unit?.name; + // casting to number is required as sometimes quantity is a string if (quantity && Number(quantity) !== 0) { console.log("Using Quantity", quantity, typeof quantity); @@ -34,8 +36,12 @@ export function parseIngredientText(ingredient: RecipeIngredient, disableAmount: } else { returnQty = (quantity * scale).toString(); } + + if (unit?.useAbbreviation && unit.abbreviation) { + unitDisplay = unit.abbreviation; + } } - const text = `${returnQty} ${unit?.name || " "} ${food?.name || " "} ${note || " "}`.replace(/ {2,}/g, " "); + const text = `${returnQty} ${unitDisplay || " "} ${food?.name || " "} ${note || " "}`.replace(/ {2,}/g, " "); return sanitizeIngredientHTML(text); } diff --git a/frontend/pages/group/data/units.vue b/frontend/pages/group/data/units.vue index b48d0b5937f4..37a99fa83d23 100644 --- a/frontend/pages/group/data/units.vue +++ b/frontend/pages/group/data/units.vue @@ -36,6 +36,7 @@ + @@ -106,6 +107,11 @@ Combine +