Skip to content

Commit

Permalink
working on model select
Browse files Browse the repository at this point in the history
  • Loading branch information
vabene1111 committed Mar 11, 2024
1 parent 09dc352 commit 18767c5
Show file tree
Hide file tree
Showing 140 changed files with 7,674 additions and 5,947 deletions.
1 change: 1 addition & 0 deletions recipes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
'TITLE': 'Tandoor',
'DESCRIPTION': 'Tandoor API Docs',
'SERVE_INCLUDE_SCHEMA': False,
'ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE': False,
}

ROOT_URLCONF = 'recipes.urls'
Expand Down
1 change: 1 addition & 0 deletions vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"@mdi/font": "7.2.96",
"@types/luxon": "^3.4.2",
"@vueuse/core": "^10.9.0",
"luxon": "^3.4.4",
"mavon-editor": "^3.0.1",
"pinia": "^2.1.7",
Expand Down
140 changes: 115 additions & 25 deletions vue3/src/components/inputs/ModelSelect.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
<template>
<template v-if="allow_create">
Combobox
<template v-if="allowCreate">
<v-combobox
label="Combobox"
v-model="selected_items"
v-model:search="search_query"
@update:search="debouncedSearchFunction"
:items="items"
:loading="search_loading"
:hide-no-data="!(allowCreate && search_query != '')"
:multiple="multiple"
:clearable="clearable"
item-title="name"
item-value="id"
chips
@update:search="search"
></v-combobox>
:chips="renderAsChips"
:closable-chips="renderAsChips"
no-filter
>

<template #no-data v-if="allowCreate && search_query != '' && !search_loading && multiple">
<v-list-item>
<v-list-item-title>
Press enter to create "<strong>{{ search_query }}</strong>"
</v-list-item-title>
</v-list-item>
</template>

<template v-slot:item="{ item, index, props }">
<v-list-item v-bind="props">
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item>
</template>

<template v-if="renderAsChips" v-slot:chip="{ item, index, props }">
<v-chip closable>{{ item.title }}</v-chip>
</template>

</v-combobox>

</template>
<template v-else>
Autocomplete

<v-autocomplete
label="Autocomplete"
:items="items"
:loading="search_loading"
:multiple="multiple"
item-title="name"
item-value="id"
chips
closable-chips
no-filter
@update:search="debouncedSearchFunction"
></v-autocomplete>
</template>
</template>

<script lang="ts" setup>
import {ref, onMounted} from 'vue'
import {computed, onMounted, ref, Ref, watch} from 'vue'
import {ApiApi} from "@/openapi/index.js";
import {useDebounceFn} from "@vueuse/core";
const props = defineProps(
{
search_on_load: {type: Boolean, default: false},
multiple: {type: Boolean, default: true},
allowCreate: {type: Boolean, default: false},
clearable: {type: Boolean, default: false,},
chips: {type: Boolean, default: undefined,},
itemName: {type: String, default: 'name'},
itemValue: {type: String, default: 'id'},
// old props
placeholder: {type: String, default: undefined},
model: {
type: String,
Expand All @@ -53,35 +98,80 @@ const props = defineProps(
type: Object,
default: undefined,
},
search_on_load: {type: Boolean, default: true},
multiple: {type: Boolean, default: true},
allow_create: {type: Boolean, default: false},
create_placeholder: {type: String, default: "You Forgot to Add a Tag Placeholder"},
clear: {type: Number},
disabled: {type: Boolean, default: false,},
}
)
const items = ref([])
const items: Ref<Array<any>> = ref([])
const selected_items: Ref<Array<any> | any> = ref(undefined)
const search_query = ref('')
const search_loading = ref(false)
function genericApiCall(model: string, query: string) {
// TODO make mode an enum
// TODO make model an enum as well an manually "clear" allowed types?
const api = new ApiApi()
const renderAsChips = computed(() => {
if (props.chips != undefined) {
return props.chips
}
return props.multiple
})
api[`api${model}List`]({page: 1, query: query}).then(r => {
this.items = r.results
})
}
watch(selected_items, (new_items, old_items) => {
if (!(new_items instanceof Array) && !(old_items instanceof Array)) {
//TODO detect creation of single selects
} else {
if (old_items == undefined && new_items instanceof Array) {
old_items = []
}
if (new_items == undefined && old_items instanceof Array) {
new_items = []
}
function search(query: string) {
if (old_items.length > new_items.length) {
// item was removed
} else if (old_items.length < new_items.length) {
console.log('items created')
}
}
}
// lifecycle hooks
})
onMounted(() => {
console.log(`The initial count is ${items}.`)
if (props.search_on_load) {
debouncedSearchFunction('')
}
})
/**
* debounced search function bound to search input changing
*/
const debouncedSearchFunction = useDebounceFn((query: string) => {
search(query)
}, 300)
/**
* performs the API request to search for the selected input
* @param query input to search for on the API
*/
function search(query: string) {
const api = new ApiApi()
search_loading.value = true
api.apiFoodList({query: query}).then(r => {
if (r.results) {
items.value = r.results
if (props.allowCreate && search_query.value != '') {
// TODO check if search_query is already in items
items.value.unshift({id: null, name: `Create "${search_query.value}"`})
}
}
}).catch(err => {
//useMessageStore().addMessage(MessageType.ERROR, err, 8000)
}).finally(() => {
search_loading.value = false
})
}
</script>


Expand Down
1 change: 0 additions & 1 deletion vue3/src/openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ models/AuthToken.ts
models/Automation.ts
models/AutomationTypeEnum.ts
models/BaseUnitEnum.ts
models/BlankEnum.ts
models/BookmarkletImport.ts
models/BookmarkletImportList.ts
models/ConnectorConfigConfig.ts
Expand Down
2 changes: 1 addition & 1 deletion vue3/src/openapi/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.0
7.4.0
Loading

0 comments on commit 18767c5

Please sign in to comment.