2024-12-17 16:52:03 +01:00
|
|
|
<template>
|
|
|
|
<div class="flex flex-row gap-2 w-full">
|
|
|
|
<div class="flex flex-row gap-2 w-full">
|
|
|
|
<div class="flex flex-col gap-2 w-full">
|
2025-04-16 16:11:10 +02:00
|
|
|
<div class="flex flex-row gap-2 w-full">
|
|
|
|
<div
|
|
|
|
class="h-fit p-1 border border-gray-400 hover:bg-gray-200 rounded-md"
|
|
|
|
title="Join Modus wechseln"
|
|
|
|
@click="swapJoinType(value.type)"
|
2025-04-15 09:26:25 +02:00
|
|
|
>
|
2025-04-16 16:11:10 +02:00
|
|
|
<ArrowsUpDownIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<select v-if="value.type == 'defined'" v-model="context" class="w-full">
|
|
|
|
<option value="" disabled>Relation auswählen</option>
|
|
|
|
<option
|
|
|
|
v-for="relation in activeTable?.relations"
|
|
|
|
:value="relation.column"
|
|
|
|
:disabled="
|
2025-04-15 09:26:25 +02:00
|
|
|
alreadyJoined.includes(joinTableName(relation.referencedTableName)) &&
|
|
|
|
joinTableName(relation.referencedTableName) != value.table
|
|
|
|
"
|
|
|
|
>
|
2025-04-16 16:11:10 +02:00
|
|
|
{{ relation.column }} -> {{ joinTableName(relation.referencedTableName) }}
|
|
|
|
<span
|
|
|
|
v-if="
|
|
|
|
alreadyJoined.includes(joinTableName(relation.referencedTableName)) &&
|
|
|
|
joinTableName(relation.referencedTableName) != value.table
|
|
|
|
"
|
|
|
|
>
|
|
|
|
(Join auf dieser Ebene besteht schon)
|
|
|
|
</span>
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
<div v-else class="flex flex-col w-full">
|
|
|
|
<select v-model="joinTable">
|
|
|
|
<option value="" disabled>Tabelle auswählen</option>
|
|
|
|
<option
|
|
|
|
v-for="table in tableMetas"
|
|
|
|
:value="table.tableName"
|
|
|
|
:disabled="alreadyJoined.includes(table.tableName) && table.tableName != value.table"
|
|
|
|
>
|
|
|
|
{{ table.tableName }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
<input v-model="context" type="text" placeholder="Join Condition tabA.col = tabB.col" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Table v-model="value" disable-table-select :show-table-select="false" />
|
2024-12-17 16:52:03 +01:00
|
|
|
</div>
|
|
|
|
<div class="h-fit 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>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent, type PropType } from "vue";
|
|
|
|
import { mapActions, mapState } from "pinia";
|
2025-04-16 16:11:10 +02:00
|
|
|
import { type DynamicQueryStructure, type JoinStructure } from "@/types/dynamicQueries";
|
2025-01-02 18:28:13 +01:00
|
|
|
import { useQueryBuilderStore } from "@/stores/admin/club/queryBuilder";
|
2024-12-17 16:52:03 +01:00
|
|
|
import Table from "./Table.vue";
|
2025-04-16 16:11:10 +02:00
|
|
|
import { ArrowsUpDownIcon, TrashIcon } from "@heroicons/vue/24/outline";
|
2024-12-19 10:32:58 +01:00
|
|
|
import { joinTableName } from "@/helpers/queryFormatter";
|
2025-04-15 10:29:25 +02:00
|
|
|
import { v4 as uuid } from "uuid";
|
2024-12-17 16:52:03 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
table: {
|
|
|
|
type: String,
|
|
|
|
default: "",
|
|
|
|
},
|
|
|
|
modelValue: {
|
2025-04-16 16:11:10 +02:00
|
|
|
type: Object as PropType<DynamicQueryStructure & JoinStructure>,
|
2025-04-15 09:26:25 +02:00
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
alreadyJoined: {
|
|
|
|
type: Array as PropType<Array<string>>,
|
|
|
|
default: [],
|
2024-12-17 16:52:03 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
emits: ["update:model-value", "remove"],
|
|
|
|
computed: {
|
|
|
|
...mapState(useQueryBuilderStore, ["tableMetas"]),
|
|
|
|
activeTable() {
|
|
|
|
return this.tableMetas.find((tm) => tm.tableName == this.table);
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
get() {
|
|
|
|
return this.modelValue;
|
|
|
|
},
|
2025-04-16 16:11:10 +02:00
|
|
|
set(val: DynamicQueryStructure & JoinStructure) {
|
2024-12-17 16:52:03 +01:00
|
|
|
this.$emit("update:model-value", val);
|
|
|
|
},
|
|
|
|
},
|
2025-04-16 16:11:10 +02:00
|
|
|
context: {
|
2024-12-17 16:52:03 +01:00
|
|
|
get() {
|
2025-04-16 16:11:10 +02:00
|
|
|
if (this.modelValue.type == "defined") {
|
|
|
|
return this.modelValue.foreignColumn ?? "";
|
|
|
|
} else {
|
|
|
|
return this.modelValue.condition ?? "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
set(val: string) {
|
|
|
|
console.log(val, this.modelValue.type);
|
|
|
|
if (this.modelValue.type == "defined") {
|
|
|
|
let relTable = this.activeTable?.relations.find((r) => r.column == val);
|
|
|
|
this.$emit("update:model-value", {
|
|
|
|
...this.modelValue,
|
|
|
|
foreignColumn: val,
|
|
|
|
table: joinTableName(relTable?.referencedTableName ?? ""),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$emit("update:model-value", {
|
|
|
|
...this.modelValue,
|
|
|
|
condition: val,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
joinTable: {
|
|
|
|
get(): string {
|
|
|
|
return this.modelValue.table;
|
2024-12-17 16:52:03 +01:00
|
|
|
},
|
|
|
|
set(val: string) {
|
|
|
|
this.$emit("update:model-value", {
|
|
|
|
...this.modelValue,
|
2025-04-16 16:11:10 +02:00
|
|
|
table: val,
|
2024-12-17 16:52:03 +01:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2025-04-15 10:29:25 +02:00
|
|
|
mounted() {
|
|
|
|
if (!this.value.id) {
|
|
|
|
this.value.id = uuid();
|
|
|
|
}
|
|
|
|
},
|
2025-04-16 16:11:10 +02:00
|
|
|
methods: {
|
|
|
|
swapJoinType(type: string) {
|
|
|
|
if (type == "defined") {
|
|
|
|
this.value.type = "custom";
|
|
|
|
} else {
|
|
|
|
this.value.type = "defined";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2024-12-17 16:52:03 +01:00
|
|
|
});
|
|
|
|
</script>
|