Skip to content
Snippets Groups Projects
Commit 92e089a5 authored by Kirill Stytsenko's avatar Kirill Stytsenko
Browse files

Better `refresh` function

Former-commit-id: d0d3a52c
parent ae95abee
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
(no tables) (no tables)
</v-card-title> </v-card-title>
</v-card> </v-card>
<v-expansion-panels v-if="!loading && tables.length > 0" accordion> <v-expansion-panels v-if="!loading && tables.length > 0" v-model="panel" accordion>
<v-expansion-panel v-for="(item,i) in tables" :key="i" @click="details(item)"> <v-expansion-panel v-for="(item,i) in tables" :key="i" @click="details(item.id, true)">
<v-expansion-panel-header> <v-expansion-panel-header>
{{ item.name }} {{ item.name }}
</v-expansion-panel-header> </v-expansion-panel-header>
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
{{ col.column_type }} {{ col.column_type }}
</td> </td>
<td> <td>
<DialogsColumnUnit :column="col" :table-id="tableDetails.id" /> <DialogsColumnUnit :column="col" :table-id="tableDetails.id" @save="details" />
</td> </td>
<td> <td>
<v-simple-checkbox v-model="col.is_primary_key" disabled aria-readonly="true" /> <v-simple-checkbox v-model="col.is_primary_key" disabled aria-readonly="true" />
...@@ -163,6 +163,7 @@ export default { ...@@ -163,6 +163,7 @@ export default {
return { return {
loading: false, loading: false,
tables: [], tables: [],
panel: null,
tableDetails: { tableDetails: {
id: null, id: null,
internal_name: null, internal_name: null,
...@@ -178,12 +179,13 @@ export default { ...@@ -178,12 +179,13 @@ export default {
this.refresh() this.refresh()
}, },
methods: { methods: {
async details (table) { async details (tableId, clicked = false) {
if (this.tableDetails.id === table.id) { // don't fetch details when we click-close an open accordion
if (clicked && this.tables[this.panel] && this.tables[this.panel].id === tableId) {
return return
} }
try { try {
const res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/table/${table.id}`) const res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/table/${tableId}`)
console.debug('table', res.data) console.debug('table', res.data)
this.tableDetails = res.data this.tableDetails = res.data
} catch (err) { } catch (err) {
...@@ -191,14 +193,17 @@ export default { ...@@ -191,14 +193,17 @@ export default {
this.$toast.error('Could not get table details.') this.$toast.error('Could not get table details.')
} }
}, },
async refresh () { /**
// XXX same as in QueryBuilder * if tableId is given, open the table after refresh
*/
async refresh (tableId) {
let res let res
try { try {
this.loading = true this.loading = true
res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/table`) res = await this.$axios.get(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/table`)
this.tables = res.data this.tables = res.data
this.loading = false this.loading = false
if (tableId) { this.openPanelByTableId(tableId) }
} catch (err) { } catch (err) {
this.$toast.error('Could not list table.') this.$toast.error('Could not list table.')
} }
...@@ -217,6 +222,12 @@ export default { ...@@ -217,6 +222,12 @@ export default {
showDeleteTableDialog (id) { showDeleteTableDialog (id) {
this.deleteTableId = id this.deleteTableId = id
this.dialogDelete = true this.dialogDelete = true
},
/**
* open up the accordion with the table that has been updated (by the ColumnUnit dialog)
*/
openPanelByTableId (id) {
this.panel = this.tables.findIndex(t => t.id === id)
} }
} }
} }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
v-model="dialog" v-model="dialog"
max-width="600px"> max-width="600px">
<template v-slot:activator="{ on, attrs }"> <template v-slot:activator="{ on, attrs }">
<i v-if="!name">unspecified</i>
<span v-else>{{ name }}</span>
<v-btn <v-btn
class="ml-2" class="ml-2"
icon icon
...@@ -169,7 +167,6 @@ export default { ...@@ -169,7 +167,6 @@ export default {
console.log(error) console.log(error)
} }
} }
console.log(this.$route.params.database_id, this.tableId, this.column)
try { try {
await this.$axios.post('/api/units/savecolumnsconcept', { await this.$axios.post('/api/units/savecolumnsconcept', {
cdbid: Number(this.$route.params.database_id), cdbid: Number(this.$route.params.database_id),
...@@ -180,7 +177,7 @@ export default { ...@@ -180,7 +177,7 @@ export default {
this.dialog = false this.dialog = false
this.saved = true this.saved = true
this.$nextTick(() => { this.$nextTick(() => {
this.$emit('save') this.$emit('save', this.tableId)
}) })
} catch (err) { } catch (err) {
this.$toast.error('Could not save column unit.') this.$toast.error('Could not save column unit.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment