From 1caabef56a9f07569b75e13ccdadbd37e973dbb6 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Fri, 4 Mar 2022 16:54:59 +0100 Subject: [PATCH] step functions --- vue/src/apps/ImportView/ImportView.vue | 133 ++++++++++++++++++------- 1 file changed, 98 insertions(+), 35 deletions(-) diff --git a/vue/src/apps/ImportView/ImportView.vue b/vue/src/apps/ImportView/ImportView.vue index 34bc5831..0a155cfe 100644 --- a/vue/src/apps/ImportView/ImportView.vue +++ b/vue/src/apps/ImportView/ImportView.vue @@ -44,7 +44,8 @@ - Options + Options
- Split - Merge all - - - - Delete - Merge - - + All + all
+ +
+
+ + {{ i.original_text }} + + +
+
+ + + + + + + + + + + + + + + + + + + +
@@ -129,14 +159,15 @@ - Advanced Options + Advanced Options + - @@ -144,16 +175,18 @@ - Import + Import + - Import & View + Import & View Import & Edit - Import & start new import + Import & start new import @@ -189,10 +222,12 @@
+ :placeholder="$t('paste_json')" style="font-size: 12px">
- {{ $t('Import') }} + + {{ $t('Import') }} + @@ -244,7 +279,7 @@ export default { data() { return { tab_index: 0, - collapse_visible : { + collapse_visible: { url: true, options: false, advanced_options: false, @@ -350,30 +385,46 @@ export default { }) }, /** - * Splits the steps of a given recipe at the split character (e.g. \n or \n\n) + * utility function used by splitAllSteps and splitStep to split a single step object into multiple step objects + * @param step: single step + * @param split_character: character to split steps at + * @return array of step objects + */ + splitStepObject: function (step, split_character) { + let steps = [] + step.instruction.split(split_character).forEach(part => { + if (part.trim() !== '') { + steps.push({'instruction': part, 'ingredients': []}) + } + }) + steps[0].ingredients = step.ingredients // put all ingredients from the original step in the ingredients of the first step of the split step list + return steps + }, + /** + * Splits all steps of a given recipe at the split character (e.g. \n or \n\n) * @param split_character: character to split steps at */ - splitSteps: function (split_character) { + splitAllSteps: function (split_character) { let steps = [] this.recipe_json.steps.forEach(step => { - step.instruction.split(split_character).forEach(part => { - if (part.trim() !== ''){ - steps.push({'instruction': part, 'ingredients': []}) - } - }) - }) - this.recipe_json.steps.forEach(step => { - if (step.ingredients.length > 0) { - console.log('found ingredients', step.ingredients) - steps[0].ingredients = steps[0].ingredients.concat(step.ingredients) - } + steps = steps.concat(this.splitStepObject(step, split_character)) }) this.recipe_json.steps = steps }, /** - * Merge steps of a given recipe into one + * Splits the given step at the split character (e.g. \n or \n\n) + * @param step: step ingredients to split + * @param split_character: character to split steps at */ - mergeSteps: function (){ + splitStep: function (step, split_character) { + let old_index = this.recipe_json.steps.findIndex(x => x === step) + let new_steps = this.splitStepObject(step, split_character) + this.recipe_json.steps.splice(old_index, 1, ...new_steps) + }, + /** + * Merge all steps of a given recipe into one + */ + mergeAllSteps: function () { let step = {'instruction': '', 'ingredients': []} this.recipe_json.steps.forEach(s => { step.instruction += s.instruction + '\n' @@ -381,6 +432,18 @@ export default { }) this.recipe_json.steps = [step] }, + /** + * Merge two steps (the given and next one) + */ + mergeStep: function (step) { + let step_index = this.recipe_json.steps.findIndex(x => x === step) + let removed_steps = this.recipe_json.steps.splice(step_index, 2) + + this.recipe_json.steps.splice(step_index, 0, { + 'instruction': removed_steps.flatMap(x => x.instruction).join('\n'), + 'ingredients': removed_steps.flatMap(x => x.ingredients) + }) + }, /** * Clear list of recently imported recipe urls */