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-19 10:32:58 +01:00
|
|
|
<div class="flex flex-row max-lg:flex-wrap 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="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>
|
2024-12-19 10:32:58 +01:00
|
|
|
<div
|
|
|
|
v-if="allowPredefinedSelect && can('read', 'settings', 'query_store')"
|
|
|
|
class="flex flex-row gap-2 max-lg:w-full max-lg:order-10"
|
|
|
|
>
|
2024-12-18 22:27:44 +01:00
|
|
|
<select v-model="activeQueryId" class="max-h-[34px] !py-0">
|
|
|
|
<option :value="undefined" disabled>gepeicherte Anfrage auswählen</option>
|
|
|
|
<option v-for="query in queries" :key="query.id" :value="query.id" @click="value = query.query">
|
|
|
|
{{ query.title }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
<div
|
|
|
|
v-if="can('create', 'settings', 'query_store')"
|
|
|
|
class="p-1 border border-gray-400 bg-gray-100 rounded-md"
|
|
|
|
title="Abfrage speichern"
|
|
|
|
@click="$emit('query:save')"
|
|
|
|
>
|
|
|
|
<InboxArrowDownIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-12-19 10:32:58 +01:00
|
|
|
<div class="grow max-lg:hidden"></div>
|
|
|
|
<div class="flex flex-row min-w-fit 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"
|
2024-12-18 22:27:44 +01:00
|
|
|
:class="typeof value == 'object' ? 'bg-gray-200' : ''"
|
2024-12-17 16:52:03 +01:00
|
|
|
title="Visual Builder"
|
|
|
|
@click="queryMode = 'builder'"
|
|
|
|
>
|
|
|
|
<RectangleGroupIcon class="text-gray-500 h-6 w-6 cursor-pointer" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
class="p-1"
|
2024-12-18 22:27:44 +01:00
|
|
|
:class="typeof value == 'string' ? 'bg-gray-200' : ''"
|
2024-12-17 16:52:03 +01:00
|
|
|
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-18 22:27:44 +01:00
|
|
|
import { mapActions, mapState, mapWritableState } from "pinia";
|
2024-12-14 17:02:34 +01:00
|
|
|
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-18 22:27:44 +01:00
|
|
|
import { useAbilityStore } from "@/stores/ability";
|
|
|
|
import { useQueryStoreStore } from "@/stores/admin/queryStore";
|
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-18 22:27:44 +01:00
|
|
|
allowPredefinedSelect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2024-12-14 17:02:34 +01:00
|
|
|
},
|
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 = "";
|
|
|
|
}
|
|
|
|
},
|
2024-12-18 22:27:44 +01:00
|
|
|
activeQueryId() {
|
|
|
|
let query = this.queries.find((t) => t.id == this.activeQueryId)?.query;
|
|
|
|
if (query != undefined) {
|
|
|
|
this.value = query;
|
|
|
|
}
|
|
|
|
},
|
2024-12-17 16:52:03 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-12-18 22:27:44 +01:00
|
|
|
autoChangeFlag: false as boolean,
|
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: {
|
2024-12-18 22:27:44 +01:00
|
|
|
...mapState(useAbilityStore, ["can"]),
|
2024-12-14 17:02:34 +01:00
|
|
|
...mapState(useQueryBuilderStore, ["tableMetas", "loading"]),
|
2024-12-18 22:27:44 +01:00
|
|
|
...mapWritableState(useQueryBuilderStore, ["activeQueryId"]),
|
|
|
|
...mapState(useQueryStoreStore, ["queries"]),
|
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();
|
2024-12-18 22:27:44 +01:00
|
|
|
this.fetchQueries();
|
2024-12-14 17:02:34 +01:00
|
|
|
},
|
|
|
|
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-18 22:27:44 +01:00
|
|
|
...mapActions(useQueryStoreStore, ["fetchQueries"]),
|
2024-12-17 16:52:03 +01:00
|
|
|
clearQuery() {
|
|
|
|
this.$emit("update:model-value", undefined);
|
2024-12-18 22:27:44 +01:00
|
|
|
this.activeQueryId = undefined;
|
|
|
|
if (typeof this.value != "string") {
|
2024-12-17 16:52:03 +01:00
|
|
|
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>
|