2024-12-14 17:02:34 +01:00
|
|
|
<template>
|
2024-12-15 13:48:55 +01:00
|
|
|
<div class="flex flex-col border border-gray-300 rounded-md select-none">
|
2024-12-14 17:02:34 +01:00
|
|
|
<div class="flex flex-row gap-2 border-b border-gray-300 p-2">
|
2024-12-16 13:56:06 +01:00
|
|
|
<div
|
|
|
|
class="p-1 border border-gray-400 bg-green-200 rounded-md"
|
|
|
|
title="Abfrage starten"
|
|
|
|
@click="$emit('query:run')"
|
|
|
|
>
|
2024-12-14 17:02:34 +01:00
|
|
|
<PlayIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
2024-12-16 13:56:06 +01:00
|
|
|
<div
|
|
|
|
class="p-1 border border-gray-400 bg-gray-100 rounded-md"
|
|
|
|
title="Abfrage speichern"
|
|
|
|
@click="$emit('query:save')"
|
|
|
|
>
|
2024-12-14 17:02:34 +01:00
|
|
|
<InboxArrowDownIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
2024-12-16 13:56:06 +01:00
|
|
|
<div
|
|
|
|
class="p-1 border border-gray-400 bg-gray-100 rounded-md"
|
|
|
|
title="Ergebnisse exportieren"
|
|
|
|
@click="$emit('results:export')"
|
|
|
|
>
|
|
|
|
<ArchiveBoxArrowDownIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="p-1 border border-gray-400 bg-red-200 rounded-md"
|
|
|
|
title="Ergebnisse leeren"
|
|
|
|
@click="$emit('results:clear')"
|
|
|
|
>
|
2024-12-14 17:02:34 +01:00
|
|
|
<NoSymbolIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
2024-12-17 16:52:03 +01:00
|
|
|
<div class="p-1 border border-gray-400 bg-red-200 rounded-md" title="Anfrage löschen" @click="clearQuery">
|
2024-12-16 17:49:18 +01:00
|
|
|
<TrashIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
2024-12-17 16:52:03 +01:00
|
|
|
<div class="grow"></div>
|
|
|
|
<div class="flex flex-row overflow-hidden border border-gray-400 rounded-md">
|
2024-12-18 14:29:33 +01:00
|
|
|
<div
|
|
|
|
class="p-1"
|
|
|
|
:class="queryMode == 'structure' ? 'bg-gray-200' : ''"
|
|
|
|
title="Schema-Struktur"
|
|
|
|
@click="queryMode = 'structure'"
|
|
|
|
>
|
|
|
|
<SparklesIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
2024-12-17 16:52:03 +01:00
|
|
|
<div
|
|
|
|
class="p-1"
|
|
|
|
:class="queryMode == 'builder' ? 'bg-gray-200' : ''"
|
|
|
|
title="Visual Builder"
|
|
|
|
@click="queryMode = 'builder'"
|
|
|
|
>
|
|
|
|
<RectangleGroupIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="p-1"
|
|
|
|
:class="queryMode == 'editor' ? 'bg-gray-200' : ''"
|
|
|
|
title="SQL Editor"
|
|
|
|
@click="queryMode = 'editor'"
|
|
|
|
>
|
|
|
|
<CommandLineIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-12-14 17:02:34 +01:00
|
|
|
</div>
|
2024-12-17 16:52:03 +01:00
|
|
|
<div class="p-2 h-44 md:h-60 w-full overflow-y-auto">
|
2024-12-18 14:29:33 +01:00
|
|
|
<div v-if="queryMode == 'structure'">
|
|
|
|
<img src="/administration-db.png" class="h-full w-full cursor-pointer" @click="showStructure" />
|
|
|
|
</div>
|
|
|
|
<textarea v-else-if="typeof value == 'string'" v-model="value" placeholder="SQL Query" class="h-full w-full" />
|
2024-12-17 16:52:03 +01:00
|
|
|
<Table v-else v-model="value" />
|
2024-12-14 17:02:34 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-12-18 14:29:33 +01:00
|
|
|
import { defineAsyncComponent, defineComponent, markRaw, type PropType } from "vue";
|
2024-12-14 17:02:34 +01:00
|
|
|
import { mapActions, mapState } from "pinia";
|
|
|
|
import type { DynamicQueryStructure } from "../../types/dynamicQueries";
|
2024-12-16 17:49:18 +01:00
|
|
|
import {
|
|
|
|
ArchiveBoxArrowDownIcon,
|
2024-12-17 16:52:03 +01:00
|
|
|
CommandLineIcon,
|
2024-12-16 17:49:18 +01:00
|
|
|
InboxArrowDownIcon,
|
|
|
|
NoSymbolIcon,
|
|
|
|
PlayIcon,
|
2024-12-17 16:52:03 +01:00
|
|
|
RectangleGroupIcon,
|
2024-12-16 17:49:18 +01:00
|
|
|
TrashIcon,
|
2024-12-18 14:29:33 +01:00
|
|
|
SparklesIcon,
|
2024-12-16 17:49:18 +01:00
|
|
|
} from "@heroicons/vue/24/outline";
|
2024-12-14 17:02:34 +01:00
|
|
|
import { useQueryBuilderStore } from "../../stores/admin/queryBuilder";
|
2024-12-18 14:29:33 +01:00
|
|
|
import { useModalStore } from "../../stores/modal";
|
2024-12-15 13:48:55 +01:00
|
|
|
import Table from "./Table.vue";
|
2024-12-14 17:02:34 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
2024-12-15 13:48:55 +01:00
|
|
|
modelValue: {
|
2024-12-17 16:52:03 +01:00
|
|
|
type: [Object, String] as PropType<DynamicQueryStructure | string>,
|
2024-12-14 17:02:34 +01:00
|
|
|
default: {
|
|
|
|
select: "*",
|
|
|
|
table: "",
|
|
|
|
where: [],
|
|
|
|
join: [],
|
|
|
|
orderBy: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-12-16 13:56:06 +01:00
|
|
|
emits: ["update:model-value", "query:run", "query:save", "results:export", "results:clear"],
|
2024-12-17 16:52:03 +01:00
|
|
|
watch: {
|
|
|
|
queryMode() {
|
|
|
|
if (this.queryMode == "builder") {
|
|
|
|
this.value = {
|
|
|
|
select: "*",
|
|
|
|
table: "",
|
|
|
|
where: [],
|
|
|
|
join: [],
|
|
|
|
orderBy: [],
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.value = "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-12-18 14:29:33 +01:00
|
|
|
queryMode: "builder" as "builder" | "editor" | "structure",
|
2024-12-17 16:52:03 +01:00
|
|
|
};
|
|
|
|
},
|
2024-12-14 17:02:34 +01:00
|
|
|
computed: {
|
|
|
|
...mapState(useQueryBuilderStore, ["tableMetas", "loading"]),
|
2024-12-15 13:48:55 +01:00
|
|
|
value: {
|
|
|
|
get() {
|
|
|
|
return this.modelValue;
|
|
|
|
},
|
|
|
|
set(val: DynamicQueryStructure) {
|
|
|
|
this.$emit("update:model-value", val);
|
|
|
|
},
|
|
|
|
},
|
2024-12-14 17:02:34 +01:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.fetchTableMetas();
|
|
|
|
},
|
|
|
|
methods: {
|
2024-12-18 14:29:33 +01:00
|
|
|
...mapActions(useModalStore, ["openModal"]),
|
2024-12-14 17:02:34 +01:00
|
|
|
...mapActions(useQueryBuilderStore, ["fetchTableMetas"]),
|
2024-12-17 16:52:03 +01:00
|
|
|
clearQuery() {
|
|
|
|
this.$emit("update:model-value", undefined);
|
|
|
|
if (this.queryMode == "builder") {
|
|
|
|
this.value = {
|
|
|
|
select: "*",
|
|
|
|
table: "",
|
|
|
|
where: [],
|
|
|
|
join: [],
|
|
|
|
orderBy: [],
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.value = "";
|
|
|
|
}
|
|
|
|
},
|
2024-12-18 14:29:33 +01:00
|
|
|
showStructure() {
|
|
|
|
this.openModal(markRaw(defineAsyncComponent(() => import("@/components/queryBuilder/StructureModal.vue"))));
|
|
|
|
},
|
2024-12-14 17:02:34 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|