This commit is contained in:
smilerz
2021-12-21 13:53:40 -06:00
parent 24bef756e8
commit a3008a6091
2 changed files with 110 additions and 110 deletions

View File

@@ -920,7 +920,7 @@ export default {
makeToast(this.$t("Warning"), this.$t("NoCategory"), "warning") makeToast(this.$t("Warning"), this.$t("NoCategory"), "warning")
} }
// TODO make decision - should inheritance always be turned off when category set manually or give user a choice at front-end or make it a setting? // TODO make decision - should inheritance always be set manually or give user a choice at front-end or make it a setting?
let food = this.items.filter((x) => x.food.id == item?.[0]?.food.id ?? item.food.id)[0].food let food = this.items.filter((x) => x.food.id == item?.[0]?.food.id ?? item.food.id)[0].food
food.supermarket_category = this.shopping_categories.filter((x) => x?.id === this.shopcat)?.[0] food.supermarket_category = this.shopping_categories.filter((x) => x?.id === this.shopcat)?.[0]
this.updateFood(food, "supermarket_category") this.updateFood(food, "supermarket_category")

View File

@@ -15,14 +15,14 @@
:loading="loading" :loading="loading"
@search-change="search" @search-change="search"
@input="selectionChanged" @input="selectionChanged"
@tag="addNew"> @tag="addNew"
>
</multiselect> </multiselect>
</template> </template>
<script> <script>
import Multiselect from "vue-multiselect"
import Multiselect from 'vue-multiselect' import { ApiMixin } from "@/utils/utils"
import {ApiMixin} from "@/utils/utils";
export default { export default {
name: "GenericMultiselect", name: "GenericMultiselect",
@@ -39,48 +39,52 @@ export default {
props: { props: {
placeholder: { type: String, default: undefined }, placeholder: { type: String, default: undefined },
model: { model: {
type: Object, default() { type: Object,
default() {
return {} return {}
}
}, },
label: {type: String, default: 'name'}, },
label: { type: String, default: "name" },
parent_variable: { type: String, default: undefined }, parent_variable: { type: String, default: undefined },
limit: {type: Number, default: 10,}, limit: { type: Number, default: 10 },
sticky_options: { sticky_options: {
type: Array, default() { type: Array,
default() {
return [] return []
} },
}, },
initial_selection: { initial_selection: {
type: Array, default() { type: Array,
default() {
return [] return []
} },
}, },
multiple: { type: Boolean, default: true }, multiple: { type: Boolean, default: true },
allow_create: {type: Boolean, default: false}, // TODO: this will create option to add new drop-downs allow_create: { type: Boolean, default: false },
create_placeholder: {type: String, default: 'You Forgot to Add a Tag Placeholder'}, create_placeholder: { type: String, default: "You Forgot to Add a Tag Placeholder" },
}, },
watch: { watch: {
initial_selection: function (newVal, oldVal) { // watch it initial_selection: function (newVal, oldVal) {
// watch it
this.selected_objects = newVal this.selected_objects = newVal
}, },
}, },
mounted() { mounted() {
this.search('') this.search("")
this.selected_objects = this.initial_selection this.selected_objects = this.initial_selection
}, },
computed: { computed: {
lookupPlaceholder() { lookupPlaceholder() {
return this.placeholder || this.model.name || this.$t('Search') return this.placeholder || this.model.name || this.$t("Search")
}, },
}, },
methods: { methods: {
// this.genericAPI inherited from ApiMixin // this.genericAPI inherited from ApiMixin
search: function (query) { search: function (query) {
let options = { let options = {
'page': 1, page: 1,
'pageSize': 10, pageSize: 10,
'query': query query: query,
} }
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => { this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
this.objects = this.sticky_options.concat(result.data?.results ?? result.data) this.objects = this.sticky_options.concat(result.data?.results ?? result.data)
@@ -101,23 +105,19 @@ export default {
}) })
}, },
selectionChanged: function () { selectionChanged: function () {
this.$emit('change', {var: this.parent_variable, val: this.selected_objects}) this.$emit("change", { var: this.parent_variable, val: this.selected_objects })
}, },
addNew(e) { addNew(e) {
this.$emit('new', e) this.$emit("new", e)
// could refactor as Promise - seems unecessary // could refactor as Promise - seems unecessary
setTimeout(() => { setTimeout(() => {
this.search(''); this.search("")
}, 750); }, 750)
},
} },
}
} }
</script> </script>
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style> <style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
<style scoped> <style scoped></style>
</style>