added ingredient auto sort feature
This commit is contained in:
parent
12a1f261db
commit
8307828528
1
.gitignore
vendored
1
.gitignore
vendored
@ -84,3 +84,4 @@ cookbook/static/vue
|
||||
vue/webpack-stats.json
|
||||
cookbook/templates/sw.js
|
||||
.prettierignore
|
||||
vue/.yarn
|
||||
|
@ -18,7 +18,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (recipes)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (recipes)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
|
1
vue/.yarnrc.yml
Normal file
1
vue/.yarnrc.yml
Normal file
@ -0,0 +1 @@
|
||||
nodeLinker: node-modules
|
@ -24,6 +24,7 @@
|
||||
"mavon-editor": "^2.10.4",
|
||||
"moment": "^2.29.4",
|
||||
"prismjs": "^1.29.0",
|
||||
"string-similarity": "^4.0.4",
|
||||
"vue": "^2.6.14",
|
||||
"vue-class-component": "^7.2.3",
|
||||
"vue-click-outside": "^1.1.0",
|
||||
@ -36,10 +37,10 @@
|
||||
"vue-property-decorator": "^9.1.2",
|
||||
"vue-sanitize": "^0.2.2",
|
||||
"vue-simple-calendar": "^5.0.0",
|
||||
"vue-template-compiler": "2.6.14",
|
||||
"vue2-touch-events": "^3.2.2",
|
||||
"vuedraggable": "^2.24.3",
|
||||
"vuex": "^3.6.0",
|
||||
"vue-template-compiler": "2.6.14",
|
||||
"workbox-webpack-plugin": "^6.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -3,10 +3,15 @@
|
||||
<h5>Steps</h5>
|
||||
<div class="row">
|
||||
<div class="col col-md-12 text-center">
|
||||
<b-button @click="splitAllSteps('\n')" variant="secondary" v-b-tooltip.hover :title="$t('Split_All_Steps')"><i
|
||||
<b-button @click="autoSortIngredients()" variant="secondary" v-b-tooltip.hover v-if="recipe_json.steps.length > 1"
|
||||
:title="$t('Auto_Sort_Help')"><i class="fas fa-random"></i> {{ $t('Auto_Sort') }}
|
||||
</b-button>
|
||||
<b-button @click="splitAllSteps('\n')" variant="secondary" class="ml-1" v-b-tooltip.hover
|
||||
:title="$t('Split_All_Steps')"><i
|
||||
class="fas fa-expand-arrows-alt"></i> {{ $t('All') }}
|
||||
</b-button>
|
||||
<b-button @click="mergeAllSteps()" variant="primary" class="ml-1" v-b-tooltip.hover :title="$t('Combine_All_Steps')"><i
|
||||
<b-button @click="mergeAllSteps()" variant="primary" class="ml-1" v-b-tooltip.hover
|
||||
:title="$t('Combine_All_Steps')"><i
|
||||
class="fas fa-compress-arrows-alt"></i> {{ $t('All') }}
|
||||
</b-button>
|
||||
</div>
|
||||
@ -59,6 +64,7 @@
|
||||
|
||||
|
||||
import draggable from "vuedraggable";
|
||||
import stringSimilarity from "string-similarity"
|
||||
|
||||
export default {
|
||||
name: "ImportViewStepEditor",
|
||||
@ -142,6 +148,34 @@ export default {
|
||||
'ingredients': removed_steps.flatMap(x => x.ingredients)
|
||||
})
|
||||
},
|
||||
/**
|
||||
* automatically assign ingredients to steps based on text matching
|
||||
*/
|
||||
autoSortIngredients: function () {
|
||||
let ingredients = this.recipe_json.steps.flatMap(s => s.ingredients)
|
||||
this.recipe_json.steps.forEach(s => s.ingredients = [])
|
||||
|
||||
ingredients.forEach(i => {
|
||||
let found = false
|
||||
this.recipe_json.steps.forEach(s => {
|
||||
if (s.instruction.includes(i.food.name.trim()) && !found) {
|
||||
found = true
|
||||
s.ingredients.push(i)
|
||||
}
|
||||
})
|
||||
if (!found) {
|
||||
let best_match = {rating: 0, step: this.recipe_json.steps[0]}
|
||||
this.recipe_json.steps.forEach(s => {
|
||||
let match = stringSimilarity.findBestMatch(i.food.name.trim(), s.instruction.split(' '))
|
||||
if (match.bestMatch.rating > best_match.rating) {
|
||||
best_match = {rating: match.bestMatch.rating, step: s}
|
||||
}
|
||||
})
|
||||
best_match.step.ingredients.push(i)
|
||||
found = true
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -68,7 +68,8 @@
|
||||
"Enable_Amount": "Enable Amount",
|
||||
"Disable_Amount": "Disable Amount",
|
||||
"Ingredient Editor": "Ingredient Editor",
|
||||
|
||||
"Auto_Sort": "Auto Sort",
|
||||
"Auto_Sort_Help": "Move all ingredients to the best fitting step.",
|
||||
"Private_Recipe": "Private Recipe",
|
||||
"Private_Recipe_Help": "Recipe is only shown to you and people its shared with.",
|
||||
"reusable_help_text": "Should the invite link be usable for more than one user.",
|
||||
|
28536
vue/yarn.lock
28536
vue/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user