fix recipe search in export form (converted to change safe genericAPI)

This commit is contained in:
smilerz
2022-02-23 17:24:06 -06:00
parent abeeac838b
commit c8dcca8630
3 changed files with 32 additions and 26 deletions

View File

@@ -179,7 +179,7 @@ class ImportForm(ImportExportBase):
class ExportForm(ImportExportBase): class ExportForm(ImportExportBase):
recipes = forms.ModelMultipleChoiceField(widget=MultiSelectWidget, queryset=Recipe.objects.none(), required=False) recipes = forms.ModelMultipleChoiceField(widget=MultiSelectWidget, queryset=Recipe.objects.none(), required=False)
all = forms.BooleanField(required=False) all = forms.BooleanField(required=False)
filter = forms.IntegerField(required=False) custom_filter = forms.IntegerField(required=False)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
space = kwargs.pop('space') space = kwargs.pop('space')

View File

@@ -124,8 +124,8 @@ def export_recipe(request):
recipes = form.cleaned_data['recipes'] recipes = form.cleaned_data['recipes']
if form.cleaned_data['all']: if form.cleaned_data['all']:
recipes = Recipe.objects.filter(space=request.space, internal=True).all() recipes = Recipe.objects.filter(space=request.space, internal=True).all()
elif filter := form.cleaned_data['filter']: elif custom_filter := form.cleaned_data['custom_filter']:
search = RecipeSearch(request, filter=filter) search = RecipeSearch(request, filter=custom_filter)
recipes = search.get_queryset(Recipe.objects.filter(space=request.space, internal=True)) recipes = search.get_queryset(Recipe.objects.filter(space=request.space, internal=True))
integration = get_integration(request, form.cleaned_data['type']) integration = get_integration(request, form.cleaned_data['type'])

View File

@@ -17,7 +17,7 @@
{{ $t("All recipes") }} {{ $t("All recipes") }}
</b-form-checkbox> </b-form-checkbox>
<multiselect <!-- <multiselect
:searchable="true" :searchable="true"
:disabled="disabled_multiselect" :disabled="disabled_multiselect"
v-model="recipe_list" v-model="recipe_list"
@@ -35,7 +35,17 @@
:loading="recipes_loading" :loading="recipes_loading"
@search-change="searchRecipes" @search-change="searchRecipes"
> >
</multiselect> </multiselect> -->
<generic-multiselect
class="input-group-text m-0 p-0"
@change="recipe_list = $event.val"
label="name"
:model="Models.RECIPE"
style="flex-grow: 1; flex-shrink: 1; flex-basis: 0"
v-bind:placeholder="$t('Recipe')"
:limit="20"
:multiple="true"
/>
<generic-multiselect <generic-multiselect
@change="filter = $event.val" @change="filter = $event.val"
:model="Models.CUSTOM_FILTER" :model="Models.CUSTOM_FILTER"
@@ -61,7 +71,7 @@ import "bootstrap-vue/dist/bootstrap-vue.css"
import LoadingSpinner from "@/components/LoadingSpinner" import LoadingSpinner from "@/components/LoadingSpinner"
import { StandardToasts, makeToast, resolveDjangoUrl, ApiMixin } from "@/utils/utils" import { StandardToasts, makeToast, resolveDjangoUrl, ApiMixin } from "@/utils/utils"
import Multiselect from "vue-multiselect" // import Multiselect from "vue-multiselect"
import GenericMultiselect from "@/components/GenericMultiselect" import GenericMultiselect from "@/components/GenericMultiselect"
import { ApiApiFactory } from "@/utils/openapi/api.ts" import { ApiApiFactory } from "@/utils/openapi/api.ts"
import axios from "axios" import axios from "axios"
@@ -74,7 +84,7 @@ export default {
ResolveUrlMixin, ResolveUrlMixin,
ToastMixin, ToastMixin,
],*/ ],*/
components: { Multiselect, GenericMultiselect }, components: { GenericMultiselect },
mixins: [ApiMixin], mixins: [ApiMixin],
data() { data() {
return { return {
@@ -92,7 +102,7 @@ export default {
}, },
mounted() { mounted() {
if (this.export_id) this.insertRequested() if (this.export_id) this.insertRequested()
else this.searchRecipes("") // else this.searchRecipes("")
}, },
methods: { methods: {
insertRequested: function () { insertRequested: function () {
@@ -110,26 +120,22 @@ export default {
console.log(err) console.log(err)
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH) StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
}) })
.then((e) => this.searchRecipes("")) // .then((e) => this.searchRecipes(""))
}, },
searchRecipes: function (query) { // searchRecipes: function (query) {
let apiFactory = new ApiApiFactory() // this.recipes_loading = true
this.recipes_loading = true // this.genericAPI(this.Models.RECIPE, this.Actions.LIST, { query: query })
// .then((response) => {
let maxResultLenght = 1000 // this.recipes = response.data.results
apiFactory // this.recipes_loading = false
.listRecipes(query, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 1, maxResultLenght) // })
.then((response) => { // .catch((err) => {
this.recipes = response.data.results // console.log(err)
this.recipes_loading = false // StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
}) // })
.catch((err) => { // },
console.log(err)
StandardToasts.makeStandardToast(StandardToasts.FAIL_FETCH)
})
},
exportRecipe: function () { exportRecipe: function () {
if (this.recipe_list.length < 1 && this.export_all == false && this.filter === undefined) { if (this.recipe_list.length < 1 && this.export_all == false && this.filter === undefined) {
@@ -142,7 +148,7 @@ export default {
let formData = new FormData() let formData = new FormData()
formData.append("type", this.recipe_app) formData.append("type", this.recipe_app)
formData.append("all", this.export_all) formData.append("all", this.export_all)
formData.append("filter", this.filter?.id) formData.append("filter", this.filter?.id ?? null)
for (var i = 0; i < this.recipe_list.length; i++) { for (var i = 0; i < this.recipe_list.length; i++) {
formData.append("recipes", this.recipe_list[i].id) formData.append("recipes", this.recipe_list[i].id)