| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div class="text-center"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     <v-dialog | 
					
						
							|  |  |  |       v-model="dialog" | 
					
						
							|  |  |  |       width="800" | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <template #activator="{ props }"> | 
					
						
							|  |  |  |         <BaseButton | 
					
						
							|  |  |  |           v-bind="props" | 
					
						
							|  |  |  |           @click="inputText = inputTextProp" | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |           {{ $t("new-recipe.bulk-add") }} | 
					
						
							| 
									
										
										
										
											2021-08-23 12:24:38 -08:00
										 |  |  |         </BaseButton> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |       </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       <v-card> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-app-bar | 
					
						
							|  |  |  |           density="compact" | 
					
						
							|  |  |  |           dark | 
					
						
							|  |  |  |           color="primary" | 
					
						
							|  |  |  |           class="mb-2 position-relative left-0 top-0 w-100" | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           <v-icon | 
					
						
							|  |  |  |             size="large" | 
					
						
							|  |  |  |             start | 
					
						
							|  |  |  |           > | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             {{ $globals.icons.createAlt }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <v-toolbar-title class="headline"> | 
					
						
							|  |  |  |             {{ $t("new-recipe.bulk-add") }} | 
					
						
							|  |  |  |           </v-toolbar-title> | 
					
						
							|  |  |  |           <v-spacer /> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |         </v-app-bar> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         <v-card-text> | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |           <v-textarea | 
					
						
							|  |  |  |             v-model="inputText" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             variant="outlined" | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |             rows="12" | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |             hide-details | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |             :placeholder="$t('new-recipe.paste-in-your-recipe-data-each-line-will-be-treated-as-an-item-in-a-list')" | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           /> | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <v-divider /> | 
					
						
							|  |  |  |           <template | 
					
						
							|  |  |  |             v-for="(util) in utilities" | 
					
						
							|  |  |  |             :key="util.id" | 
					
						
							|  |  |  |           > | 
					
						
							|  |  |  |             <v-list-item | 
					
						
							|  |  |  |               density="compact" | 
					
						
							|  |  |  |               class="py-1" | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |               <v-list-item-title> | 
					
						
							|  |  |  |                 <v-list-item-subtitle class="wrap-word"> | 
					
						
							|  |  |  |                   {{ util.description }} | 
					
						
							|  |  |  |                 </v-list-item-subtitle> | 
					
						
							|  |  |  |               </v-list-item-title> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |               <BaseButton | 
					
						
							|  |  |  |                 size="small" | 
					
						
							|  |  |  |                 color="info" | 
					
						
							|  |  |  |                 @click="util.action" | 
					
						
							|  |  |  |               > | 
					
						
							|  |  |  |                 <template #icon> | 
					
						
							|  |  |  |                   {{ $globals.icons.robot }} | 
					
						
							|  |  |  |                 </template> | 
					
						
							| 
									
										
										
										
											2022-08-10 07:12:45 +02:00
										 |  |  |                 {{ $t("general.run") }} | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |               </BaseButton> | 
					
						
							|  |  |  |             </v-list-item> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |             <v-divider class="mx-2" /> | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |           </template> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |         </v-card-text> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         <v-divider /> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         <v-card-actions> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |           <BaseButton | 
					
						
							|  |  |  |             cancel | 
					
						
							|  |  |  |             @click="dialog = false" | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |           <v-spacer /> | 
					
						
							|  |  |  |           <BaseButton | 
					
						
							|  |  |  |             save | 
					
						
							|  |  |  |             color="success" | 
					
						
							|  |  |  |             @click="save" | 
					
						
							|  |  |  |           /> | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |         </v-card-actions> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |     </v-dialog> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  | export default defineNuxtComponent({ | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |   props: { | 
					
						
							|  |  |  |     inputTextProp: { | 
					
						
							|  |  |  |       type: String, | 
					
						
							|  |  |  |       required: false, | 
					
						
							|  |  |  |       default: "", | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |   emits: ["bulk-data"], | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |   setup(props, context) { | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     const state = reactive({ | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |       dialog: false, | 
					
						
							| 
									
										
										
										
											2022-09-25 15:00:45 -08:00
										 |  |  |       inputText: props.inputTextProp, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function splitText() { | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |       return state.inputText.split("\n").filter(line => !(line === "\n" || !line)); | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |     function removeFirstCharacter() { | 
					
						
							|  |  |  |       state.inputText = splitText() | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         .map(line => line.substring(1)) | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |         .join("\n"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 11:28:47 -08:00
										 |  |  |     const numberedLineRegex = /\d+[.):] /gm; | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function splitByNumberedLine() { | 
					
						
							|  |  |  |       // Split inputText by numberedLineRegex
 | 
					
						
							|  |  |  |       const matches = state.inputText.match(numberedLineRegex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       matches?.forEach((match, idx) => { | 
					
						
							|  |  |  |         const replaceText = idx === 0 ? "" : "\n"; | 
					
						
							|  |  |  |         state.inputText = state.inputText.replace(match, replaceText); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     function trimAllLines() { | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |       const splitLines = splitText(); | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |       splitLines.forEach((element: string, index: number) => { | 
					
						
							|  |  |  |         splitLines[index] = element.trim(); | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |       state.inputText = splitLines.join("\n"); | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function save() { | 
					
						
							|  |  |  |       context.emit("bulk-data", splitText()); | 
					
						
							|  |  |  |       state.dialog = false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |     const i18n = useI18n(); | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const utilities = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         id: "trim-whitespace", | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         description: i18n.t("new-recipe.trim-whitespace-description"), | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |         action: trimAllLines, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         id: "trim-prefix", | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         description: i18n.t("new-recipe.trim-prefix-description"), | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |         action: removeFirstCharacter, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         id: "split-by-numbered-line", | 
					
						
							| 
									
										
										
										
											2025-06-20 00:09:12 +07:00
										 |  |  |         description: i18n.t("new-recipe.split-by-numbered-line-description"), | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |         action: splitByNumberedLine, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2022-05-11 17:14:03 -08:00
										 |  |  |       utilities, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       splitText, | 
					
						
							|  |  |  |       trimAllLines, | 
					
						
							| 
									
										
										
										
											2021-11-04 18:15:23 -08:00
										 |  |  |       removeFirstCharacter, | 
					
						
							| 
									
										
										
										
											2021-11-05 15:48:10 -08:00
										 |  |  |       splitByNumberedLine, | 
					
						
							| 
									
										
										
										
											2021-10-31 14:46:46 -08:00
										 |  |  |       save, | 
					
						
							|  |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-11-04 14:01:37 -08:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-31 15:07:19 -08:00
										 |  |  | </script> |