mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-28 06:34:16 -05:00
feat: Upgraded Ingredient Parsing Workflow (#6151)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<v-form
|
||||
ref="domUrlForm"
|
||||
@submit.prevent="createFromHtmlOrJson(newRecipeData, importKeywordsAsTags, stayInEditMode)"
|
||||
@submit.prevent="createFromHtmlOrJson(newRecipeData, importKeywordsAsTags)"
|
||||
>
|
||||
<div>
|
||||
<v-card-title class="headline">
|
||||
@@ -48,14 +48,22 @@
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="importKeywordsAsTags"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.import-original-keywords-as-tags')"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="stayInEditMode"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.stay-in-edit-mode')"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="parseRecipe"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.parse-recipe-ingredients-after-import')"
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-actions class="justify-center">
|
||||
<div style="width: 250px">
|
||||
@@ -76,6 +84,7 @@
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { useTagStore } from "~/composables/store/use-tag-store";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import { useNewRecipeOptions } from "~/composables/use-new-recipe-options";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
|
||||
@@ -92,28 +101,16 @@ export default defineNuxtComponent({
|
||||
const domUrlForm = ref<VForm | null>(null);
|
||||
|
||||
const api = useUserApi();
|
||||
const router = useRouter();
|
||||
const tags = useTagStore();
|
||||
|
||||
const importKeywordsAsTags = computed({
|
||||
get() {
|
||||
return route.query.use_keywords === "1";
|
||||
},
|
||||
set(v: boolean) {
|
||||
router.replace({ query: { ...route.query, use_keywords: v ? "1" : "0" } });
|
||||
},
|
||||
});
|
||||
const {
|
||||
importKeywordsAsTags,
|
||||
stayInEditMode,
|
||||
parseRecipe,
|
||||
navigateToRecipe,
|
||||
} = useNewRecipeOptions();
|
||||
|
||||
const stayInEditMode = computed({
|
||||
get() {
|
||||
return route.query.edit === "1";
|
||||
},
|
||||
set(v: boolean) {
|
||||
router.replace({ query: { ...route.query, edit: v ? "1" : "0" } });
|
||||
},
|
||||
});
|
||||
|
||||
function handleResponse(response: AxiosResponse<string> | null, edit = false, refreshTags = false) {
|
||||
function handleResponse(response: AxiosResponse<string> | null, refreshTags = false) {
|
||||
if (response?.status !== 201) {
|
||||
state.error = true;
|
||||
state.loading = false;
|
||||
@@ -123,7 +120,7 @@ export default defineNuxtComponent({
|
||||
tags.actions.refresh();
|
||||
}
|
||||
|
||||
router.push(`/g/${groupSlug.value}/r/${response.data}?edit=${edit.toString()}`);
|
||||
navigateToRecipe(response.data, groupSlug.value, `/g/${groupSlug.value}/r/create/html`);
|
||||
}
|
||||
|
||||
const newRecipeData = ref<string | object | null>(null);
|
||||
@@ -151,7 +148,7 @@ export default defineNuxtComponent({
|
||||
}
|
||||
handleIsEditJson();
|
||||
|
||||
async function createFromHtmlOrJson(htmlOrJsonData: string | object | null, importKeywordsAsTags: boolean, stayInEditMode: boolean) {
|
||||
async function createFromHtmlOrJson(htmlOrJsonData: string | object | null, importKeywordsAsTags: boolean) {
|
||||
if (!htmlOrJsonData || !domUrlForm.value?.validate()) {
|
||||
return;
|
||||
}
|
||||
@@ -166,13 +163,14 @@ export default defineNuxtComponent({
|
||||
|
||||
state.loading = true;
|
||||
const { response } = await api.recipes.createOneByHtmlOrJson(dataString, importKeywordsAsTags);
|
||||
handleResponse(response, stayInEditMode, importKeywordsAsTags);
|
||||
handleResponse(response, importKeywordsAsTags);
|
||||
}
|
||||
|
||||
return {
|
||||
domUrlForm,
|
||||
importKeywordsAsTags,
|
||||
stayInEditMode,
|
||||
parseRecipe,
|
||||
newRecipeData,
|
||||
handleIsEditJson,
|
||||
createFromHtmlOrJson,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
:multiple="true"
|
||||
@uploaded="uploadImages"
|
||||
/>
|
||||
<div v-if="uploadedImages.length > 0" class="mt-3">
|
||||
<div v-if="uploadedImages.length" class="mt-3">
|
||||
<p class="my-2">
|
||||
{{ $t("recipe.crop-and-rotate-the-image") }}
|
||||
</p>
|
||||
@@ -60,20 +60,28 @@
|
||||
</v-row>
|
||||
</div>
|
||||
</v-container>
|
||||
<v-checkbox
|
||||
v-if="uploadedImages.length"
|
||||
v-model="shouldTranslate"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.should-translate-description')"
|
||||
:disabled="loading"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-if="uploadedImages.length"
|
||||
v-model="parseRecipe"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.parse-recipe-ingredients-after-import')"
|
||||
:disabled="loading"
|
||||
/>
|
||||
</v-card-text>
|
||||
<v-card-actions v-if="uploadedImages.length">
|
||||
<div class="w-100 d-flex flex-column align-center">
|
||||
<p style="width: 250px">
|
||||
<BaseButton rounded block type="submit" :loading="loading" />
|
||||
</p>
|
||||
<p>
|
||||
<v-checkbox
|
||||
v-model="shouldTranslate"
|
||||
hide-details
|
||||
:label="$t('recipe.should-translate-description')"
|
||||
:disabled="loading"
|
||||
/>
|
||||
</p>
|
||||
<p v-if="loading" class="mb-0">
|
||||
{{
|
||||
uploadedImages.length > 1
|
||||
@@ -91,6 +99,7 @@
|
||||
<script lang="ts">
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
import { useNewRecipeOptions } from "~/composables/use-new-recipe-options";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
|
||||
export default defineNuxtComponent({
|
||||
@@ -102,7 +111,6 @@ export default defineNuxtComponent({
|
||||
const i18n = useI18n();
|
||||
const api = useUserApi();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const groupSlug = computed(() => route.params.groupSlug || "");
|
||||
|
||||
const domUrlForm = ref<VForm | null>(null);
|
||||
@@ -111,6 +119,8 @@ export default defineNuxtComponent({
|
||||
const uploadedImagesPreviewUrls = ref<string[]>([]);
|
||||
const shouldTranslate = ref(true);
|
||||
|
||||
const { parseRecipe, navigateToRecipe } = useNewRecipeOptions();
|
||||
|
||||
function uploadImages(files: File[]) {
|
||||
uploadedImages.value = [...uploadedImages.value, ...files];
|
||||
uploadedImageNames.value = [...uploadedImageNames.value, ...files.map(file => file.name)];
|
||||
@@ -143,7 +153,7 @@ export default defineNuxtComponent({
|
||||
state.loading = false;
|
||||
}
|
||||
else {
|
||||
router.push(`/g/${groupSlug.value}/r/${data}`);
|
||||
navigateToRecipe(data, groupSlug.value, `/g/${groupSlug.value}/r/create/image`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +194,7 @@ export default defineNuxtComponent({
|
||||
uploadedImages,
|
||||
uploadedImagesPreviewUrls,
|
||||
shouldTranslate,
|
||||
parseRecipe,
|
||||
uploadImages,
|
||||
clearImage,
|
||||
createRecipe,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div>
|
||||
<v-form
|
||||
ref="domUrlForm"
|
||||
@submit.prevent="createByUrl(recipeUrl, importKeywordsAsTags, stayInEditMode)"
|
||||
@submit.prevent="createByUrl(recipeUrl, importKeywordsAsTags)"
|
||||
>
|
||||
<div>
|
||||
<v-card-title class="headline">
|
||||
@@ -44,6 +44,12 @@
|
||||
hide-details
|
||||
:label="$t('recipe.stay-in-edit-mode')"
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="parseRecipe"
|
||||
color="primary"
|
||||
hide-details
|
||||
:label="$t('recipe.parse-recipe-ingredients-after-import')"
|
||||
/>
|
||||
<v-card-actions class="justify-center">
|
||||
<div style="width: 250px">
|
||||
<BaseButton
|
||||
@@ -111,6 +117,7 @@
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import { useTagStore } from "~/composables/store/use-tag-store";
|
||||
import { useNewRecipeOptions } from "~/composables/use-new-recipe-options";
|
||||
import { validators } from "~/composables/use-validators";
|
||||
import type { VForm } from "~/types/auto-forms";
|
||||
|
||||
@@ -132,10 +139,17 @@ export default defineNuxtComponent({
|
||||
const router = useRouter();
|
||||
const tags = useTagStore();
|
||||
|
||||
const {
|
||||
importKeywordsAsTags,
|
||||
stayInEditMode,
|
||||
parseRecipe,
|
||||
navigateToRecipe,
|
||||
} = useNewRecipeOptions();
|
||||
|
||||
const bulkImporterTarget = computed(() => `/g/${groupSlug.value}/r/create/bulk`);
|
||||
const htmlOrJsonImporterTarget = computed(() => `/g/${groupSlug.value}/r/create/html`);
|
||||
|
||||
function handleResponse(response: AxiosResponse<string> | null, edit = false, refreshTags = false) {
|
||||
function handleResponse(response: AxiosResponse<string> | null, refreshTags = false) {
|
||||
if (response?.status !== 201) {
|
||||
state.error = true;
|
||||
state.loading = false;
|
||||
@@ -145,10 +159,7 @@ export default defineNuxtComponent({
|
||||
tags.actions.refresh();
|
||||
}
|
||||
|
||||
// we clear the query params first so if the user hits back, they don't re-import the recipe
|
||||
router.replace({ query: {} }).then(
|
||||
() => router.push(`/g/${groupSlug.value}/r/${response.data}?edit=${edit.toString()}`),
|
||||
);
|
||||
navigateToRecipe(response.data, groupSlug.value, `/g/${groupSlug.value}/r/create/url`);
|
||||
}
|
||||
|
||||
const recipeUrl = computed({
|
||||
@@ -163,37 +174,35 @@ export default defineNuxtComponent({
|
||||
},
|
||||
});
|
||||
|
||||
const importKeywordsAsTags = computed({
|
||||
get() {
|
||||
return route.query.use_keywords === "1";
|
||||
},
|
||||
set(v: boolean) {
|
||||
router.replace({ query: { ...route.query, use_keywords: v ? "1" : "0" } });
|
||||
},
|
||||
});
|
||||
|
||||
const stayInEditMode = computed({
|
||||
get() {
|
||||
return route.query.edit === "1";
|
||||
},
|
||||
set(v: boolean) {
|
||||
router.replace({ query: { ...route.query, edit: v ? "1" : "0" } });
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (!recipeUrl.value) {
|
||||
return;
|
||||
}
|
||||
if (recipeUrl.value && recipeUrl.value.includes("https")) {
|
||||
// Check if we have a query params for using keywords as tags or staying in edit mode.
|
||||
// We don't use these in the app anymore, but older automations such as Bookmarklet might still use them,
|
||||
// and they're easy enough to support.
|
||||
const importKeywordsAsTagsParam = route.query.use_keywords;
|
||||
if (importKeywordsAsTagsParam === "1") {
|
||||
importKeywordsAsTags.value = true;
|
||||
}
|
||||
else if (importKeywordsAsTagsParam === "0") {
|
||||
importKeywordsAsTags.value = false;
|
||||
}
|
||||
|
||||
if (recipeUrl.value.includes("https")) {
|
||||
createByUrl(recipeUrl.value, importKeywordsAsTags.value, stayInEditMode.value);
|
||||
const stayInEditModeParam = route.query.edit;
|
||||
if (stayInEditModeParam === "1") {
|
||||
stayInEditMode.value = true;
|
||||
}
|
||||
else if (stayInEditModeParam === "0") {
|
||||
stayInEditMode.value = false;
|
||||
}
|
||||
|
||||
createByUrl(recipeUrl.value, importKeywordsAsTags.value);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
const domUrlForm = ref<VForm | null>(null);
|
||||
|
||||
async function createByUrl(url: string | null, importKeywordsAsTags: boolean, stayInEditMode: boolean) {
|
||||
async function createByUrl(url: string | null, importKeywordsAsTags: boolean) {
|
||||
if (url === null) {
|
||||
return;
|
||||
}
|
||||
@@ -204,7 +213,7 @@ export default defineNuxtComponent({
|
||||
}
|
||||
state.loading = true;
|
||||
const { response } = await api.recipes.createOneByUrl(url, importKeywordsAsTags);
|
||||
handleResponse(response, stayInEditMode, importKeywordsAsTags);
|
||||
handleResponse(response, importKeywordsAsTags);
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -213,6 +222,7 @@ export default defineNuxtComponent({
|
||||
recipeUrl,
|
||||
importKeywordsAsTags,
|
||||
stayInEditMode,
|
||||
parseRecipe,
|
||||
domUrlForm,
|
||||
createByUrl,
|
||||
...toRefs(state),
|
||||
|
||||
Reference in New Issue
Block a user