| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | <template> | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |   <div> | 
					
						
							|  |  |  |     <!-- Create Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-if="createTarget" | 
					
						
							|  |  |  |       v-model="dialogStates.create" | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       width="100%" | 
					
						
							|  |  |  |       max-width="1100px" | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       :icon="$globals.icons.pages" | 
					
						
							|  |  |  |       :title="$t('cookbook.create-a-cookbook')" | 
					
						
							|  |  |  |       :submit-icon="$globals.icons.save" | 
					
						
							|  |  |  |       :submit-text="$tc('general.save')" | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       :submit-disabled="!createTarget.queryFilterString" | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       @submit="actions.updateOne(createTarget)" | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       @cancel="deleteCreateTarget()" | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <CookbookEditor | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |           :key="createTargetKey" | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |           :cookbook=createTarget | 
					
						
							|  |  |  |           :actions="actions" | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							| 
									
										
										
										
											2021-09-04 20:24:32 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |     <!-- Delete Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="dialogStates.delete" | 
					
						
							|  |  |  |       :title="$t('general.delete-with-name', { name: $t('cookbook.cookbook') })" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							|  |  |  |       color="error" | 
					
						
							|  |  |  |       @confirm="deleteCookbook()" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <p>{{ $t("general.confirm-delete-generic-with-name", { name: $t('cookbook.cookbook') }) }}</p> | 
					
						
							|  |  |  |         <p v-if="deleteTarget" class="mt-4 ml-4">{{ deleteTarget.name }}</p> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <!-- Cookbook Page --> | 
					
						
							|  |  |  |     <!-- Page Title --> | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |     <v-container class="px-12"> | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       <BasePageTitle divider> | 
					
						
							|  |  |  |         <template #header> | 
					
						
							|  |  |  |           <v-img max-height="100" max-width="100" :src="require('~/static/svgs/manage-cookbooks.svg')"></v-img> | 
					
						
							|  |  |  |         </template> | 
					
						
							|  |  |  |         <template #title> {{ $t('cookbook.cookbooks') }} </template> | 
					
						
							|  |  |  |         {{ $t('cookbook.description') }} | 
					
						
							|  |  |  |       </BasePageTitle> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <!-- Create New --> | 
					
						
							|  |  |  |       <BaseButton create @click="createCookbook" /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <!-- Cookbook List --> | 
					
						
							|  |  |  |       <v-expansion-panels class="mt-2"> | 
					
						
							| 
									
										
										
										
											2024-10-24 11:24:42 -05:00
										 |  |  |         <draggable | 
					
						
							|  |  |  |           v-model="cookbooks" | 
					
						
							|  |  |  |           handle=".handle" | 
					
						
							|  |  |  |           delay="250" | 
					
						
							|  |  |  |           delay-on-touch-only | 
					
						
							|  |  |  |           style="width: 100%" | 
					
						
							|  |  |  |           @change="actions.updateOrder()" | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |           <v-expansion-panel v-for="cookbook in cookbooks" :key="cookbook.id" class="my-2 left-border rounded"> | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |             <v-expansion-panel-header disable-icon-rotate class="headline"> | 
					
						
							|  |  |  |               <div class="d-flex align-center"> | 
					
						
							|  |  |  |                 <v-icon large left> | 
					
						
							|  |  |  |                   {{ $globals.icons.pages }} | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  |                 </v-icon> | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |                 {{ cookbook.name }} | 
					
						
							| 
									
										
										
										
											2022-04-03 16:32:58 -08:00
										 |  |  |               </div> | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |               <template #actions> | 
					
						
							|  |  |  |                 <v-icon class="handle"> | 
					
						
							|  |  |  |                   {{ $globals.icons.arrowUpDown }} | 
					
						
							|  |  |  |                 </v-icon> | 
					
						
							|  |  |  |                 <v-btn icon small class="ml-2"> | 
					
						
							|  |  |  |                   <v-icon> | 
					
						
							|  |  |  |                     {{ $globals.icons.edit }} | 
					
						
							|  |  |  |                   </v-icon> | 
					
						
							|  |  |  |                 </v-btn> | 
					
						
							|  |  |  |               </template> | 
					
						
							|  |  |  |             </v-expansion-panel-header> | 
					
						
							|  |  |  |             <v-expansion-panel-content> | 
					
						
							|  |  |  |               <CookbookEditor :cookbook="cookbook" :actions="actions" :collapsable="false" @delete="deleteEventHandler" /> | 
					
						
							|  |  |  |               <v-card-actions> | 
					
						
							|  |  |  |                 <v-spacer></v-spacer> | 
					
						
							|  |  |  |                 <BaseButtonGroup | 
					
						
							|  |  |  |                   :buttons="[{ | 
					
						
							| 
									
										
										
										
											2022-01-09 21:04:24 -09:00
										 |  |  |                     icon: $globals.icons.delete, | 
					
						
							| 
									
										
										
										
											2022-04-01 09:50:31 -08:00
										 |  |  |                     text: $tc('general.delete'), | 
					
						
							| 
									
										
										
										
											2022-01-09 21:04:24 -09:00
										 |  |  |                     event: 'delete', | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                   { | 
					
						
							|  |  |  |                     icon: $globals.icons.save, | 
					
						
							| 
									
										
										
										
											2022-04-01 09:50:31 -08:00
										 |  |  |                     text: $tc('general.save'), | 
					
						
							| 
									
										
										
										
											2022-01-09 21:04:24 -09:00
										 |  |  |                     event: 'save', | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |                     disabled: !cookbook.queryFilterString | 
					
						
							| 
									
										
										
										
											2022-01-09 21:04:24 -09:00
										 |  |  |                   }, | 
					
						
							|  |  |  |                 ]" | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |                 @delete="deleteEventHandler(cookbook)" | 
					
						
							|  |  |  |                 @save="actions.updateOne(cookbook)" /> | 
					
						
							|  |  |  |               </v-card-actions> | 
					
						
							|  |  |  |             </v-expansion-panel-content> | 
					
						
							|  |  |  |           </v-expansion-panel> | 
					
						
							|  |  |  |         </draggable> | 
					
						
							|  |  |  |       </v-expansion-panels> | 
					
						
							|  |  |  |     </v-container> | 
					
						
							|  |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | </template> | 
					
						
							| 
									
										
										
										
											2022-03-23 04:54:16 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2024-02-05 11:47:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  | import { defineComponent, onBeforeUnmount, onMounted, reactive, ref } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  | import draggable from "vuedraggable"; | 
					
						
							| 
									
										
										
										
											2021-09-05 22:05:29 -08:00
										 |  |  | import { useCookbooks } from "@/composables/use-group-cookbooks"; | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  | import CookbookEditor from "~/components/Domain/Cookbook/CookbookEditor.vue"; | 
					
						
							|  |  |  | import { ReadCookBook } from "~/lib/api/types/cookbook"; | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |   components: { CookbookEditor, draggable }, | 
					
						
							| 
									
										
										
										
											2024-02-02 14:45:30 +00:00
										 |  |  |   middleware: ["auth", "group-only"], | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |     const dialogStates = reactive({ | 
					
						
							|  |  |  |       create: false, | 
					
						
							|  |  |  |       delete: false, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-09-01 21:39:40 -08:00
										 |  |  |     const { cookbooks, actions } = useCookbooks(); | 
					
						
							| 
									
										
										
										
											2024-06-26 12:41:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |     // create
 | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |     const createTargetKey = ref(0); | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |     const createTarget = ref<ReadCookBook | null>(null); | 
					
						
							|  |  |  |     async function createCookbook() { | 
					
						
							|  |  |  |       await actions.createOne().then((cookbook) => { | 
					
						
							|  |  |  |         createTarget.value = cookbook as ReadCookBook; | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |         createTargetKey.value++; | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |       dialogStates.create = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // delete
 | 
					
						
							|  |  |  |     const deleteTarget = ref<ReadCookBook | null>(null); | 
					
						
							|  |  |  |     function deleteEventHandler(item: ReadCookBook){ | 
					
						
							|  |  |  |       deleteTarget.value = item; | 
					
						
							|  |  |  |       dialogStates.delete = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     function deleteCookbook() { | 
					
						
							|  |  |  |       if (!deleteTarget.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       actions.deleteOne(deleteTarget.value.id); | 
					
						
							|  |  |  |       dialogStates.delete = false; | 
					
						
							|  |  |  |       deleteTarget.value = null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function deleteCreateTarget() { | 
					
						
							|  |  |  |       if (!createTarget.value?.id) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       actions.deleteOne(createTarget.value.id); | 
					
						
							|  |  |  |       dialogStates.create = false; | 
					
						
							|  |  |  |       createTarget.value = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     function handleUnmount() { | 
					
						
							|  |  |  |       if(!createTarget.value?.id || createTarget.value.queryFilterString) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       deleteCreateTarget(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     onMounted(() => { | 
					
						
							|  |  |  |       window.addEventListener("beforeunload", handleUnmount); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     onBeforeUnmount(() => { | 
					
						
							|  |  |  |       handleUnmount(); | 
					
						
							|  |  |  |       window.removeEventListener("beforeunload", handleUnmount); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  |     return { | 
					
						
							|  |  |  |       cookbooks, | 
					
						
							|  |  |  |       actions, | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       dialogStates, | 
					
						
							|  |  |  |       // create
 | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       createTargetKey, | 
					
						
							| 
									
										
										
										
											2024-02-04 17:15:25 +01:00
										 |  |  |       createTarget, | 
					
						
							|  |  |  |       createCookbook, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // delete
 | 
					
						
							|  |  |  |       deleteTarget, | 
					
						
							|  |  |  |       deleteEventHandler, | 
					
						
							|  |  |  |       deleteCookbook, | 
					
						
							| 
									
										
										
										
											2024-10-17 10:35:39 -05:00
										 |  |  |       deleteCreateTarget, | 
					
						
							| 
									
										
										
										
											2021-08-31 14:39:02 -08:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |       title: this.$t("cookbook.cookbooks") as string, | 
					
						
							| 
									
										
										
										
											2021-10-07 09:39:47 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-08-06 16:28:12 -08:00
										 |  |  | }); | 
					
						
							|  |  |  | </script> |