| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container fluid> | 
					
						
							|  |  |  |     <!-- Export Purge Confirmation Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="purgeExportsDialog" | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       :title="$t('data-pages.recipes.purge-exports')" | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       color="error" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							|  |  |  |       @confirm="purgeExports()" | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       <v-card-text> {{ $t('data-pages.recipes.are-you-sure-you-want-to-delete-all-export-data') }} </v-card-text> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <!-- Base Dialog Object --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       ref="domDialog" | 
					
						
							|  |  |  |       v-model="dialog.state" | 
					
						
							|  |  |  |       width="650px" | 
					
						
							|  |  |  |       :icon="dialog.icon" | 
					
						
							|  |  |  |       :title="dialog.title" | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       :submit-text="$t('general.submit')" | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       @submit="dialog.callback" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text v-if="dialog.mode == MODES.tag"> | 
					
						
							| 
									
										
										
										
											2022-06-03 20:12:32 -08:00
										 |  |  |         <RecipeOrganizerSelector v-model="toSetTags" selector-type="tags" /> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       </v-card-text> | 
					
						
							|  |  |  |       <v-card-text v-else-if="dialog.mode == MODES.category"> | 
					
						
							| 
									
										
										
										
											2022-06-03 20:12:32 -08:00
										 |  |  |         <RecipeOrganizerSelector v-model="toSetCategories" selector-type="categories" /> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       </v-card-text> | 
					
						
							|  |  |  |       <v-card-text v-else-if="dialog.mode == MODES.delete"> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         <p class="h4">{{ $t('data-pages.recipes.confirm-delete-recipes') }}</p> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         <v-card outlined> | 
					
						
							|  |  |  |           <v-virtual-scroll height="400" item-height="25" :items="selected"> | 
					
						
							|  |  |  |             <template #default="{ item }"> | 
					
						
							|  |  |  |               <v-list-item class="pb-2"> | 
					
						
							|  |  |  |                 <v-list-item-content> | 
					
						
							|  |  |  |                   <v-list-item-title>{{ item.name }}</v-list-item-title> | 
					
						
							|  |  |  |                 </v-list-item-content> | 
					
						
							|  |  |  |               </v-list-item> | 
					
						
							|  |  |  |             </template> | 
					
						
							|  |  |  |           </v-virtual-scroll> | 
					
						
							|  |  |  |         </v-card> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |       <v-card-text v-else-if="dialog.mode == MODES.export"> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         <p class="h4">{{ $t('data-pages.recipes.the-following-recipes-selected-length-will-be-exported', [selected.length]) }}</p> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         <v-card outlined> | 
					
						
							|  |  |  |           <v-virtual-scroll height="400" item-height="25" :items="selected"> | 
					
						
							|  |  |  |             <template #default="{ item }"> | 
					
						
							|  |  |  |               <v-list-item class="pb-2"> | 
					
						
							|  |  |  |                 <v-list-item-content> | 
					
						
							|  |  |  |                   <v-list-item-title>{{ item.name }}</v-list-item-title> | 
					
						
							|  |  |  |                 </v-list-item-content> | 
					
						
							|  |  |  |               </v-list-item> | 
					
						
							|  |  |  |             </template> | 
					
						
							|  |  |  |           </v-virtual-scroll> | 
					
						
							|  |  |  |         </v-card> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |       <v-card-text v-else-if="dialog.mode == MODES.updateSettings" class="px-12"> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         <p>{{ $t('data-pages.recipes.settings-chosen-explanation') }}</p> | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |         <div class="mx-auto"> | 
					
						
							|  |  |  |           <RecipeSettingsSwitches v-model="recipeSettings" /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <p class="text-center mb-0"> | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |           <i>{{ $tc('data-pages.recipes.selected-length-recipe-s-settings-will-be-updated', selected.length) }}</i> | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |         </p> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     </BaseDialog> | 
					
						
							|  |  |  |     <section> | 
					
						
							|  |  |  |       <!-- Recipe Data Table --> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       <BaseCardSectionTitle :icon="$globals.icons.primary" :title="$tc('data-pages.recipes.recipe-data')"> | 
					
						
							|  |  |  |         {{ $t('data-pages.recipes.recipe-data-description') }} | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       </BaseCardSectionTitle> | 
					
						
							|  |  |  |       <v-card-actions class="mt-n5 mb-1"> | 
					
						
							|  |  |  |         <v-menu offset-y bottom nudge-bottom="6" :close-on-content-click="false"> | 
					
						
							|  |  |  |           <template #activator="{ on, attrs }"> | 
					
						
							| 
									
										
										
										
											2022-07-31 15:31:20 -05:00
										 |  |  |             <v-btn color="accent" class="mr-2" dark v-bind="attrs" v-on="on"> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |               <v-icon left> | 
					
						
							|  |  |  |                 {{ $globals.icons.cog }} | 
					
						
							|  |  |  |               </v-icon> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |               {{ $t('data-pages.columns') }} | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |             </v-btn> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |           <v-card> | 
					
						
							|  |  |  |             <v-card-title class="py-2"> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |               <div>{{ $t('data-pages.recipes.recipe-columns') }}</div> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |             </v-card-title> | 
					
						
							|  |  |  |             <v-divider class="mx-2"></v-divider> | 
					
						
							|  |  |  |             <v-card-text class="mt-n5"> | 
					
						
							|  |  |  |               <v-checkbox | 
					
						
							| 
									
										
										
										
											2022-03-22 21:08:06 -08:00
										 |  |  |                 v-for="(_, key) in headers" | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |                 :key="key" | 
					
						
							|  |  |  |                 v-model="headers[key]" | 
					
						
							|  |  |  |                 dense | 
					
						
							|  |  |  |                 flat | 
					
						
							|  |  |  |                 inset | 
					
						
							|  |  |  |                 :label="headerLabels[key]" | 
					
						
							|  |  |  |                 hide-details | 
					
						
							|  |  |  |               ></v-checkbox> | 
					
						
							|  |  |  |             </v-card-text> | 
					
						
							|  |  |  |           </v-card> | 
					
						
							|  |  |  |         </v-menu> | 
					
						
							|  |  |  |         <BaseOverflowButton | 
					
						
							|  |  |  |           :disabled="selected.length < 1" | 
					
						
							|  |  |  |           mode="event" | 
					
						
							|  |  |  |           color="info" | 
					
						
							|  |  |  |           :items="actions" | 
					
						
							|  |  |  |           @export-selected="openDialog(MODES.export)" | 
					
						
							|  |  |  |           @tag-selected="openDialog(MODES.tag)" | 
					
						
							|  |  |  |           @categorize-selected="openDialog(MODES.category)" | 
					
						
							|  |  |  |           @delete-selected="openDialog(MODES.delete)" | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |           @update-settings="openDialog(MODES.updateSettings)" | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         > | 
					
						
							|  |  |  |         </BaseOverflowButton> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         <p v-if="selected.length > 0" class="text-caption my-auto ml-5">{{ $tc('general.selected-count', selected.length) }}</p> | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       </v-card-actions> | 
					
						
							|  |  |  |       <v-card> | 
					
						
							|  |  |  |         <RecipeDataTable v-model="selected" :loading="loading" :recipes="allRecipes" :show-headers="headers" /> | 
					
						
							|  |  |  |         <v-card-actions class="justify-end"> | 
					
						
							|  |  |  |           <BaseButton color="info"> | 
					
						
							|  |  |  |             <template #icon> | 
					
						
							|  |  |  |               {{ $globals.icons.database }} | 
					
						
							|  |  |  |             </template> | 
					
						
							| 
									
										
										
										
											2023-12-07 11:08:47 -06:00
										 |  |  |             {{ $t('general.import') }} | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |           </BaseButton> | 
					
						
							|  |  |  |           <BaseButton | 
					
						
							|  |  |  |             color="info" | 
					
						
							|  |  |  |             @click=" | 
					
						
							|  |  |  |               selectAll(); | 
					
						
							|  |  |  |               openDialog(MODES.export); | 
					
						
							|  |  |  |             " | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <template #icon> | 
					
						
							|  |  |  |               {{ $globals.icons.database }} | 
					
						
							|  |  |  |             </template> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |             {{ $t('general.export-all') }} | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |           </BaseButton> | 
					
						
							|  |  |  |         </v-card-actions> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |     </section> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <section class="mt-10"> | 
					
						
							| 
									
										
										
										
											2023-11-21 14:44:41 +00:00
										 |  |  |       <!-- Data Table --> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       <BaseCardSectionTitle :icon="$globals.icons.database" section :title="$tc('data-pages.recipes.data-exports')"> | 
					
						
							|  |  |  |         {{ $t('data-pages.recipes.data-exports-description') }} | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       </BaseCardSectionTitle> | 
					
						
							|  |  |  |       <v-card-actions class="mt-n5 mb-1"> | 
					
						
							|  |  |  |         <BaseButton delete @click="purgeExportsDialog = true"> </BaseButton> | 
					
						
							|  |  |  |       </v-card-actions> | 
					
						
							|  |  |  |       <v-card> | 
					
						
							|  |  |  |         <GroupExportData :exports="groupExports" /> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |     </section> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  | import { defineComponent, reactive, ref, useContext, onMounted } from "@nuxtjs/composition-api"; | 
					
						
							|  |  |  | import RecipeDataTable from "~/components/Domain/Recipe/RecipeDataTable.vue"; | 
					
						
							| 
									
										
										
										
											2022-06-03 20:12:32 -08:00
										 |  |  | import RecipeOrganizerSelector from "~/components/Domain/Recipe/RecipeOrganizerSelector.vue"; | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							|  |  |  | import { useRecipes, allRecipes } from "~/composables/recipes"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { Recipe, RecipeSettings } from "~/lib/api/types/recipe"; | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | import GroupExportData from "~/components/Domain/Group/GroupExportData.vue"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { GroupDataExport } from "~/lib/api/types/group"; | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  | import { MenuItem } from "~/components/global/BaseOverflowButton.vue"; | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  | import RecipeSettingsSwitches from "~/components/Domain/Recipe/RecipeSettingsSwitches.vue"; | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  | enum MODES { | 
					
						
							|  |  |  |   tag = "tag", | 
					
						
							|  |  |  |   category = "category", | 
					
						
							|  |  |  |   export = "export", | 
					
						
							|  |  |  |   delete = "delete", | 
					
						
							|  |  |  |   updateSettings = "updateSettings", | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |   components: { RecipeDataTable, RecipeOrganizerSelector, GroupExportData, RecipeSettingsSwitches }, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |   scrollToTop: true, | 
					
						
							|  |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2024-08-31 21:54:10 -05:00
										 |  |  |     const { $auth, $globals, i18n } = useContext(); | 
					
						
							|  |  |  |     const { getAllRecipes, refreshRecipes } = useRecipes(true, true, false, `householdId=${$auth.user?.householdId || ""}`); | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     const selected = ref<Recipe[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function resetAll() { | 
					
						
							|  |  |  |       selected.value = []; | 
					
						
							|  |  |  |       toSetTags.value = []; | 
					
						
							|  |  |  |       toSetCategories.value = []; | 
					
						
							|  |  |  |       loading.value = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const headers = reactive({ | 
					
						
							|  |  |  |       id: false, | 
					
						
							|  |  |  |       owner: false, | 
					
						
							|  |  |  |       tags: true, | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  |       tools: true, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       categories: true, | 
					
						
							|  |  |  |       recipeYield: false, | 
					
						
							|  |  |  |       dateAdded: false, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const headerLabels = { | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       id: i18n.t("general.id"), | 
					
						
							|  |  |  |       owner: i18n.t("general.owner"), | 
					
						
							|  |  |  |       tags: i18n.t("tag.tags"), | 
					
						
							|  |  |  |       categories: i18n.t("recipe.categories"), | 
					
						
							|  |  |  |       tools: i18n.t("tool.tools"), | 
					
						
							|  |  |  |       recipeYield: i18n.t("recipe.recipe-yield"), | 
					
						
							|  |  |  |       dateAdded: i18n.t("general.date-added"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  |     const actions: MenuItem[] = [ | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       { | 
					
						
							|  |  |  |         icon: $globals.icons.database, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.tc("export.export"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         event: "export-selected", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         icon: $globals.icons.tags, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.tc("data-pages.recipes.tag"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         event: "tag-selected", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-10-25 17:08:58 +02:00
										 |  |  |         icon: $globals.icons.categories, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.tc("data-pages.recipes.categorize"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         event: "categorize-selected", | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |       { | 
					
						
							|  |  |  |         icon: $globals.icons.cog, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.tc("data-pages.recipes.update-settings"), | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |         event: "update-settings", | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       { | 
					
						
							|  |  |  |         icon: $globals.icons.delete, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.tc("general.delete"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         event: "delete-selected", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const api = useUserApi(); | 
					
						
							|  |  |  |     const loading = ref(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // Group Exports
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const purgeExportsDialog = ref(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function purgeExports() { | 
					
						
							|  |  |  |       await api.bulk.purgeExports(); | 
					
						
							|  |  |  |       refreshExports(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const groupExports = ref<GroupDataExport[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function refreshExports() { | 
					
						
							|  |  |  |       const { data } = await api.bulk.fetchExports(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							|  |  |  |         groupExports.value = data; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onMounted(async () => { | 
					
						
							|  |  |  |       await refreshExports(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     // ===============================================================
 | 
					
						
							|  |  |  |     // All Recipes
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function selectAll() { | 
					
						
							|  |  |  |       selected.value = allRecipes.value; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function exportSelected() { | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							|  |  |  |       const { data } = await api.bulk.bulkExport({ | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |         recipes: selected.value.map((x: Recipe) => x.slug ?? ""), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         exportType: "json", | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							|  |  |  |         console.log(data); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       resetAll(); | 
					
						
							|  |  |  |       refreshExports(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const toSetTags = ref([]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function tagSelected() { | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       const recipes = selected.value.map((x: Recipe) => x.slug ?? ""); | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       await api.bulk.bulkTag({ recipes, tags: toSetTags.value }); | 
					
						
							|  |  |  |       await refreshRecipes(); | 
					
						
							|  |  |  |       resetAll(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const toSetCategories = ref([]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function categorizeSelected() { | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       const recipes = selected.value.map((x: Recipe) => x.slug ?? ""); | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       await api.bulk.bulkCategorize({ recipes, categories: toSetCategories.value }); | 
					
						
							|  |  |  |       await refreshRecipes(); | 
					
						
							|  |  |  |       resetAll(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function deleteSelected() { | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       const recipes = selected.value.map((x: Recipe) => x.slug ?? ""); | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const { response, data } = await api.bulk.bulkDelete({ recipes }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(response, data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await refreshRecipes(); | 
					
						
							|  |  |  |       resetAll(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |     const recipeSettings = reactive<RecipeSettings>({ | 
					
						
							|  |  |  |       public: false, | 
					
						
							|  |  |  |       showNutrition: false, | 
					
						
							|  |  |  |       showAssets: false, | 
					
						
							|  |  |  |       landscapeView: false, | 
					
						
							|  |  |  |       disableComments: false, | 
					
						
							|  |  |  |       disableAmount: false, | 
					
						
							|  |  |  |       locked: false, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function updateSettings() { | 
					
						
							|  |  |  |       loading.value = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const recipes = selected.value.map((x: Recipe) => x.slug ?? ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { response, data } = await api.bulk.bulkSetSettings({ recipes, settings: recipeSettings }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       console.log(response, data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await refreshRecipes(); | 
					
						
							|  |  |  |       resetAll(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     // ============================================================
 | 
					
						
							|  |  |  |     // Dialog Management
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const dialog = reactive({ | 
					
						
							|  |  |  |       state: false, | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       title: i18n.t("data-pages.recipes.tag-recipes"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       mode: MODES.tag, | 
					
						
							|  |  |  |       tag: "", | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |       callback: () => { | 
					
						
							|  |  |  |         // Stub function to be overwritten
 | 
					
						
							|  |  |  |         return Promise.resolve(); | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       icon: $globals.icons.tags, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |     function openDialog(mode: MODES) { | 
					
						
							|  |  |  |       const titles: Record<MODES, string> = { | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         [MODES.tag]: i18n.tc("data-pages.recipes.tag-recipes"), | 
					
						
							|  |  |  |         [MODES.category]: i18n.tc("data-pages.recipes.categorize-recipes"), | 
					
						
							|  |  |  |         [MODES.export]: i18n.tc("data-pages.recipes.export-recipes"), | 
					
						
							|  |  |  |         [MODES.delete]: i18n.tc("data-pages.recipes.delete-recipes"), | 
					
						
							|  |  |  |         [MODES.updateSettings]: i18n.tc("data-pages.recipes.update-settings"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |       const callbacks: Record<MODES, () => Promise<void>> = { | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         [MODES.tag]: tagSelected, | 
					
						
							|  |  |  |         [MODES.category]: categorizeSelected, | 
					
						
							|  |  |  |         [MODES.export]: exportSelected, | 
					
						
							|  |  |  |         [MODES.delete]: deleteSelected, | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |         [MODES.updateSettings]: updateSettings, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |       const icons: Record<MODES, string> = { | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         [MODES.tag]: $globals.icons.tags, | 
					
						
							| 
									
										
										
										
											2023-10-25 17:08:58 +02:00
										 |  |  |         [MODES.category]: $globals.icons.categories, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |         [MODES.export]: $globals.icons.database, | 
					
						
							|  |  |  |         [MODES.delete]: $globals.icons.delete, | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |         [MODES.updateSettings]: $globals.icons.cog, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       dialog.mode = mode; | 
					
						
							|  |  |  |       dialog.title = titles[mode]; | 
					
						
							|  |  |  |       dialog.callback = callbacks[mode]; | 
					
						
							|  |  |  |       dialog.icon = icons[mode]; | 
					
						
							|  |  |  |       dialog.state = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2022-08-14 10:37:44 -08:00
										 |  |  |       recipeSettings, | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |       selectAll, | 
					
						
							|  |  |  |       loading, | 
					
						
							|  |  |  |       actions, | 
					
						
							|  |  |  |       allRecipes, | 
					
						
							|  |  |  |       categorizeSelected, | 
					
						
							|  |  |  |       deleteSelected, | 
					
						
							|  |  |  |       dialog, | 
					
						
							|  |  |  |       exportSelected, | 
					
						
							|  |  |  |       getAllRecipes, | 
					
						
							|  |  |  |       headerLabels, | 
					
						
							|  |  |  |       headers, | 
					
						
							|  |  |  |       MODES, | 
					
						
							|  |  |  |       openDialog, | 
					
						
							|  |  |  |       selected, | 
					
						
							|  |  |  |       tagSelected, | 
					
						
							|  |  |  |       toSetCategories, | 
					
						
							|  |  |  |       toSetTags, | 
					
						
							|  |  |  |       groupExports, | 
					
						
							|  |  |  |       purgeExportsDialog, | 
					
						
							|  |  |  |       purgeExports, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       title: this.$tc("data-pages.recipes.recipe-data"), | 
					
						
							| 
									
										
										
										
											2021-12-04 14:18:46 -09:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | </script> |