| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container v-if="recipe"> | 
					
						
							|  |  |  |     <v-container> | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       <v-alert dismissible border="left" colored-border type="warning" elevation="2" :icon="$globals.icons.alert"> | 
					
						
							|  |  |  |         <b>Experimental Feature</b> | 
					
						
							|  |  |  |         <div> | 
					
						
							|  |  |  |           Mealie can use natural language processing to attempt to parse and create units, and foods for your Recipe | 
					
						
							|  |  |  |           ingredients. This is experimental and may not work as expected. If you choose to not use the parsed results | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |           you can select cancel and your changes will not be saved. | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </v-alert> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       <BaseCardSectionTitle title="Ingredients Processor"> | 
					
						
							|  |  |  |         To use the ingredient parser, click the "Parse All" button and the process will start. When the processed | 
					
						
							|  |  |  |         ingredients are available, you can look through the items and verify that they were parsed correctly. The models | 
					
						
							|  |  |  |         confidence score is displayed on the right of the title item. This is an average of all scores and may not be | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |         wholely accurate. | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-27 12:48:21 -09:00
										 |  |  |         <div class="my-4"> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |           Alerts will be displayed if a matching foods or unit is found but does not exists in the database. | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2022-02-27 12:48:21 -09:00
										 |  |  |         <div class="d-flex align-center mb-n4"> | 
					
						
							|  |  |  |           <div class="mb-4">Select Parser</div> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |           <BaseOverflowButton | 
					
						
							|  |  |  |             v-model="parser" | 
					
						
							| 
									
										
										
										
											2022-02-27 12:48:21 -09:00
										 |  |  |             btn-class="mx-2 mb-4" | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |             :items="[ | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 text: 'Natural Language Processor ', | 
					
						
							|  |  |  |                 value: 'nlp', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               { | 
					
						
							|  |  |  |                 text: 'Brute Parser', | 
					
						
							|  |  |  |                 value: 'brute', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ]" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </BaseCardSectionTitle> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       <div class="d-flex mt-n3 mb-4 justify-end" style="gap: 5px"> | 
					
						
							|  |  |  |         <BaseButton cancel class="mr-auto" @click="$router.go(-1)"></BaseButton> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         <BaseButton color="info" @click="fetchParsed"> | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |           <template #icon> {{ $globals.icons.foods }}</template> | 
					
						
							|  |  |  |           Parse All | 
					
						
							|  |  |  |         </BaseButton> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         <BaseButton save @click="saveAll"> Save All </BaseButton> | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       <v-expansion-panels v-model="panels" multiple> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         <v-expansion-panel v-for="(ing, index) in parsedIng" :key="index"> | 
					
						
							|  |  |  |           <v-expansion-panel-header class="my-0 py-0" disable-icon-rotate> | 
					
						
							| 
									
										
										
										
											2022-06-26 21:20:38 +02:00
										 |  |  |             <template #default="{ open }"> | 
					
						
							|  |  |  |               <v-fade-transition> | 
					
						
							|  |  |  |                 <span v-if="!open" key="0"> {{ ing.input }} </span> | 
					
						
							|  |  |  |               </v-fade-transition> | 
					
						
							|  |  |  |             </template> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |             <template #actions> | 
					
						
							|  |  |  |               <v-icon left :color="isError(ing) ? 'error' : 'success'"> | 
					
						
							|  |  |  |                 {{ isError(ing) ? $globals.icons.alert : $globals.icons.check }} | 
					
						
							|  |  |  |               </v-icon> | 
					
						
							|  |  |  |               <div class="my-auto" :color="isError(ing) ? 'error-text' : 'success-text'"> | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |                 {{ ing.confidence ? asPercentage(ing.confidence.average) : "" }} | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </template> | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |           </v-expansion-panel-header> | 
					
						
							|  |  |  |           <v-expansion-panel-content class="pb-0 mb-0"> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |             <RecipeIngredientEditor v-model="parsedIng[index].ingredient" /> | 
					
						
							| 
									
										
										
										
											2022-06-26 21:20:38 +02:00
										 |  |  |             {{ ing.input }} | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |             <v-card-actions> | 
					
						
							|  |  |  |               <v-spacer></v-spacer> | 
					
						
							|  |  |  |               <BaseButton | 
					
						
							|  |  |  |                 v-if="errors[index].foodError && errors[index].foodErrorMessage !== ''" | 
					
						
							|  |  |  |                 color="warning" | 
					
						
							|  |  |  |                 small | 
					
						
							|  |  |  |                 @click="createFood(ing.ingredient.food, index)" | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 {{ errors[index].foodErrorMessage }} | 
					
						
							|  |  |  |               </BaseButton> | 
					
						
							|  |  |  |             </v-card-actions> | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |           </v-expansion-panel-content> | 
					
						
							|  |  |  |         </v-expansion-panel> | 
					
						
							|  |  |  |       </v-expansion-panels> | 
					
						
							|  |  |  |     </v-container> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | import { defineComponent, ref, useRoute, useRouter } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | import { invoke, until } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   CreateIngredientFood, | 
					
						
							|  |  |  |   CreateIngredientUnit, | 
					
						
							|  |  |  |   IngredientFood, | 
					
						
							|  |  |  |   IngredientUnit, | 
					
						
							|  |  |  |   ParsedIngredient, | 
					
						
							| 
									
										
										
										
											2023-02-11 21:26:10 -09:00
										 |  |  |   RecipeIngredient, | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientEditor.vue"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  | import { useRecipe } from "~/composables/recipes"; | 
					
						
							|  |  |  | import { useFoodData, useFoodStore, useUnitStore } from "~/composables/store"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { Parser } from "~/lib/api/user/recipes/recipe"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | interface Error { | 
					
						
							|  |  |  |   ingredientIndex: number; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |   unitError: boolean; | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |   unitErrorMessage: string; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |   foodError: boolean; | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |   foodErrorMessage: string; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   components: { | 
					
						
							|  |  |  |     RecipeIngredientEditor, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |     const panels = ref<number[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |     const route = useRoute(); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |     const router = useRouter(); | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |     const slug = route.value.params.slug; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const { recipe, loading } = useRecipe(slug); | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |     invoke(async () => { | 
					
						
							|  |  |  |       await until(recipe).not.toBeNull(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       fetchParsed(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |     const ingredients = ref<any[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |     // =========================================================
 | 
					
						
							|  |  |  |     // Parser Logic
 | 
					
						
							|  |  |  |     const parser = ref<Parser>("nlp"); | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |     const parsedIng = ref<ParsedIngredient[]>([]); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     async function fetchParsed() { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       if (!recipe.value || !recipe.value.recipeIngredient) { | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       const raw = recipe.value.recipeIngredient.map((ing) => ing.note ?? ""); | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       const { data } = await api.recipes.parseIngredients(parser.value, raw); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							| 
									
										
										
										
											2022-06-10 21:17:51 -05:00
										 |  |  |         // When we send the recipe ingredient text to be parsed, we lose the reference to the original unparsed ingredient.
 | 
					
						
							|  |  |  |         // Generally this is fine, but if the unparsed ingredient had a title, we lose it; we add back the title for each ingredient here.
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  |           for (let i = 0; i < recipe.value.recipeIngredient.length; i++) { | 
					
						
							|  |  |  |             data[i].ingredient.title = recipe.value.recipeIngredient[i].title; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } catch (TypeError) { | 
					
						
							| 
									
										
										
										
											2022-06-26 21:20:38 +02:00
										 |  |  |           console.error("Index Mismatch Error during recipe ingredient parsing; did the number of ingredients change?"); | 
					
						
							| 
									
										
										
										
											2022-06-10 21:17:51 -05:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         parsedIng.value = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         errors.value = data.map((ing, index: number) => { | 
					
						
							|  |  |  |           const unitError = !checkForUnit(ing.ingredient.unit); | 
					
						
							|  |  |  |           const foodError = !checkForFood(ing.ingredient.food); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           let unitErrorMessage = ""; | 
					
						
							|  |  |  |           let foodErrorMessage = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if (unitError || foodError) { | 
					
						
							|  |  |  |             if (unitError) { | 
					
						
							|  |  |  |               if (ing?.ingredient?.unit?.name) { | 
					
						
							|  |  |  |                 unitErrorMessage = `Create missing unit '${ing?.ingredient?.unit?.name || "No unit"}'`; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (foodError) { | 
					
						
							|  |  |  |               if (ing?.ingredient?.food?.name) { | 
					
						
							|  |  |  |                 foodErrorMessage = `Create missing food '${ing.ingredient.food.name || "No food"}'?`; | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |           panels.value.push(index); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           return { | 
					
						
							|  |  |  |             ingredientIndex: index, | 
					
						
							|  |  |  |             unitError, | 
					
						
							|  |  |  |             unitErrorMessage, | 
					
						
							|  |  |  |             foodError, | 
					
						
							|  |  |  |             foodErrorMessage, | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function isError(ing: ParsedIngredient) { | 
					
						
							|  |  |  |       if (!ing?.confidence?.average) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       return !(ing.confidence.average >= 0.75); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |     function asPercentage(num: number | undefined): string { | 
					
						
							|  |  |  |       if (!num) { | 
					
						
							|  |  |  |         return "0%"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       return Math.round(num * 100).toFixed(2) + "%"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // =========================================================
 | 
					
						
							|  |  |  |     // Food and Ingredient Logic
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |     const foodStore = useFoodStore(); | 
					
						
							|  |  |  |     const foodData = useFoodData(); | 
					
						
							|  |  |  |     const { units } = useUnitStore(); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const errors = ref<Error[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function checkForUnit(unit?: IngredientUnit | CreateIngredientUnit) { | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       if (!unit) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       if (units.value && unit?.name) { | 
					
						
							| 
									
										
										
										
											2023-03-23 09:21:22 -08:00
										 |  |  |         const lower = unit.name.toLowerCase(); | 
					
						
							|  |  |  |         return units.value.some((u) => u.name.toLowerCase() === lower); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |     function checkForFood(food?: IngredientFood | CreateIngredientFood) { | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       if (!food) { | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       if (foodStore.foods.value && food?.name) { | 
					
						
							| 
									
										
										
										
											2023-03-23 09:21:22 -08:00
										 |  |  |         const lower = food.name.toLowerCase(); | 
					
						
							|  |  |  |         return foodStore.foods.value.some((f) => f.name.toLowerCase() === lower); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |     async function createFood(food: CreateIngredientFood | undefined, index: number) { | 
					
						
							|  |  |  |       if (!food) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       foodData.data.name = food.name; | 
					
						
							|  |  |  |       await foodStore.actions.createOne(foodData.data); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       errors.value[index].foodError = false; | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       foodData.reset(); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // =========================================================
 | 
					
						
							| 
									
										
										
										
											2023-03-23 09:21:22 -08:00
										 |  |  |     // Save All Logic
 | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |     async function saveAll() { | 
					
						
							|  |  |  |       let ingredients = parsedIng.value.map((ing) => { | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           ...ing.ingredient, | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |           originalText: ing.input, | 
					
						
							| 
									
										
										
										
											2022-03-29 18:07:01 +02:00
										 |  |  |         } as RecipeIngredient; | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       ingredients = ingredients.map((ing) => { | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |         if (!foodStore.foods.value || !units.value) { | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |           return ing; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // Get food from foods
 | 
					
						
							| 
									
										
										
										
											2023-03-23 09:21:22 -08:00
										 |  |  |         const lowerFood = ing.food?.name?.toLowerCase(); | 
					
						
							|  |  |  |         ing.food = foodStore.foods.value.find((f) => f.name.toLowerCase() === lowerFood); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Get unit from units
 | 
					
						
							| 
									
										
										
										
											2023-03-23 09:21:22 -08:00
										 |  |  |         const lowerUnit = ing.unit?.name?.toLowerCase(); | 
					
						
							|  |  |  |         ing.unit = units.value.find((u) => u.name.toLowerCase() === lowerUnit); | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         return ing; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       if (!recipe.value || !recipe.value.slug) { | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       recipe.value.recipeIngredient = ingredients; | 
					
						
							|  |  |  |       const { response } = await api.recipes.updateOne(recipe.value.slug, recipe.value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							|  |  |  |         router.push("/recipe/" + recipe.value.slug); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       parser, | 
					
						
							|  |  |  |       saveAll, | 
					
						
							|  |  |  |       createFood, | 
					
						
							|  |  |  |       errors, | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       actions: foodStore.actions, | 
					
						
							|  |  |  |       workingFoodData: foodData, | 
					
						
							| 
									
										
										
										
											2021-10-16 16:06:13 -08:00
										 |  |  |       isError, | 
					
						
							|  |  |  |       panels, | 
					
						
							|  |  |  |       asPercentage, | 
					
						
							|  |  |  |       fetchParsed, | 
					
						
							|  |  |  |       parsedIng, | 
					
						
							| 
									
										
										
										
											2021-10-09 13:08:23 -08:00
										 |  |  |       recipe, | 
					
						
							|  |  |  |       loading, | 
					
						
							|  |  |  |       ingredients, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       title: "Parser", | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |