Merge pull request #1543 from smilerz/feature/copy-to-new-recipe

copy to new recipe
This commit is contained in:
vabene1111
2022-02-17 10:56:03 +01:00
committed by GitHub
2 changed files with 20 additions and 0 deletions

View File

@@ -31,6 +31,9 @@
{{ $t("Print") }}
</button>
</a>
<a href="javascript:void(0);">
<button class="dropdown-item" @click="copyToNew"><i class="fas fa-copy fa-fw"></i> {{ $t("copy_to_new") }}</button>
</a>
<a class="dropdown-item" :href="resolveDjangoUrl('view_export') + '?r=' + recipe.id" target="_blank" rel="noopener noreferrer"><i class="fas fa-file-export fa-fw"></i> {{ $t("Export") }}</a>
@@ -202,6 +205,21 @@ export default {
addToShopping() {
this.$bvModal.show(`shopping_${this.modal_id}`)
},
copyToNew: function () {
let recipename = window.prompt(this.$t("copy_to_new"), this.$t("recipe_name"))
let apiClient = new ApiApiFactory()
apiClient.retrieveRecipe(this.recipe.id).then((results) => {
apiClient
.createRecipe({ ...results.data, ...{ id: undefined, name: recipename } })
.then((newrecipe) => {
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
window.open(this.resolveDjangoUrl("view_recipe", newrecipe.data.id))
})
.catch((error) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_CREATE)
})
})
},
},
}
</script>

View File

@@ -297,6 +297,8 @@
"Foods": "Foods",
"review_shopping": "Review shopping entries before saving",
"view_recipe": "View Recipe",
"copy_to_new": "Copy To New Recipe",
"recipe_name": "Recipe Name",
"paste_ingredients_placeholder": "Paste ingredient list here...",
"paste_ingredients": "Paste Ingredients",
"ingredient_list": "Ingredient List"