added basic ingredient editor

This commit is contained in:
vabene1111
2022-04-14 13:01:27 +02:00
parent 2ee96c2ea4
commit 7befa4a084
10 changed files with 381 additions and 98 deletions

View File

@@ -26,11 +26,11 @@
<script>
import Vue from "vue"
import Multiselect from "vue-multiselect"
import { ApiMixin } from "@/utils/utils"
import {ApiMixin} from "@/utils/utils"
export default {
name: "GenericMultiselect",
components: { Multiselect },
components: {Multiselect},
mixins: [ApiMixin],
data() {
return {
@@ -42,16 +42,16 @@ export default {
}
},
props: {
placeholder: { type: String, default: undefined },
placeholder: {type: String, default: undefined},
model: {
type: Object,
default() {
return {}
},
},
label: { type: String, default: "name" },
parent_variable: { type: String, default: undefined },
limit: { type: Number, default: 25 },
label: {type: String, default: "name"},
parent_variable: {type: String, default: undefined},
limit: {type: Number, default: 25},
sticky_options: {
type: Array,
default() {
@@ -68,10 +68,11 @@ export default {
type: Object,
default: undefined,
},
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 },
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},
},
watch: {
initial_selection: function (newVal, oldVal) {
@@ -82,12 +83,12 @@ export default {
empty[this.label] = `..${this.$t("loading")}..`
this.selected_objects.forEach((x) => {
if (typeof x !== "object") {
this.selected_objects[this.selected_objects.indexOf(x)] = { ...empty, id: x }
this.selected_objects[this.selected_objects.indexOf(x)] = {...empty, id: x}
get_details.push(x)
}
})
get_details.forEach((x) => {
this.genericAPI(this.model, this.Actions.FETCH, { id: x })
this.genericAPI(this.model, this.Actions.FETCH, {id: x})
.then((result) => {
// this.selected_objects[this.selected_objects.map((y) => y.id).indexOf(x)] = result.data
Vue.set(this.selected_objects, this.selected_objects.map((y) => y.id).indexOf(x), result.data)
@@ -103,8 +104,8 @@ export default {
if (typeof this.selected_objects !== "object") {
let empty = {}
empty[this.label] = `..${this.$t("loading")}..`
this.selected_objects = { ...empty, id: this.selected_objects }
this.genericAPI(this.model, this.Actions.FETCH, { id: this.selected_objects })
this.selected_objects = {...empty, id: this.selected_objects}
this.genericAPI(this.model, this.Actions.FETCH, {id: this.selected_objects})
.then((result) => {
this.selected_objects = result.data
})
@@ -123,7 +124,9 @@ export default {
},
mounted() {
this.id = Math.random()
this.search("")
if (this.search_on_load) {
this.search("")
}
if (this.multiple || !this.initial_single_selection) {
this.selected_objects = this.initial_selection
} else {
@@ -171,7 +174,7 @@ export default {
})
},
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) {
this.$emit("new", e)