From 56c310b7f88fb9a0c4b9b7b6586194cdda0c3d2f Mon Sep 17 00:00:00 2001
From: Martin Weise <martin.weise@tuwien.ac.at>
Date: Thu, 23 Sep 2021 19:38:28 +0200
Subject: [PATCH] disabled the other dbs for query-re execution feature

Former-commit-id: d046f638ccd323e3d5d7e34ca3f0efe0042d48c6
---
 fda-ui/components/QueryList.vue               |  2 +-
 fda-ui/components/dialogs/CreateDB.vue        |  5 +-
 fda-ui/components/query/Builder.vue           |  2 +-
 .../_database_id/queries/_query_id/index.vue  | 56 +++++++++++++++++++
 fda-ui/server-middleware/query/index.js       |  2 +-
 5 files changed, 63 insertions(+), 4 deletions(-)
 create mode 100644 fda-ui/pages/databases/_database_id/queries/_query_id/index.vue

diff --git a/fda-ui/components/QueryList.vue b/fda-ui/components/QueryList.vue
index 4e2c5a6eb8..1b1cad9609 100644
--- a/fda-ui/components/QueryList.vue
+++ b/fda-ui/components/QueryList.vue
@@ -70,7 +70,7 @@
           </v-row>
           <v-row dense>
             <v-col>
-              <v-btn color="primary" :to="`/databases/${$route.params.database_id}/tables/${item.id}`" disabled>
+              <v-btn color="primary" :to="`/databases/${$route.params.database_id}/queries/${item.id}`">
                 <v-icon left>mdi-run</v-icon> Execute Again
               </v-btn>
             </v-col>
diff --git a/fda-ui/components/dialogs/CreateDB.vue b/fda-ui/components/dialogs/CreateDB.vue
index ed5e242be0..44dc286475 100644
--- a/fda-ui/components/dialogs/CreateDB.vue
+++ b/fda-ui/components/dialogs/CreateDB.vue
@@ -89,7 +89,10 @@ export default {
       let res
       try {
         res = await this.$axios.get('/api/image/')
-        this.engines = res.data
+        this.engines = res.data.map((e) => {
+          e.disabled = (e.id !== 3)
+          return e
+        })
         console.debug('engines', this.engines)
       } catch (err) {
         this.$toast.error('Failed to fetch supported engines. Try reload the page.')
diff --git a/fda-ui/components/query/Builder.vue b/fda-ui/components/query/Builder.vue
index aa2a9f7c60..e6d01bf970 100644
--- a/fda-ui/components/query/Builder.vue
+++ b/fda-ui/components/query/Builder.vue
@@ -97,7 +97,7 @@ export default {
   },
   methods: {
     async execute () {
-      const query = this.query.sql.replaceAll('"', '')
+      const query = this.query.sql.replaceAll('`', '')
       this.loading = true
       try {
         const res = await this.$axios.put(`/api/database/${this.$route.params.database_id}/query`, {
diff --git a/fda-ui/pages/databases/_database_id/queries/_query_id/index.vue b/fda-ui/pages/databases/_database_id/queries/_query_id/index.vue
new file mode 100644
index 0000000000..3cd6e8e5cd
--- /dev/null
+++ b/fda-ui/pages/databases/_database_id/queries/_query_id/index.vue
@@ -0,0 +1,56 @@
+<template>
+  <div>
+    <v-card>
+      <v-card-title v-if="!loading">
+        Result of Query #{{ id }}
+      </v-card-title>
+      <v-card-subtitle v-if="!loading">
+        <code v-if="hash">{{ hash }}</code>
+      </v-card-subtitle>
+      <v-data-table
+        :headers="headers"
+        :items="rows"
+        :loading="loading"
+        :items-per-page="30"
+        class="elevation-1" />
+    </v-card>
+  </div>
+</template>
+<script>
+export default {
+  name: 'QueryShow',
+  components: {
+  },
+  data () {
+    return {
+      id: this.$route.params.query_id,
+      hash: null,
+      loading: true,
+      table: null,
+      headers: [],
+      rows: []
+    }
+  },
+  mounted () {
+    this.loadData()
+  },
+  methods: {
+    async loadData () {
+      try {
+        const res = await this.$axios.get(`/api/database/${this.$route.params.database_id}/query/${this.$route.params.query_id}`)
+        this.headers = Object.keys(res.data.result[0]).map((c) => {
+          return { text: c, value: c }
+        })
+        this.rows = res.data.result
+        console.debug('query data', res.data)
+      } catch (err) {
+        this.$toast.error('Could not load table data.')
+      }
+      this.loading = false
+    }
+  }
+}
+</script>
+
+<style>
+</style>
diff --git a/fda-ui/server-middleware/query/index.js b/fda-ui/server-middleware/query/index.js
index 9cf322c330..bb688815c9 100644
--- a/fda-ui/server-middleware/query/index.js
+++ b/fda-ui/server-middleware/query/index.js
@@ -1,5 +1,5 @@
 const { format } = require('sql-formatter')
-const knex = require('knex')({ client: 'pg' })
+const knex = require('knex')({ client: 'mysql' })
 
 export function buildQuery ({ table, select, clauses }) {
   const builder = knex(table)
-- 
GitLab