| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |   <v-container | 
					
						
							|  |  |  |     :class="{ | 
					
						
							|  |  |  |       'pa-0': $vuetify.breakpoint.smAndDown, | 
					
						
							|  |  |  |     }" | 
					
						
							|  |  |  |   > | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     <v-card v-if="skeleton" :color="`white ${false ? 'darken-2' : 'lighten-4'}`" class="pa-3"> | 
					
						
							|  |  |  |       <v-skeleton-loader class="mx-auto" height="700px" type="card"></v-skeleton-loader> | 
					
						
							|  |  |  |     </v-card> | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     <v-card v-else-if="recipe" class="d-print-none"> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       <!-- Recipe Header --> | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |       <div class="d-flex justify-end flex-wrap align-stretch"> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |         <v-card v-if="!enableLandscape" width="50%" flat class="d-flex flex-column justify-center align-center"> | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |           <v-card-text> | 
					
						
							|  |  |  |             <v-card-title class="headline pa-0 flex-column align-center"> | 
					
						
							|  |  |  |               {{ recipe.name }} | 
					
						
							|  |  |  |               <RecipeRating :key="recipe.slug" :value="recipe.rating" :name="recipe.name" :slug="recipe.slug" /> | 
					
						
							|  |  |  |             </v-card-title> | 
					
						
							|  |  |  |             <v-divider class="my-2"></v-divider> | 
					
						
							|  |  |  |             <VueMarkdown :source="recipe.description"> </VueMarkdown> | 
					
						
							|  |  |  |             <v-divider></v-divider> | 
					
						
							|  |  |  |             <div class="d-flex justify-center mt-5"> | 
					
						
							|  |  |  |               <RecipeTimeCard | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |                 class="d-flex justify-center flex-wrap" | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |                 :class="true ? undefined : 'force-bottom'" | 
					
						
							|  |  |  |                 :prep-time="recipe.prepTime" | 
					
						
							|  |  |  |                 :total-time="recipe.totalTime" | 
					
						
							|  |  |  |                 :perform-time="recipe.performTime" | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           </v-card-text> | 
					
						
							|  |  |  |         </v-card> | 
					
						
							|  |  |  |         <v-img | 
					
						
							|  |  |  |           :key="imageKey" | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |           :max-width="enableLandscape ? null : '50%'" | 
					
						
							| 
									
										
										
										
											2022-01-07 16:09:54 -05:00
										 |  |  |           :min-height="hideImage ? '50' : imageHeight" | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |           :src="recipeImage(recipe.slug, '', imageKey)" | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |           class="d-print-none" | 
					
						
							|  |  |  |           @error="hideImage = true" | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <RecipeTimeCard | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             v-if="enableLandscape" | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |             :class="true ? undefined : 'force-bottom'" | 
					
						
							|  |  |  |             :prep-time="recipe.prepTime" | 
					
						
							|  |  |  |             :total-time="recipe.totalTime" | 
					
						
							|  |  |  |             :perform-time="recipe.performTime" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         </v-img> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       <v-divider></v-divider> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       <RecipeActionMenu | 
					
						
							|  |  |  |         v-model="form" | 
					
						
							|  |  |  |         :slug="recipe.slug" | 
					
						
							| 
									
										
										
										
											2021-12-11 19:12:08 -09:00
										 |  |  |         :locked="$auth.user.id !== recipe.userId && recipe.settings.locked" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         :name="recipe.name" | 
					
						
							|  |  |  |         :logged-in="$auth.loggedIn" | 
					
						
							|  |  |  |         :open="form" | 
					
						
							| 
									
										
										
										
											2021-11-05 21:29:15 -08:00
										 |  |  |         :recipe-id="recipe.id" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         class="ml-auto" | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |         @close="closeEditor" | 
					
						
							|  |  |  |         @json="toggleJson" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         @edit=" | 
					
						
							|  |  |  |           jsonEditor = false; | 
					
						
							|  |  |  |           form = true; | 
					
						
							|  |  |  |         " | 
					
						
							|  |  |  |         @save="updateRecipe(recipe.slug, recipe)" | 
					
						
							|  |  |  |         @delete="deleteRecipe(recipe.slug)" | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |         @print="printRecipe" | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       /> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       <!--  Editors  --> | 
					
						
							|  |  |  |       <LazyRecipeJsonEditor v-if="jsonEditor" v-model="recipe" class="mt-10" :options="jsonEditorOptions" /> | 
					
						
							|  |  |  |       <div v-else> | 
					
						
							|  |  |  |         <v-card-text | 
					
						
							|  |  |  |           :class="{ | 
					
						
							|  |  |  |             'px-2': $vuetify.breakpoint.smAndDown, | 
					
						
							|  |  |  |           }" | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           <div v-if="form" class="d-flex justify-start align-center"> | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |             <RecipeImageUploadBtn class="my-1" :slug="recipe.slug" @upload="uploadImage" @refresh="imageKey++" /> | 
					
						
							| 
									
										
										
										
											2021-12-11 19:12:08 -09:00
										 |  |  |             <RecipeSettingsMenu class="my-1 mx-1" :value="recipe.settings" :is-owner="recipe.userId == $auth.user.id" @upload="uploadImage" /> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |           <!-- Recipe Title Section --> | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |           <template v-if="!form && enableLandscape"> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |             <v-card-title class="pa-0 ma-0 headline"> | 
					
						
							|  |  |  |               {{ recipe.name }} | 
					
						
							|  |  |  |             </v-card-title> | 
					
						
							|  |  |  |             <VueMarkdown :source="recipe.description"> </VueMarkdown> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |           <template v-else-if="form"> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |             <v-text-field | 
					
						
							|  |  |  |               v-model="recipe.name" | 
					
						
							|  |  |  |               class="my-3" | 
					
						
							|  |  |  |               :label="$t('recipe.recipe-name')" | 
					
						
							|  |  |  |               :rules="[validators.required]" | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |             </v-text-field> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             <div class="d-flex flex-wrap"> | 
					
						
							|  |  |  |               <v-text-field v-model="recipe.totalTime" class="mx-2" :label="$t('recipe.total-time')"></v-text-field> | 
					
						
							|  |  |  |               <v-text-field v-model="recipe.prepTime" class="mx-2" :label="$t('recipe.prep-time')"></v-text-field> | 
					
						
							|  |  |  |               <v-text-field v-model="recipe.performTime" class="mx-2" :label="$t('recipe.perform-time')"></v-text-field> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             <v-textarea v-model="recipe.description" auto-grow min-height="100" :label="$t('recipe.description')"> | 
					
						
							|  |  |  |             </v-textarea> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             <v-text-field v-model="recipe.recipeYield" dense :label="$t('recipe.servings')"> </v-text-field> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |           <!-- Advanced Editor --> | 
					
						
							|  |  |  |           <div v-if="form"> | 
					
						
							|  |  |  |             <h2 class="mb-4">{{ $t("recipe.ingredients") }}</h2> | 
					
						
							| 
									
										
										
										
											2021-11-20 14:30:38 -09:00
										 |  |  |             <draggable v-if="recipe.recipeIngredient.length > 0" v-model="recipe.recipeIngredient" handle=".handle"> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |               <RecipeIngredientEditor | 
					
						
							|  |  |  |                 v-for="(ingredient, index) in recipe.recipeIngredient" | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |                 :key="ingredient.referenceId" | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                 v-model="recipe.recipeIngredient[index]" | 
					
						
							|  |  |  |                 :disable-amount="recipe.settings.disableAmount" | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |                 @delete="recipe.recipeIngredient.splice(index, 1)" | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |               /> | 
					
						
							|  |  |  |             </draggable> | 
					
						
							| 
									
										
										
										
											2021-11-20 14:30:38 -09:00
										 |  |  |             <v-skeleton-loader v-else boilerplate elevation="2" type="list-item"> </v-skeleton-loader> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |             <div class="d-flex justify-end mt-2"> | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |               <v-tooltip top color="accent"> | 
					
						
							|  |  |  |                 <template #activator="{ on, attrs }"> | 
					
						
							|  |  |  |                   <span v-on="on"> | 
					
						
							|  |  |  |                     <BaseButton | 
					
						
							|  |  |  |                       :disabled="recipe.settings.disableAmount" | 
					
						
							|  |  |  |                       color="accent" | 
					
						
							|  |  |  |                       :to="`${recipe.slug}/ingredient-parser`" | 
					
						
							|  |  |  |                       v-bind="attrs" | 
					
						
							|  |  |  |                     > | 
					
						
							|  |  |  |                       <template #icon> | 
					
						
							|  |  |  |                         {{ $globals.icons.foods }} | 
					
						
							|  |  |  |                       </template> | 
					
						
							|  |  |  |                       Parse | 
					
						
							|  |  |  |                     </BaseButton> | 
					
						
							|  |  |  |                   </span> | 
					
						
							|  |  |  |                 </template> | 
					
						
							|  |  |  |                 <span>{{ | 
					
						
							|  |  |  |                   recipe.settings.disableAmount ? "Enable ingredient amounts to use this feature" : "Parse ingredients" | 
					
						
							|  |  |  |                 }}</span> | 
					
						
							|  |  |  |               </v-tooltip> | 
					
						
							| 
									
										
										
										
											2021-10-28 19:28:33 -08:00
										 |  |  |               <RecipeDialogBulkAdd class="ml-1 mr-1" @bulk-data="addIngredient" /> | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  |               <BaseButton @click="addIngredient"> {{ $t("general.new") }} </BaseButton> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |           <div class="d-flex justify-space-between align-center pb-3"> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             <v-tooltip v-if="!form" small top color="secondary darken-1"> | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  |               <template #activator="{ on, attrs }"> | 
					
						
							|  |  |  |                 <v-btn | 
					
						
							|  |  |  |                   v-if="recipe.recipeYield" | 
					
						
							|  |  |  |                   dense | 
					
						
							|  |  |  |                   small | 
					
						
							|  |  |  |                   :hover="false" | 
					
						
							|  |  |  |                   type="label" | 
					
						
							|  |  |  |                   :ripple="false" | 
					
						
							|  |  |  |                   elevation="0" | 
					
						
							|  |  |  |                   color="secondary darken-1" | 
					
						
							|  |  |  |                   class="rounded-sm static" | 
					
						
							|  |  |  |                   v-bind="attrs" | 
					
						
							|  |  |  |                   @click="scale = 1" | 
					
						
							|  |  |  |                   v-on="on" | 
					
						
							|  |  |  |                 > | 
					
						
							|  |  |  |                   {{ scaledYield }} | 
					
						
							|  |  |  |                 </v-btn> | 
					
						
							|  |  |  |               </template> | 
					
						
							|  |  |  |               <span> Reset Scale </span> | 
					
						
							|  |  |  |             </v-tooltip> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             <template v-if="!recipe.settings.disableAmount && !form"> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |               <v-btn color="secondary darken-1" class="mx-1" small @click="scale > 1 ? scale-- : null"> | 
					
						
							|  |  |  |                 <v-icon> | 
					
						
							|  |  |  |                   {{ $globals.icons.minus }} | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |               </v-btn> | 
					
						
							|  |  |  |               <v-btn color="secondary darken-1" small @click="scale++"> | 
					
						
							|  |  |  |                 <v-icon> | 
					
						
							|  |  |  |                   {{ $globals.icons.createAlt }} | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |               </v-btn> | 
					
						
							|  |  |  |             </template> | 
					
						
							|  |  |  |             <v-spacer></v-spacer> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |             <RecipeRating | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |               v-if="enableLandscape" | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |               :key="recipe.slug" | 
					
						
							|  |  |  |               :value="recipe.rating" | 
					
						
							|  |  |  |               :name="recipe.name" | 
					
						
							|  |  |  |               :slug="recipe.slug" | 
					
						
							|  |  |  |             /> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |           <v-row> | 
					
						
							|  |  |  |             <v-col cols="12" sm="12" md="4" lg="4"> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |               <RecipeIngredients | 
					
						
							|  |  |  |                 v-if="!form" | 
					
						
							|  |  |  |                 :value="recipe.recipeIngredient" | 
					
						
							|  |  |  |                 :scale="scale" | 
					
						
							|  |  |  |                 :disable-amount="recipe.settings.disableAmount" | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |               <!-- Recipe Tools Display --> | 
					
						
							|  |  |  |               <div v-if="!form && recipe.tools && recipe.tools.length > 0"> | 
					
						
							|  |  |  |                 <h2 class="mb-2 mt-4">Required Tools</h2> | 
					
						
							|  |  |  |                 <v-list-item v-for="(tool, index) in recipe.tools" :key="index" dense> | 
					
						
							|  |  |  |                   <v-checkbox | 
					
						
							|  |  |  |                     v-model="recipe.tools[index].onHand" | 
					
						
							|  |  |  |                     hide-details | 
					
						
							|  |  |  |                     class="pt-0 my-auto py-auto" | 
					
						
							|  |  |  |                     color="secondary" | 
					
						
							|  |  |  |                     @change="updateTool(recipe.tools[index])" | 
					
						
							|  |  |  |                   > | 
					
						
							|  |  |  |                   </v-checkbox> | 
					
						
							|  |  |  |                   <v-list-item-content> | 
					
						
							|  |  |  |                     {{ tool.name }} | 
					
						
							|  |  |  |                   </v-list-item-content> | 
					
						
							|  |  |  |                 </v-list-item> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |               <div v-if="$vuetify.breakpoint.mdAndUp" class="mt-5"> | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |                 <!-- Recipe Categories --> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                 <v-card v-if="recipe.recipeCategory.length > 0 || form" class="mt-2"> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |                   <v-card-title class="py-2"> | 
					
						
							|  |  |  |                     {{ $t("recipe.categories") }} | 
					
						
							|  |  |  |                   </v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                     <RecipeCategoryTagSelector | 
					
						
							|  |  |  |                       v-if="form" | 
					
						
							|  |  |  |                       v-model="recipe.recipeCategory" | 
					
						
							| 
									
										
										
										
											2021-10-02 22:07:29 -08:00
										 |  |  |                       :return-object="true" | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                       :show-add="true" | 
					
						
							|  |  |  |                       :show-label="false" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <RecipeChips v-else :items="recipe.recipeCategory" /> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 <!-- Recipe Tags --> | 
					
						
							|  |  |  |                 <v-card v-if="recipe.tags.length > 0 || form" class="mt-2"> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |                   <v-card-title class="py-2"> | 
					
						
							|  |  |  |                     {{ $t("tag.tags") }} | 
					
						
							|  |  |  |                   </v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text> | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                     <RecipeCategoryTagSelector | 
					
						
							|  |  |  |                       v-if="form" | 
					
						
							|  |  |  |                       v-model="recipe.tags" | 
					
						
							| 
									
										
										
										
											2021-10-02 22:07:29 -08:00
										 |  |  |                       :return-object="true" | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |                       :show-add="true" | 
					
						
							|  |  |  |                       :tag-selector="true" | 
					
						
							|  |  |  |                       :show-label="false" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <RecipeChips v-else :items="recipe.tags" :is-category="false" /> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |                 <!-- Recipe Tools Edit --> | 
					
						
							|  |  |  |                 <v-card v-if="form" class="mt-2"> | 
					
						
							|  |  |  |                   <v-card-title class="py-2"> Required Tools </v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text class="pt-0"> | 
					
						
							|  |  |  |                     <RecipeTools v-model="recipe.tools" :edit="form" /> | 
					
						
							|  |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 <RecipeNutrition | 
					
						
							|  |  |  |                   v-if="recipe.settings.showNutrition" | 
					
						
							|  |  |  |                   v-model="recipe.nutrition" | 
					
						
							|  |  |  |                   class="mt-10" | 
					
						
							|  |  |  |                   :edit="form" | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2021-12-06 17:14:14 -09:00
										 |  |  |                 <client-only> | 
					
						
							|  |  |  |                   <RecipeAssets | 
					
						
							|  |  |  |                     v-if="recipe.settings.showAssets" | 
					
						
							|  |  |  |                     v-model="recipe.assets" | 
					
						
							|  |  |  |                     :edit="form" | 
					
						
							|  |  |  |                     :slug="recipe.slug" | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 </client-only> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </v-col> | 
					
						
							|  |  |  |             <v-divider v-if="$vuetify.breakpoint.mdAndUp" class="my-divider" :vertical="true"></v-divider> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             <v-col cols="12" sm="12" md="8" lg="8"> | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |               <RecipeInstructions | 
					
						
							|  |  |  |                 v-model="recipe.recipeInstructions" | 
					
						
							|  |  |  |                 :ingredients="recipe.recipeIngredient" | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |                 :disable-amount="recipe.settings.disableAmount" | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |                 :edit="form" | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |               <div v-if="form" class="d-flex"> | 
					
						
							|  |  |  |                 <RecipeDialogBulkAdd class="ml-auto my-2 mr-1" @bulk-data="addStep" /> | 
					
						
							|  |  |  |                 <BaseButton class="my-2" @click="addStep()"> {{ $t("general.new") }}</BaseButton> | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |               <!-- TODO: Somehow fix duplicate code for mobile/desktop --> | 
					
						
							|  |  |  |               <div v-if="!$vuetify.breakpoint.mdAndUp" class="mt-5"> | 
					
						
							|  |  |  |                 <!-- Recipe Tools Edit --> | 
					
						
							|  |  |  |                 <v-card v-if="form"> | 
					
						
							|  |  |  |                   <v-card-title class="py-2"> Required Tools</v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text class="pt-0"> | 
					
						
							|  |  |  |                     <RecipeTools v-model="recipe.tools" :edit="form" /> | 
					
						
							|  |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 <!-- Recipe Categories --> | 
					
						
							|  |  |  |                 <v-card v-if="recipe.recipeCategory.length > 0 || form" class="mt-2"> | 
					
						
							|  |  |  |                   <v-card-title class="py-2"> | 
					
						
							|  |  |  |                     {{ $t("recipe.categories") }} | 
					
						
							|  |  |  |                   </v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text> | 
					
						
							|  |  |  |                     <RecipeCategoryTagSelector | 
					
						
							|  |  |  |                       v-if="form" | 
					
						
							|  |  |  |                       v-model="recipe.recipeCategory" | 
					
						
							|  |  |  |                       :return-object="true" | 
					
						
							|  |  |  |                       :show-add="true" | 
					
						
							|  |  |  |                       :show-label="false" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <RecipeChips v-else :items="recipe.recipeCategory" /> | 
					
						
							|  |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 <!-- Recipe Tags --> | 
					
						
							|  |  |  |                 <v-card v-if="recipe.tags.length > 0 || form" class="mt-2"> | 
					
						
							|  |  |  |                   <v-card-title class="py-2"> | 
					
						
							|  |  |  |                     {{ $t("tag.tags") }} | 
					
						
							|  |  |  |                   </v-card-title> | 
					
						
							|  |  |  |                   <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |                   <v-card-text> | 
					
						
							|  |  |  |                     <RecipeCategoryTagSelector | 
					
						
							|  |  |  |                       v-if="form" | 
					
						
							|  |  |  |                       v-model="recipe.tags" | 
					
						
							|  |  |  |                       :return-object="true" | 
					
						
							|  |  |  |                       :show-add="true" | 
					
						
							|  |  |  |                       :tag-selector="true" | 
					
						
							|  |  |  |                       :show-label="false" | 
					
						
							|  |  |  |                     /> | 
					
						
							|  |  |  |                     <RecipeChips v-else :items="recipe.tags" :is-category="false" /> | 
					
						
							|  |  |  |                   </v-card-text> | 
					
						
							|  |  |  |                 </v-card> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 <RecipeNutrition | 
					
						
							|  |  |  |                   v-if="recipe.settings.showNutrition" | 
					
						
							|  |  |  |                   v-model="recipe.nutrition" | 
					
						
							|  |  |  |                   class="mt-10" | 
					
						
							|  |  |  |                   :edit="form" | 
					
						
							|  |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2021-12-06 17:14:14 -09:00
										 |  |  |                 <client-only> | 
					
						
							|  |  |  |                   <RecipeAssets | 
					
						
							|  |  |  |                     v-if="recipe.settings.showAssets" | 
					
						
							|  |  |  |                     v-model="recipe.assets" | 
					
						
							|  |  |  |                     :edit="form" | 
					
						
							|  |  |  |                     :slug="recipe.slug" | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 </client-only> | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |               <RecipeNotes v-model="recipe.notes" :edit="form" /> | 
					
						
							|  |  |  |             </v-col> | 
					
						
							|  |  |  |           </v-row> | 
					
						
							| 
									
										
										
										
											2021-10-28 19:28:33 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           <v-card-actions class="justify-end"> | 
					
						
							|  |  |  |             <v-text-field | 
					
						
							|  |  |  |               v-if="form" | 
					
						
							|  |  |  |               v-model="recipe.orgURL" | 
					
						
							|  |  |  |               class="mt-10" | 
					
						
							|  |  |  |               :label="$t('recipe.original-url')" | 
					
						
							|  |  |  |             ></v-text-field> | 
					
						
							|  |  |  |             <v-btn | 
					
						
							|  |  |  |               v-else-if="recipe.orgURL" | 
					
						
							|  |  |  |               dense | 
					
						
							|  |  |  |               small | 
					
						
							|  |  |  |               :hover="false" | 
					
						
							|  |  |  |               type="label" | 
					
						
							|  |  |  |               :ripple="false" | 
					
						
							|  |  |  |               elevation="0" | 
					
						
							|  |  |  |               :href="recipe.orgURL" | 
					
						
							|  |  |  |               color="secondary darken-1" | 
					
						
							|  |  |  |               target="_blank" | 
					
						
							|  |  |  |               class="rounded-sm mr-4" | 
					
						
							|  |  |  |             > | 
					
						
							|  |  |  |               {{ $t("recipe.original-url") }} | 
					
						
							|  |  |  |             </v-btn> | 
					
						
							|  |  |  |           </v-card-actions> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |         </v-card-text> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |       <v-card v-if="form && $auth.user.advanced" flat class="ma-2 mb-2"> | 
					
						
							|  |  |  |         <v-card-title> API Extras </v-card-title> | 
					
						
							|  |  |  |         <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |         <v-card-text> | 
					
						
							|  |  |  |           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 part applications. You can use these keys to contain information to | 
					
						
							|  |  |  |           trigger automation or custom messages to relay to your desired device. | 
					
						
							|  |  |  |           <v-row v-for="(value, key) in recipe.extras" :key="key" class="mt-1"> | 
					
						
							|  |  |  |             <v-col cols="8"> | 
					
						
							|  |  |  |               <v-text-field v-model="recipe.extras[key]" dense :label="key"> | 
					
						
							|  |  |  |                 <template #prepend> | 
					
						
							|  |  |  |                   <v-btn color="error" icon class="mt-n4" @click="removeApiExtra(key)"> | 
					
						
							|  |  |  |                     <v-icon> {{ $globals.icons.delete }} </v-icon> | 
					
						
							|  |  |  |                   </v-btn> | 
					
						
							|  |  |  |                 </template> | 
					
						
							|  |  |  |               </v-text-field> | 
					
						
							|  |  |  |             </v-col> | 
					
						
							|  |  |  |           </v-row> | 
					
						
							|  |  |  |         </v-card-text> | 
					
						
							|  |  |  |         <v-card-actions class="d-flex"> | 
					
						
							|  |  |  |           <div style="max-width: 200px"> | 
					
						
							|  |  |  |             <v-text-field v-model="apiNewKey" label="Message Key"></v-text-field> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |           <BaseButton create small class="ml-5" @click="createApiExtra" /> | 
					
						
							|  |  |  |         </v-card-actions> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     </v-card> | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |     <RecipeComments | 
					
						
							|  |  |  |       v-if="recipe && !recipe.settings.disableComments && !form" | 
					
						
							|  |  |  |       v-model="recipe.comments" | 
					
						
							|  |  |  |       :slug="recipe.slug" | 
					
						
							|  |  |  |       :recipe-id="recipe.id" | 
					
						
							|  |  |  |       class="mt-4" | 
					
						
							|  |  |  |     /> | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     <RecipePrintView v-if="recipe" :recipe="recipe" /> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   </v-container> | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | </template> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  | import { | 
					
						
							|  |  |  |   computed, | 
					
						
							|  |  |  |   defineComponent, | 
					
						
							|  |  |  |   reactive, | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |   ref, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |   toRefs, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |   useContext, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |   useMeta, | 
					
						
							|  |  |  |   useRoute, | 
					
						
							|  |  |  |   useRouter, | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |   onMounted, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  | } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | // @ts-ignore
 | 
					
						
							|  |  |  | import VueMarkdown from "@adapttive/vue-markdown"; | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  | import draggable from "vuedraggable"; | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  | import { invoke, until } from "@vueuse/core"; | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  | import RecipeCategoryTagSelector from "@/components/Domain/Recipe/RecipeCategoryTagSelector.vue"; | 
					
						
							|  |  |  | import RecipeDialogBulkAdd from "@/components/Domain/Recipe//RecipeDialogBulkAdd.vue"; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  | import { useUserApi, useStaticRoutes } from "~/composables/api"; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | import { validators } from "~/composables/use-validators"; | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | import { useRecipe, useRecipeMeta } from "~/composables/recipes"; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | import RecipeActionMenu from "~/components/Domain/Recipe/RecipeActionMenu.vue"; | 
					
						
							|  |  |  | import RecipeChips from "~/components/Domain/Recipe/RecipeChips.vue"; | 
					
						
							|  |  |  | import RecipeIngredients from "~/components/Domain/Recipe/RecipeIngredients.vue"; | 
					
						
							|  |  |  | import RecipeRating from "~/components/Domain/Recipe/RecipeRating.vue"; | 
					
						
							|  |  |  | import RecipeTimeCard from "~/components/Domain/Recipe/RecipeTimeCard.vue"; | 
					
						
							|  |  |  | import RecipeNutrition from "~/components/Domain/Recipe/RecipeNutrition.vue"; | 
					
						
							|  |  |  | import RecipeInstructions from "~/components/Domain/Recipe/RecipeInstructions.vue"; | 
					
						
							|  |  |  | import RecipeNotes from "~/components/Domain/Recipe/RecipeNotes.vue"; | 
					
						
							|  |  |  | import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue"; | 
					
						
							|  |  |  | import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue"; | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  | import RecipeIngredientEditor from "~/components/Domain/Recipe/RecipeIngredientEditor.vue"; | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  | import RecipePrintView from "~/components/Domain/Recipe/RecipePrintView.vue"; | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | import RecipeTools from "~/components/Domain/Recipe/RecipeTools.vue"; | 
					
						
							|  |  |  | import RecipeComments from "~/components/Domain/Recipe/RecipeComments.vue"; | 
					
						
							| 
									
										
										
										
											2021-08-23 15:33:39 -08:00
										 |  |  | import { Recipe } from "~/types/api-types/recipe"; | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  | import { uuid4, deepCopy } from "~/composables/use-utils"; | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  | import { Tool } from "~/api/class-interfaces/tools"; | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  | import { useRouteQuery } from "~/composables/use-router"; | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   components: { | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     draggable, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     RecipeActionMenu, | 
					
						
							| 
									
										
										
										
											2021-12-06 17:14:14 -09:00
										 |  |  |     RecipeAssets: () => { | 
					
						
							|  |  |  |       if (process.client) { | 
					
						
							|  |  |  |         return import(/* webpackChunkName: "RecipeAssets" */ "~/components/Domain/Recipe/RecipeAssets.vue"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |     RecipeCategoryTagSelector, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     RecipeChips, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |     RecipeComments, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     RecipeDialogBulkAdd, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |     RecipeImageUploadBtn, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     RecipeIngredientEditor, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     RecipeIngredients, | 
					
						
							|  |  |  |     RecipeInstructions, | 
					
						
							|  |  |  |     RecipeNotes, | 
					
						
							|  |  |  |     RecipeNutrition, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     RecipePrintView, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     RecipeRating, | 
					
						
							|  |  |  |     RecipeSettingsMenu, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |     RecipeTimeCard, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |     RecipeTools, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     VueMarkdown, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |   async beforeRouteLeave(_to, _from, next) { | 
					
						
							|  |  |  |     const isSame = JSON.stringify(this.recipe) === JSON.stringify(this.originalRecipe); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     console.log({ working: this.recipe, saved: this.originalRecipe }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (this.form && !isSame) { | 
					
						
							|  |  |  |       if (window.confirm("You have unsaved changes. Do you want to save before leaving?")) { | 
					
						
							|  |  |  |         // @ts-ignore
 | 
					
						
							|  |  |  |         await this.api.recipes.updateOne(this.recipe.slug, this.recipe); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     next(); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     const route = useRoute(); | 
					
						
							|  |  |  |     const router = useRouter(); | 
					
						
							|  |  |  |     const slug = route.value.params.slug; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const api = useUserApi(); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Edit on Navigate
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const edit = useRouteQuery("edit", ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onMounted(() => { | 
					
						
							|  |  |  |       console.log("edit", edit.value); | 
					
						
							|  |  |  |       if (edit.value) { | 
					
						
							|  |  |  |         console.log("edit", edit.value); | 
					
						
							|  |  |  |         state.form = edit.value === "true"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Check Before Leaving
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const domSaveChangesDialog = ref(null); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     const state = reactive({ | 
					
						
							|  |  |  |       form: false, | 
					
						
							|  |  |  |       scale: 1, | 
					
						
							|  |  |  |       hideImage: false, | 
					
						
							|  |  |  |       imageKey: 1, | 
					
						
							|  |  |  |       loadFailed: false, | 
					
						
							|  |  |  |       skeleton: false, | 
					
						
							|  |  |  |       jsonEditor: false, | 
					
						
							|  |  |  |       jsonEditorOptions: { | 
					
						
							|  |  |  |         mode: "code", | 
					
						
							|  |  |  |         search: false, | 
					
						
							|  |  |  |         mainMenuBar: false, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const { recipe, loading, fetchRecipe } = useRecipe(slug); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-06 17:14:14 -09:00
										 |  |  |     // Manage a deep copy of the recipe so we can detect if changes have occurred and inform
 | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |     // the user if they try to navigate away from the page without saving.
 | 
					
						
							|  |  |  |     const originalRecipe = ref<Recipe | null>(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     invoke(async () => { | 
					
						
							|  |  |  |       await until(recipe).not.toBeNull(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       originalRecipe.value = deepCopy(recipe.value); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-09 16:19:23 -08:00
										 |  |  |     const { recipeImage } = useStaticRoutes(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     const { $vuetify } = useContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ===========================================================================
 | 
					
						
							|  |  |  |     // Layout Helpers
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const enableLandscape = computed(() => { | 
					
						
							|  |  |  |       const preferLandscape = recipe?.value?.settings?.landscapeView; | 
					
						
							|  |  |  |       const smallScreen = !$vuetify.breakpoint.smAndUp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (preferLandscape) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } else if (smallScreen) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return false; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     // ===========================================================================
 | 
					
						
							|  |  |  |     // Button Click Event Handlers
 | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     async function updateRecipe(slug: string, recipe: Recipe) { | 
					
						
							|  |  |  |       const { data } = await api.recipes.updateOne(slug, recipe); | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       state.form = false; | 
					
						
							| 
									
										
										
										
											2021-11-05 21:29:15 -08:00
										 |  |  |       state.jsonEditor = false; | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       if (data?.slug) { | 
					
						
							|  |  |  |         router.push("/recipe/" + data.slug); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function deleteRecipe(slug: string) { | 
					
						
							|  |  |  |       const { data } = await api.recipes.deleteOne(slug); | 
					
						
							|  |  |  |       if (data?.slug) { | 
					
						
							|  |  |  |         router.push("/"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     async function closeEditor() { | 
					
						
							|  |  |  |       state.form = false; | 
					
						
							|  |  |  |       state.jsonEditor = false; | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |       await fetchRecipe(); | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function toggleJson() { | 
					
						
							|  |  |  |       state.jsonEditor = !state.jsonEditor; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |     const scaledYield = computed(() => { | 
					
						
							|  |  |  |       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 * state.scale)); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return recipe.value?.recipeYield; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |     async function uploadImage(fileObject: File) { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       if (!recipe.value || !recipe.value.slug) { | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       const newVersion = await api.recipes.updateImage(recipe.value.slug, fileObject); | 
					
						
							|  |  |  |       if (newVersion?.data?.version) { | 
					
						
							|  |  |  |         recipe.value.image = newVersion.data.version; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       state.imageKey++; | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |     function addStep(steps: Array<string> | null = null) { | 
					
						
							|  |  |  |       if (!recipe.value?.recipeInstructions) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (steps) { | 
					
						
							|  |  |  |         const cleanedSteps = steps.map((step) => { | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |           return { id: uuid4(), text: step, title: "", ingredientReferences: [] }; | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         recipe.value.recipeInstructions.push(...cleanedSteps); | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |         recipe.value.recipeInstructions.push({ id: uuid4(), text: "", title: "", ingredientReferences: [] }); | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |     function addIngredient(ingredients: Array<string> | null = null) { | 
					
						
							|  |  |  |       if (ingredients?.length) { | 
					
						
							|  |  |  |         const newIngredients = ingredients.map((x) => { | 
					
						
							|  |  |  |           return { | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |             referenceId: uuid4(), | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |             title: "", | 
					
						
							|  |  |  |             note: x, | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |             unit: undefined, | 
					
						
							|  |  |  |             food: undefined, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |             disableAmount: true, | 
					
						
							|  |  |  |             quantity: 1, | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (newIngredients) { | 
					
						
							|  |  |  |           recipe?.value?.recipeIngredient?.push(...newIngredients); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         recipe?.value?.recipeIngredient?.push({ | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |           referenceId: uuid4(), | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |           title: "", | 
					
						
							|  |  |  |           note: "", | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |           unit: undefined, | 
					
						
							|  |  |  |           food: undefined, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |           disableAmount: true, | 
					
						
							|  |  |  |           quantity: 1, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Recipe Tools
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function updateTool(tool: Tool) { | 
					
						
							|  |  |  |       const { response } = await api.tools.updateOne(tool.id, tool); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (response?.status === 200) { | 
					
						
							|  |  |  |         console.log("Update Successful"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Recipe API Extras
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const apiNewKey = ref(""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function createApiExtra() { | 
					
						
							|  |  |  |       if (!recipe.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!recipe.value.extras) { | 
					
						
							|  |  |  |         recipe.value.extras = {}; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // check for duplicate keys
 | 
					
						
							|  |  |  |       if (Object.keys(recipe.value.extras).includes(apiNewKey.value)) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       recipe.value.extras[apiNewKey.value] = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       apiNewKey.value = ""; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function removeApiExtra(key: string) { | 
					
						
							|  |  |  |       if (!recipe.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!recipe.value.extras) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       delete recipe.value.extras[key]; | 
					
						
							|  |  |  |       recipe.value.extras = { ...recipe.value.extras }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Metadata
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |     // @ts-ignore
 | 
					
						
							|  |  |  |     const metaData = useRecipeMeta(recipe); | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-05 11:55:46 -09:00
										 |  |  |     useMeta(metaData); | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |       createApiExtra, | 
					
						
							|  |  |  |       apiNewKey, | 
					
						
							| 
									
										
										
										
											2021-11-06 14:32:55 -08:00
										 |  |  |       originalRecipe, | 
					
						
							|  |  |  |       domSaveChangesDialog, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       enableLandscape, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |       scaledYield, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       toggleJson, | 
					
						
							| 
									
										
										
										
											2021-08-27 20:05:02 -08:00
										 |  |  |       ...toRefs(state), | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       recipe, | 
					
						
							|  |  |  |       api, | 
					
						
							|  |  |  |       loading, | 
					
						
							| 
									
										
										
										
											2021-09-09 08:51:29 -08:00
										 |  |  |       addStep, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       deleteRecipe, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       closeEditor, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |       updateTool, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       updateRecipe, | 
					
						
							| 
									
										
										
										
											2021-08-03 21:38:45 -08:00
										 |  |  |       uploadImage, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       validators, | 
					
						
							| 
									
										
										
										
											2021-08-09 16:19:23 -08:00
										 |  |  |       recipeImage, | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |       addIngredient, | 
					
						
							| 
									
										
										
										
											2021-11-22 20:10:48 -09:00
										 |  |  |       removeApiExtra, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   head: {}, | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |   computed: { | 
					
						
							|  |  |  |     imageHeight() { | 
					
						
							|  |  |  |       return this.$vuetify.breakpoint.xs ? "200" : "400"; | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   methods: { | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     printRecipe() { | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  |       window.print(); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-31 14:45:28 -08:00
										 |  |  | </script> | 
					
						
							| 
									
										
										
										
											2021-08-02 22:15:11 -08:00
										 |  |  | 
 |