From 7426bb4e7627fe32e91c16a049a6603f90479744 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 10 Mar 2022 17:35:11 +0100 Subject: [PATCH] auto import multiple urls --- vue/src/apps/ImportView/ImportView.vue | 143 ++++-- .../ImportView/ImportViewAdvancedMapping.vue | 408 ------------------ 2 files changed, 98 insertions(+), 453 deletions(-) delete mode 100644 vue/src/apps/ImportView/ImportViewAdvancedMapping.vue diff --git a/vue/src/apps/ImportView/ImportView.vue b/vue/src/apps/ImportView/ImportView.vue index 406e98327..8ad043c8b 100644 --- a/vue/src/apps/ImportView/ImportView.vue +++ b/vue/src/apps/ImportView/ImportView.vue @@ -21,22 +21,66 @@ - - - - - - - - Clear recent imports - +
+
+ Multiple RecipesSingle Recipe +
+
+ +
+
+ + + + + + + + + + +
+
+ +
+
+ +
+ Clear import list +
    +
  • + {{ x }} +
  • +
+ + Import + +
+
+
+ +
@@ -112,24 +156,6 @@ - - - - Advanced Options - - - - - - - - - - - @@ -184,7 +210,8 @@ :placeholder="$t('paste_json')" style="font-size: 12px"> - + {{ $t('Import') }} @@ -226,7 +253,6 @@ import {ApiApiFactory} from "@/utils/openapi/api"; import draggable from "vuedraggable"; import {INTEGRATIONS} from "@/utils/integration"; import ImportViewStepEditor from "@/apps/ImportView/ImportViewStepEditor"; -import ImportViewAdvancedMapping from "@/apps/ImportView/ImportViewAdvancedMapping"; Vue.use(BootstrapVue) @@ -237,7 +263,6 @@ export default { ToastMixin, ], components: { - ImportViewAdvancedMapping, ImportViewStepEditor, draggable, }, @@ -253,6 +278,12 @@ export default { // URL import LS_IMPORT_RECENT: 'import_recent_urls', //TODO use central helper to manage all local storage keys (and maybe even access) website_url: '', + website_url_list: [ + 'https://madamedessert.de/schokoladenpudding-rezept-mit-echter-schokolade/', + 'https://www.essen-und-trinken.de/rezepte/58294-rzpt-schokoladenpudding', + 'https://www.chefkoch.de/rezepte/1825781296124455/Schokoladenpudding-selbst-gemacht.html' + ], + import_multiple: false, recent_urls: [], source_data: '', recipe_json: undefined, @@ -274,19 +305,21 @@ export default { this.tab_index = 0 //TODO add ability to pass open tab via get parameter if (window.BOOKMARKLET_IMPORT_ID !== -1) { - this.loadRecipe(window.BOOKMARKLET_IMPORT_ID) + this.loadRecipe(false, window.BOOKMARKLET_IMPORT_ID) } }, methods: { /** * Import recipe based on the data configured by the client * @param action: action to perform after import (options are: edit, view, import) + * @param data: if parameter is passed ignore global application state and import form data variable */ - importRecipe: function (action) { + importRecipe: function (action, data) { let apiFactory = new ApiApiFactory() - apiFactory.createRecipe(this.recipe_json).then(response => { // save recipe + let recipe_json = data !== undefined ? data : this.recipe_json + apiFactory.createRecipe(recipe_json).then(response => { // save recipe let recipe = response.data - apiFactory.imageRecipe(response.data.id, undefined, this.recipe_json.image).then(response => { // save recipe image + apiFactory.imageRecipe(response.data.id, undefined, recipe_json.image).then(response => { // save recipe image StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE) this.afterImportAction(action, recipe) }).catch(e => { @@ -303,6 +336,7 @@ export default { * edit: edit imported recipe * view: view imported recipe * import: restart the importer + * nothing: do nothing * @param recipe: recipe that was imported */ afterImportAction: function (action, recipe) { @@ -316,14 +350,17 @@ export default { case 'import': location.reload(); break; + case 'nothing': + break; } }, /** * Requests the recipe to be loaded form the source (url/data) from the server * Updates all variables to contain what they need to render either simple preview or manual mapping mode + * @param silent do not open the options tab after loading the recipe + * @param bookmarklet id of bookmarklet import to load instead of url, default undefined */ - loadRecipe: function (bookmarklet) { - console.log(this.website_url) + loadRecipe: function (silent, bookmarklet) { // keep list of recently imported urls if (this.website_url !== '') { if (this.recent_urls.length > 5) { @@ -351,7 +388,7 @@ export default { payload['bookmarklet'] = bookmarklet } - axios.post(resolveDjangoUrl('api_recipe_from_source'), payload,).then((response) => { + return axios.post(resolveDjangoUrl('api_recipe_from_source'), payload,).then((response) => { this.recipe_json = response.data['recipe_json']; this.$set(this.recipe_json, 'unused_keywords', this.recipe_json.keywords.filter(k => k.id === undefined)) @@ -361,12 +398,28 @@ export default { this.recipe_html = response.data['recipe_html']; this.recipe_images = response.data['recipe_images'] !== undefined ? response.data['recipe_images'] : []; - this.tab_index = 0 // open tab 0 with import wizard - this.collapse_visible.options = true // open options collapse + if (!silent) { + this.tab_index = 0 // open tab 0 with import wizard + this.collapse_visible.options = true // open options collapse + } + return this.recipe_json }).catch((err) => { StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH, err.response.data.msg) }) }, + /** + * Function to automatically import multiple urls + * Takes input from website_url_list + */ + autoImport: function () { + this.website_url_list.forEach(r => { + this.website_url = r + this.loadRecipe(true, undefined).then((recipe_json) => { + this.importRecipe('nothing', recipe_json) //TODO handle feedback of what was imported and what not + }) + }) + this.website_url_list = [] + }, /** * Import recipes with uploaded files and app integration */ diff --git a/vue/src/apps/ImportView/ImportViewAdvancedMapping.vue b/vue/src/apps/ImportView/ImportViewAdvancedMapping.vue deleted file mode 100644 index 2ee3fe9b0..000000000 --- a/vue/src/apps/ImportView/ImportViewAdvancedMapping.vue +++ /dev/null @@ -1,408 +0,0 @@ - - - - - \ No newline at end of file