| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div> | 
					
						
							|  |  |  |     <!-- Create New Dialog --> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |     <BaseDialog v-model="state.createDialog" :title="$t('data-pages.labels.new-label')" :icon="$globals.icons.tags" @submit="createLabel"> | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <MultiPurposeLabel :label="createLabelData" /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         <div class="mt-4"> | 
					
						
							|  |  |  |           <v-text-field v-model="createLabelData.name" :label="$t('general.name')"> </v-text-field> | 
					
						
							|  |  |  |           <InputColor v-model="createLabelData.color" /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <!-- Edit Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="state.editDialog" | 
					
						
							|  |  |  |       :icon="$globals.icons.tags" | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |       :title="$t('data-pages.labels.edit-label')" | 
					
						
							| 
									
										
										
										
											2024-05-04 22:27:04 +02:00
										 |  |  |       :submit-icon="$globals.icons.save" | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       :submit-text="$tc('general.save')" | 
					
						
							|  |  |  |       @submit="editSaveLabel" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text v-if="editLabel"> | 
					
						
							|  |  |  |         <MultiPurposeLabel :label="editLabel" /> | 
					
						
							|  |  |  |         <div class="mt-4"> | 
					
						
							|  |  |  |           <v-text-field v-model="editLabel.name" :label="$t('general.name')"> </v-text-field> | 
					
						
							|  |  |  |           <InputColor v-model="editLabel.color" /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     <!-- Delete Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="state.deleteDialog" | 
					
						
							|  |  |  |       :title="$tc('general.confirm')" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							|  |  |  |       color="error" | 
					
						
							|  |  |  |       @confirm="deleteLabel" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							| 
									
										
										
										
											2023-11-21 15:22:36 +00:00
										 |  |  |         {{ $t("general.confirm-delete-generic") }} | 
					
						
							| 
									
										
										
										
											2024-01-04 12:00:21 +00:00
										 |  |  |         <v-row> | 
					
						
							|  |  |  |           <MultiPurposeLabel v-if="deleteTarget" class="mt-4 ml-4 mb-1" :label="deleteTarget" /> | 
					
						
							|  |  |  |         </v-row> | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |     <!-- Bulk Delete Dialog --> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="state.bulkDeleteDialog" | 
					
						
							|  |  |  |       width="650px" | 
					
						
							|  |  |  |       :title="$tc('general.confirm')" | 
					
						
							|  |  |  |       :icon="$globals.icons.alertCircle" | 
					
						
							|  |  |  |       color="error" | 
					
						
							|  |  |  |       @confirm="deleteSelected" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <p class="h4">{{ $t('general.confirm-delete-generic-items') }}</p> | 
					
						
							|  |  |  |         <v-card outlined> | 
					
						
							|  |  |  |           <v-virtual-scroll height="400" item-height="25" :items="bulkDeleteTarget"> | 
					
						
							|  |  |  |             <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> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |     <!-- Seed Dialog--> | 
					
						
							|  |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="seedDialog" | 
					
						
							|  |  |  |       :icon="$globals.icons.foods" | 
					
						
							|  |  |  |       :title="$tc('data-pages.seed-data')" | 
					
						
							|  |  |  |       @confirm="seedDatabase" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <div class="pb-2"> | 
					
						
							|  |  |  |           {{ $t("data-pages.labels.seed-dialog-text") }} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |         <v-autocomplete | 
					
						
							|  |  |  |           v-model="locale" | 
					
						
							|  |  |  |           :items="locales" | 
					
						
							|  |  |  |           item-text="name" | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |           :label="$t('data-pages.select-language')" | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |           class="my-3" | 
					
						
							|  |  |  |           hide-details | 
					
						
							|  |  |  |           outlined | 
					
						
							|  |  |  |           offset | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <template #item="{ item }"> | 
					
						
							|  |  |  |             <v-list-item-content> | 
					
						
							| 
									
										
										
										
											2022-05-25 09:38:21 -08:00
										 |  |  |               <v-list-item-title> {{ item.name }} </v-list-item-title> | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |               <v-list-item-subtitle> | 
					
						
							|  |  |  |                 {{ item.progress }}% {{ $tc("language-dialog.translated") }} | 
					
						
							|  |  |  |               </v-list-item-subtitle> | 
					
						
							|  |  |  |             </v-list-item-content> | 
					
						
							|  |  |  |           </template> | 
					
						
							|  |  |  |         </v-autocomplete> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |         <v-alert v-if="labels && labels.length > 0" type="error" class="mb-0 text-body-2"> | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |           {{ $t("data-pages.foods.seed-dialog-warning") }} | 
					
						
							|  |  |  |         </v-alert> | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-21 14:44:41 +00:00
										 |  |  |     <!-- Data Table --> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |     <BaseCardSectionTitle :icon="$globals.icons.tags" section :title="$tc('data-pages.labels.labels')"> </BaseCardSectionTitle> | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     <CrudTable | 
					
						
							|  |  |  |       :table-config="tableConfig" | 
					
						
							|  |  |  |       :headers.sync="tableHeaders" | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       :data="labels || []" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |       :bulk-actions="[{icon: $globals.icons.delete, text: $tc('general.delete'), event: 'delete-selected'}]" | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |       initial-sort="name" | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       @delete-one="deleteEventHandler" | 
					
						
							|  |  |  |       @edit-one="editEventHandler" | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |       @delete-selected="bulkDeleteEventHandler" | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     > | 
					
						
							|  |  |  |       <template #button-row> | 
					
						
							| 
									
										
										
										
											2023-11-21 15:31:05 +01:00
										 |  |  |         <BaseButton create @click="state.createDialog = true">{{ $t("general.create") }}</BaseButton> | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       </template> | 
					
						
							|  |  |  |       <template #item.name="{ item }"> | 
					
						
							|  |  |  |         <MultiPurposeLabel v-if="item" :label="item"> | 
					
						
							|  |  |  |           {{ item.name }} | 
					
						
							|  |  |  |         </MultiPurposeLabel> | 
					
						
							|  |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |       <template #button-bottom> | 
					
						
							|  |  |  |         <BaseButton @click="seedDialog = true"> | 
					
						
							|  |  |  |           <template #icon> {{ $globals.icons.database }} </template> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |           {{ $t('data-pages.seed') }} | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |         </BaseButton> | 
					
						
							|  |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     </CrudTable> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  | import { defineComponent, onMounted, reactive, ref, useContext } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  | import type { LocaleObject } from "@nuxtjs/i18n"; | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  | import { validators } from "~/composables/use-validators"; | 
					
						
							|  |  |  | import { useUserApi } from "~/composables/api"; | 
					
						
							|  |  |  | import MultiPurposeLabel from "~/components/Domain/ShoppingList/MultiPurposeLabel.vue"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { MultiPurposeLabelSummary } from "~/lib/api/types/labels"; | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  | import { useLocales } from "~/composables/use-locales"; | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  | import { useLabelData, useLabelStore } from "~/composables/store"; | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   components: { MultiPurposeLabel }, | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const userApi = useUserApi(); | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |     const { i18n } = useContext(); | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     const tableConfig = { | 
					
						
							|  |  |  |       hideColumns: true, | 
					
						
							|  |  |  |       canExport: true, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     const tableHeaders = [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.t("general.id"), | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |         value: "id", | 
					
						
							|  |  |  |         show: false, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |         text: i18n.t("general.name"), | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |         value: "name", | 
					
						
							|  |  |  |         show: true, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const state = reactive({ | 
					
						
							|  |  |  |       createDialog: false, | 
					
						
							|  |  |  |       editDialog: false, | 
					
						
							|  |  |  |       deleteDialog: false, | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |       bulkDeleteDialog: false, | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ============================================================
 | 
					
						
							|  |  |  |     // Labels
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |     const labelData = useLabelData(); | 
					
						
							|  |  |  |     const labelStore = useLabelStore(); | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Create
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function createLabel() { | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       await labelStore.actions.createOne(labelData.data); | 
					
						
							|  |  |  |       labelData.reset(); | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       state.createDialog = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Delete
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const deleteTarget = ref<MultiPurposeLabelSummary | null>(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function deleteEventHandler(item: MultiPurposeLabelSummary) { | 
					
						
							|  |  |  |       state.deleteDialog = true; | 
					
						
							|  |  |  |       deleteTarget.value = item; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function deleteLabel() { | 
					
						
							|  |  |  |       if (!deleteTarget.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       await labelStore.actions.deleteOne(deleteTarget.value.id); | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       state.deleteDialog = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |     // Bulk Delete
 | 
					
						
							|  |  |  |     const bulkDeleteTarget = ref<MultiPurposeLabelSummary[]>([]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function bulkDeleteEventHandler(selection: MultiPurposeLabelSummary[]) { | 
					
						
							|  |  |  |       bulkDeleteTarget.value = selection; | 
					
						
							|  |  |  |       state.bulkDeleteDialog = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function deleteSelected() { | 
					
						
							|  |  |  |       for (const item of bulkDeleteTarget.value) { | 
					
						
							|  |  |  |         await labelStore.actions.deleteOne(item.id); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       bulkDeleteTarget.value = []; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     // Edit
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const editLabel = ref<MultiPurposeLabelSummary | null>(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function editEventHandler(item: MultiPurposeLabelSummary) { | 
					
						
							|  |  |  |       state.editDialog = true; | 
					
						
							|  |  |  |       editLabel.value = item; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (!editLabel.value.color) { | 
					
						
							| 
									
										
										
										
											2024-09-24 09:29:06 -05:00
										 |  |  |         editLabel.value.color = "#959595"; | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function editSaveLabel() { | 
					
						
							|  |  |  |       if (!editLabel.value) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |       await labelStore.actions.updateOne(editLabel.value); | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       state.editDialog = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |     // ============================================================
 | 
					
						
							|  |  |  |     // Seed
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const seedDialog = ref(false); | 
					
						
							|  |  |  |     const locale = ref(""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-29 02:39:51 +01:00
										 |  |  |     const { locales: LOCALES, locale: currentLocale } = useLocales(); | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     onMounted(() => { | 
					
						
							|  |  |  |       locale.value = currentLocale.value; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const locales = LOCALES.filter((locale) => | 
					
						
							|  |  |  |       (i18n.locales as LocaleObject[]).map((i18nLocale) => i18nLocale.code).includes(locale.value) | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function seedDatabase() { | 
					
						
							|  |  |  |       const { data } = await userApi.seeders.labels({ locale: locale.value }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							| 
									
										
										
										
											2022-05-29 17:29:59 -08:00
										 |  |  |         labelStore.actions.refresh(); | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     return { | 
					
						
							|  |  |  |       state, | 
					
						
							|  |  |  |       tableConfig, | 
					
						
							|  |  |  |       tableHeaders, | 
					
						
							| 
									
										
										
										
											2024-09-22 09:59:20 -05:00
										 |  |  |       labels: labelStore.store, | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       validators, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-20 17:09:16 +00:00
										 |  |  |       // create
 | 
					
						
							|  |  |  |       createLabel, | 
					
						
							|  |  |  |       createLabelData: labelData.data, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // edit
 | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |       editLabel, | 
					
						
							|  |  |  |       editEventHandler, | 
					
						
							|  |  |  |       editSaveLabel, | 
					
						
							| 
									
										
										
										
											2023-11-20 17:09:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // delete
 | 
					
						
							|  |  |  |       deleteEventHandler, | 
					
						
							|  |  |  |       deleteLabel, | 
					
						
							|  |  |  |       deleteTarget, | 
					
						
							| 
									
										
										
										
											2024-02-04 19:55:14 +01:00
										 |  |  |       bulkDeleteEventHandler, | 
					
						
							|  |  |  |       deleteSelected, | 
					
						
							|  |  |  |       bulkDeleteTarget, | 
					
						
							| 
									
										
										
										
											2022-05-06 12:17:30 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Seed
 | 
					
						
							|  |  |  |       seedDatabase, | 
					
						
							|  |  |  |       locales, | 
					
						
							|  |  |  |       locale, | 
					
						
							|  |  |  |       seedDialog, | 
					
						
							| 
									
										
										
										
											2022-03-19 11:31:17 -08:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |