fixed unit search on importer page

This commit is contained in:
vabene1111
2022-01-21 16:56:47 +01:00
parent 20adcc0e83
commit f274f31e80

View File

@@ -908,28 +908,22 @@
// }) // })
}, },
searchUnits: function (query) { searchUnits: function (query) {
let apiFactory = new ApiApiFactory()
this.units_loading = true this.units_loading = true
apiFactory this.$http.get("{% url 'dal_unit' %}" + '?q=' + query).then((response) => {
.listUnits(query, 1, this.options_limit) this.units = response.data.results;
.then((response) => { if (this.recipe_data !== undefined) {
this.units = response.data.results for (let x of Array.from(this.recipe_data.recipeIngredient)) {
if (x.unit !== null && x.unit.text !== '') {
if (this.recipe !== undefined) { this.units = this.units.filter(item => item.text !== x.unit.text)
for (let s of this.recipe.steps) { this.units.push(x.unit)
for (let i of s.ingredients) {
if (i.unit !== null && i.unit.id === undefined) {
this.units.push(i.unit)
}
}
} }
} }
this.units_loading = false }
}) this.units_loading = false
.catch((err) => { }).catch((err) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH) console.log(err)
}) this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
})
}, },
searchIngredients: function (query) { searchIngredients: function (query) {
this.ingredients_loading = true this.ingredients_loading = true