mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-02 04:39:54 -05:00
usable books page
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Ingredient} from "@/openapi";
|
||||
import {Ingredient, Recipe} from "@/openapi";
|
||||
|
||||
/**
|
||||
* returns a string representing an ingredient
|
||||
@@ -7,21 +7,46 @@ import {Ingredient} from "@/openapi";
|
||||
export function ingredientToString(ingredient: Ingredient) {
|
||||
let content = []
|
||||
|
||||
if(ingredient == undefined){
|
||||
if (ingredient == undefined) {
|
||||
return ''
|
||||
}
|
||||
|
||||
if(ingredient.amount != 0){
|
||||
if (ingredient.amount != 0) {
|
||||
content.push(ingredient.amount)
|
||||
}
|
||||
if(ingredient.unit){
|
||||
if (ingredient.unit) {
|
||||
content.push(ingredient.unit.name)
|
||||
}
|
||||
if(ingredient.food){
|
||||
if (ingredient.food) {
|
||||
content.push(ingredient.food.name)
|
||||
}
|
||||
if(ingredient.note){
|
||||
if (ingredient.note) {
|
||||
content.push(`(${ingredient.note})`)
|
||||
}
|
||||
return content.join(' ')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns a list of all ingredients used by the given recipe
|
||||
* @param recipe recipe to return ingredients for
|
||||
* @param t useI18N object to use for translation
|
||||
* @param options options object for list generation
|
||||
* showStepHeaders - add steps as a header ingredient if it's configured on the step
|
||||
*/
|
||||
export function getRecipeIngredients(recipe: Recipe, t: any, options: { showStepHeaders: boolean } = {showStepHeaders: false}) {
|
||||
let ingredients = [] as Ingredient[]
|
||||
recipe.steps.forEach((step, index) => {
|
||||
if (step.showAsHeader && options.showStepHeaders && recipe.steps.length > 1 && (step.ingredients.length > 0 || step.name != '')) {
|
||||
ingredients.push({
|
||||
amount: 0,
|
||||
unit: null,
|
||||
food: null,
|
||||
note: (step.name !== '') ? step.name : t('Step') + ' ' + (index + 1),
|
||||
isHeader: true
|
||||
} as Ingredient)
|
||||
}
|
||||
ingredients = ingredients.concat(step.ingredients)
|
||||
})
|
||||
return ingredients
|
||||
}
|
||||
Reference in New Issue
Block a user