Skip to content

Commit

Permalink
Merge pull request #1348 from smilerz/fuzzy_search
Browse files Browse the repository at this point in the history
Fuzzy search
  • Loading branch information
vabene1111 committed Jan 17, 2022
2 parents a376728 + 769365d commit c14dd04
Showing 1 changed file with 60 additions and 59 deletions.
119 changes: 60 additions & 59 deletions cookbook/templates/url_import.html
Expand Up @@ -660,13 +660,14 @@ <h5 class="card-title">{% trans 'Information' %}</h5>

</div>

<script src="{% url 'javascript-catalog' %}"></script>
<script src="{% url 'javascript-catalog' %}">
</script>
<script type="application/javascript">
let csrftoken = Cookies.get('csrftoken');
Vue.http.headers.common['X-CSRFToken'] = csrftoken;

Vue.component('vue-multiselect', window.VueMultiselect.default)
import { ApiApiFactory } from "@/utils/openapi/api"


let app = new Vue({
components: {
Expand Down Expand Up @@ -885,27 +886,27 @@ <h5 class="card-title">{% trans 'Information' %}</h5>
this.$set(this.$refs.ingredient[index].$data, 'search', this.recipe_data.recipeIngredient[index].ingredient.text)
},
searchKeywords: function (query) {
// this.keywords_loading = true
// this.$http.get("{% url 'dal_keyword' %}" + '?q=' + query).then((response) => {
// this.keywords = response.data.results;
// this.keywords_loading = false
// }).catch((err) => {
// console.log(err)
// this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
// })
let apiFactory = new ApiApiFactory()

this.keywords_loading = true
apiFactory
.listKeywords(query, undefined, undefined, 1, this.options_limit)
.then((response) => {
this.keywords = response.data.results
this.keywords_loading = false
})
.catch((err) => {
console.log(err)
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
})
this.$http.get("{% url 'dal_keyword' %}" + '?q=' + query).then((response) => {
this.keywords = response.data.results;
this.keywords_loading = false
}).catch((err) => {
console.log(err)
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
})
// let apiFactory = new ApiApiFactory()

// this.keywords_loading = true
// apiFactory
// .listKeywords(query, undefined, undefined, 1, this.options_limit)
// .then((response) => {
// this.keywords = response.data.results
// this.keywords_loading = false
// })
// .catch((err) => {
// console.log(err)
// StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
// })
},
searchUnits: function (query) {
let apiFactory = new ApiApiFactory()
Expand All @@ -932,46 +933,46 @@ <h5 class="card-title">{% trans 'Information' %}</h5>
})
},
searchIngredients: function (query) {
// this.ingredients_loading = true
// this.$http.get("{% url 'dal_food' %}" + '?q=' + query).then((response) => {
// this.ingredients = response.data.results
// if (this.recipe_data !== undefined) {
// for (let x of Array.from(this.recipe_data.recipeIngredient)) {
// if (x.ingredient.text !== '') {
// this.ingredients = this.ingredients.filter(item => item.text !== x.ingredient.text)
// this.ingredients.push(x.ingredient)
// }
// }
// }

// this.ingredients_loading = false
// }).catch((err) => {
// console.log(err)
// this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
// })
let apiFactory = new ApiApiFactory()

this.foods_loading = true
apiFactory
.listFoods(query, undefined, undefined, 1, this.options_limit)
.then((response) => {
this.foods = response.data.results

if (this.recipe !== undefined) {
for (let s of this.recipe.steps) {
for (let i of s.ingredients) {
if (i.food !== null && i.food.id === undefined) {
this.foods.push(i.food)
}
}
this.ingredients_loading = true
this.$http.get("{% url 'dal_food' %}" + '?q=' + query).then((response) => {
this.ingredients = response.data.results
if (this.recipe_data !== undefined) {
for (let x of Array.from(this.recipe_data.recipeIngredient)) {
if (x.ingredient.text !== '') {
this.ingredients = this.ingredients.filter(item => item.text !== x.ingredient.text)
this.ingredients.push(x.ingredient)
}
}
}

this.foods_loading = false
})
.catch((err) => {
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
})
this.ingredients_loading = false
}).catch((err) => {
console.log(err)
this.makeToast(gettext('Error'), gettext('There was an error loading a resource!') + err.bodyText, 'danger')
})
// let apiFactory = new ApiApiFactory()

// this.foods_loading = true
// apiFactory
// .listFoods(query, undefined, undefined, 1, this.options_limit)
// .then((response) => {
// this.foods = response.data.results

// if (this.recipe !== undefined) {
// for (let s of this.recipe.steps) {
// for (let i of s.ingredients) {
// if (i.food !== null && i.food.id === undefined) {
// this.foods.push(i.food)
// }
// }
// }
// }

// this.foods_loading = false
// })
// .catch((err) => {
// StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
// })
},
deleteNode: function (node, item, e) {
e.stopPropagation()
Expand Down

0 comments on commit c14dd04

Please sign in to comment.