upgrade query to ids by default

This commit is contained in:
Julian Krauser 2025-04-15 10:29:25 +02:00
parent 68b0aeffa8
commit fc1185d1c8
6 changed files with 49 additions and 10 deletions

View file

@ -131,6 +131,11 @@ export default defineComponent({
this.value = query; this.value = query;
} }
}, },
value() {
if (typeof this.value != "string" && !this.value.id) {
this.value.id = uuid();
}
},
}, },
data() { data() {
return { return {

View file

@ -1,6 +1,6 @@
<template> <template>
<div class="flex flex-row gap-2 items-center w-full"> <div class="flex flex-row gap-2 items-center w-full">
<select v-if="concat != '_'" v-model="concat" class="w-20! h-fit!"> <select v-if="!isFirst" v-model="concat" class="w-20! h-fit!">
<option value="" disabled>Verknüpfung auswählen</option> <option value="" disabled>Verknüpfung auswählen</option>
<option v-for="operation in ['AND', 'OR']" :value="operation"> <option v-for="operation in ['AND', 'OR']" :value="operation">
{{ operation }} {{ operation }}
@ -68,6 +68,10 @@ import { TrashIcon } from "@heroicons/vue/24/outline";
<script lang="ts"> <script lang="ts">
export default defineComponent({ export default defineComponent({
props: { props: {
isFirst: {
type: Boolean,
default: false,
},
table: { table: {
type: String, type: String,
default: "", default: "",
@ -78,9 +82,6 @@ export default defineComponent({
}, },
}, },
emits: ["update:model-value", "remove"], emits: ["update:model-value", "remove"],
data() {
return {};
},
computed: { computed: {
...mapState(useQueryBuilderStore, ["tableMetas"]), ...mapState(useQueryBuilderStore, ["tableMetas"]),
activeTable() { activeTable() {
@ -144,5 +145,10 @@ export default defineComponent({
}, },
}, },
}, },
mounted() {
if (this.concat == "_") {
this.concat = "AND";
}
},
}); });
</script> </script>

View file

@ -40,6 +40,7 @@ import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
import Table from "./Table.vue"; import Table from "./Table.vue";
import { TrashIcon } from "@heroicons/vue/24/outline"; import { TrashIcon } from "@heroicons/vue/24/outline";
import { joinTableName } from "@/helpers/queryFormatter"; import { joinTableName } from "@/helpers/queryFormatter";
import { v4 as uuid } from "uuid";
</script> </script>
<script lang="ts"> <script lang="ts">
@ -94,5 +95,10 @@ export default defineComponent({
}, },
}, },
}, },
mounted() {
if (!this.value.id) {
this.value.id = uuid();
}
},
}); });
</script> </script>

View file

@ -1,6 +1,6 @@
<template> <template>
<div class="flex flex-row gap-2 w-full border border-gray-300 rounded-md p-1"> <div class="flex flex-row gap-2 w-full border border-gray-300 rounded-md p-1">
<select v-if="concat != '_'" v-model="concat" class="w-20! h-fit!"> <select v-if="isFirst" v-model="concat" class="w-20! h-fit!">
<option value="" disabled>Verknüpfung auswählen</option> <option value="" disabled>Verknüpfung auswählen</option>
<option v-for="operation in ['AND', 'OR']" :value="operation"> <option v-for="operation in ['AND', 'OR']" :value="operation">
{{ operation }} {{ operation }}
@ -28,6 +28,10 @@ import NestedWhere from "./NestedWhere.vue";
<script lang="ts"> <script lang="ts">
export default defineComponent({ export default defineComponent({
props: { props: {
isFirst: {
type: Boolean,
default: false,
},
table: { table: {
type: String, type: String,
default: "", default: "",
@ -38,9 +42,6 @@ export default defineComponent({
}, },
}, },
emits: ["update:model-value", "remove"], emits: ["update:model-value", "remove"],
data() {
return {};
},
computed: { computed: {
...mapState(useQueryBuilderStore, ["tableMetas"]), ...mapState(useQueryBuilderStore, ["tableMetas"]),
concat: { concat: {
@ -60,5 +61,10 @@ export default defineComponent({
}, },
}, },
}, },
mounted() {
if (this.concat == "_") {
this.concat = "AND";
}
},
}); });
</script> </script>

View file

@ -16,6 +16,7 @@ import Where from "./Where.vue";
import Order from "./Order.vue"; import Order from "./Order.vue";
import Join from "./Join.vue"; import Join from "./Join.vue";
import TableSelect from "./TableSelect.vue"; import TableSelect from "./TableSelect.vue";
import { v4 as uuid } from "uuid";
</script> </script>
<script lang="ts"> <script lang="ts">
@ -55,6 +56,14 @@ export default defineComponent({
return tables; return tables;
}, },
value: {
get() {
return this.modelValue;
},
set(val: DynamicQueryStructure) {
this.$emit("update:model-value", val);
},
},
table: { table: {
get() { get() {
return this.modelValue.table || ""; return this.modelValue.table || "";
@ -96,5 +105,10 @@ export default defineComponent({
}, },
}, },
}, },
mounted() {
if (!this.value.id) {
this.value.id = uuid();
}
},
}); });
</script> </script>

View file

@ -5,6 +5,7 @@
<div v-for="(condition, index) in value" class="contents"> <div v-for="(condition, index) in value" class="contents">
<NestedCondition <NestedCondition
v-if="condition.structureType == 'nested'" v-if="condition.structureType == 'nested'"
:isFirst="index == 0"
:model-value="condition" :model-value="condition"
:table="table" :table="table"
@update:model-value="($event) => (value[index] = $event)" @update:model-value="($event) => (value[index] = $event)"
@ -12,6 +13,7 @@
/> />
<Condition <Condition
v-else v-else
:isFirst="index == 0"
:model-value="condition" :model-value="condition"
:table="table" :table="table"
@update:model-value="($event) => (value[index] = $event)" @update:model-value="($event) => (value[index] = $event)"
@ -74,14 +76,14 @@ export default defineComponent({
addNestedToValue() { addNestedToValue() {
this.value.push({ this.value.push({
structureType: "nested", structureType: "nested",
concat: this.value.length == 0 ? "_" : "AND", concat: "AND",
conditions: [], conditions: [],
}); });
}, },
addConditionToValue() { addConditionToValue() {
this.value.push({ this.value.push({
structureType: "condition", structureType: "condition",
concat: this.value.length == 0 ? "_" : "AND", concat: "AND",
operation: "eq", operation: "eq",
column: "", column: "",
value: "", value: "",