ff-admin/src/components/queryBuilder/Condition.vue

115 lines
3.2 KiB
Vue
Raw Normal View History

2024-12-16 15:39:49 +01:00
<template>
<div class="flex flex-row gap-2 items-center w-full">
<select v-if="concat != '_'" v-model="concat" class="!w-20 !h-fit">
<option value="" disabled>Verknüpfung auswählen</option>
<option v-for="operation in ['AND', 'OR']" :value="operation">
{{ operation }}
</option>
</select>
<select v-model="column">
<option value="" disabled>Verknüpfung auswählen</option>
2024-12-16 17:49:18 +01:00
<option v-for="col in activeTable?.columns" :value="col.column">
2024-12-16 15:39:49 +01:00
{{ foreignColumns?.includes(col.column) ? "FK:" : "" }} {{ col.column }}:{{ col.type }}
</option>
</select>
2024-12-16 17:49:18 +01:00
<select v-model="operation" class="!w-fit !h-fit">
<option value="" disabled>Vergleich auswählen</option>
<option v-for="op in whereOperationArray" :value="op">
{{ op }}
</option>
</select>
<input v-model="value" :type="inputType" />
2024-12-16 15:39:49 +01:00
<div class="p-1 border border-gray-400 hover:bg-gray-200 rounded-md" @click="$emit('remove')">
<TrashIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
</div>
</div>
</template>
<script setup lang="ts">
import { defineComponent, type PropType } from "vue";
import { mapActions, mapState } from "pinia";
2024-12-16 17:49:18 +01:00
import {
whereOperationArray,
type ConditionStructure,
type ConditionValue,
type WhereOperation,
type WhereType,
} from "../../types/dynamicQueries";
2024-12-16 15:39:49 +01:00
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
import { TrashIcon } from "@heroicons/vue/24/outline";
</script>
<script lang="ts">
export default defineComponent({
props: {
table: {
type: String,
default: "",
},
modelValue: {
type: Object as PropType<ConditionStructure & { structureType: "condition" }>,
default: {},
},
},
emits: ["update:model-value", "remove"],
data() {
return {};
},
computed: {
...mapState(useQueryBuilderStore, ["tableMetas"]),
activeTable() {
return this.tableMetas.find((tm) => tm.tableName == this.table);
},
foreignColumns() {
return this.activeTable?.relations.map((r) => r.column);
},
2024-12-16 17:49:18 +01:00
inputType() {
let type = this.activeTable?.columns.find((c) => c.column == this.column)?.type;
if (this.operation.includes("timespan")) return "number";
switch (type) {
case "int":
return "number";
case "varchar":
return "text";
case "date":
return "date";
default:
return "text";
}
},
2024-12-16 15:39:49 +01:00
concat: {
get() {
return this.modelValue.concat;
},
set(val: WhereType) {
this.$emit("update:model-value", { ...this.modelValue, concat: val });
},
},
column: {
get() {
return this.modelValue.column;
},
set(val: string) {
this.$emit("update:model-value", { ...this.modelValue, column: val });
},
},
operation: {
get() {
return this.modelValue.operation;
},
set(val: WhereOperation) {
this.$emit("update:model-value", { ...this.modelValue, operation: val });
},
},
value: {
get() {
return this.modelValue.value;
},
set(val: ConditionValue) {
this.$emit("update:model-value", { ...this.modelValue, value: val });
},
},
},
});
</script>