mirror of https://github.com/nocodb/nocodb
237 lines
6.7 KiB
237 lines
6.7 KiB
4 years ago
|
<template>
|
||
3 years ago
|
<v-container fluid class="pa-0 ma-0 nc-table-tab" style="height: 100%">
|
||
4 years ago
|
<v-alert v-if="error" type="error" class="ma-2">
|
||
|
{{ error }}
|
||
|
</v-alert>
|
||
|
<template v-else>
|
||
|
<v-tabs
|
||
|
v-model="active"
|
||
3 years ago
|
:height="relationTabs && relationTabs.length ? 38 : 0"
|
||
4 years ago
|
class="table-tabs"
|
||
3 years ago
|
:class="{ 'hidden-tab': !relationTabs || !relationTabs.length }"
|
||
4 years ago
|
color="pink"
|
||
3 years ago
|
@change="onTabChange"
|
||
4 years ago
|
>
|
||
3 years ago
|
<template v-if="_isUIAllowed('smartSheet')">
|
||
3 years ago
|
<v-tab v-show="relationTabs && relationTabs.length" class="">
|
||
3 years ago
|
<v-icon small> mdi-table-edit </v-icon> <span class="caption text-capitalize font-weight-bold">
|
||
|
{{ nodes.title }}</span
|
||
3 years ago
|
>
|
||
3 years ago
|
</v-tab>
|
||
3 years ago
|
<v-tab-item style="height: 100%">
|
||
4 years ago
|
<rows-xc-data-table
|
||
|
ref="tabs7"
|
||
3 years ago
|
:is-view="isView"
|
||
3 years ago
|
:is-active="isActive"
|
||
3 years ago
|
:tab-id="tabId"
|
||
3 years ago
|
:show-tabs="relationTabs && relationTabs.length"
|
||
3 years ago
|
:table="nodes.table_name"
|
||
4 years ago
|
:nodes="nodes"
|
||
3 years ago
|
:new-table="newTableCopy"
|
||
|
:mtd-new-table-update="mtdNewTableUpdate"
|
||
|
:delete-table="deleteTable"
|
||
4 years ago
|
:is-meta-table="isMetaTable"
|
||
|
/>
|
||
4 years ago
|
</v-tab-item>
|
||
|
</template>
|
||
|
</v-tabs>
|
||
|
</template>
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="dialogShow"
|
||
3 years ago
|
type="error"
|
||
|
:actions-mtd="deleteTable"
|
||
|
:dialog-show="dialogShow"
|
||
4 years ago
|
heading="Click Submit to Delete the Table"
|
||
|
/>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapActions } from 'vuex';
|
||
|
import { UITypes } from 'nocodb-sdk';
|
||
|
import dlgLabelSubmitCancel from '../utils/DlgLabelSubmitCancel';
|
||
|
import { isMetaTable } from '@/helpers/xutils';
|
||
|
import RowsXcDataTable from '~/components/project/spreadsheet/RowsXcDataTable';
|
||
4 years ago
|
|
||
|
export default {
|
||
|
components: {
|
||
|
RowsXcDataTable,
|
||
3 years ago
|
dlgLabelSubmitCancel,
|
||
4 years ago
|
},
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
error: false,
|
||
3 years ago
|
active: 1,
|
||
3 years ago
|
newTableCopy: !!this.nodes.newTable,
|
||
4 years ago
|
dialogShow: false,
|
||
|
loadIndexList: false,
|
||
|
loadTriggerList: false,
|
||
|
loadRelationList: false,
|
||
|
loadConstraintList: false,
|
||
|
loadRows: false,
|
||
|
loadColumnsMock: false,
|
||
3 years ago
|
relationTabs: [],
|
||
3 years ago
|
deleteId: null,
|
||
|
};
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async handleKeyDown(event) {
|
||
3 years ago
|
const activeTabEleKey = `tabs${this.active}`;
|
||
|
if (this.$refs[activeTabEleKey] && this.$refs[activeTabEleKey].handleKeyDown) {
|
||
|
await this.$refs[activeTabEleKey].handleKeyDown(event);
|
||
4 years ago
|
}
|
||
|
},
|
||
|
...mapActions({
|
||
3 years ago
|
removeTableTab: 'tabs/removeTableTab',
|
||
3 years ago
|
loadTablesFromParentTreeNode: 'project/loadTablesFromParentTreeNode',
|
||
4 years ago
|
}),
|
||
3 years ago
|
mtdNewTableUpdate(value) {
|
||
3 years ago
|
this.newTableCopy = value;
|
||
4 years ago
|
},
|
||
3 years ago
|
async deleteTable(action = '', id) {
|
||
3 years ago
|
if (id) {
|
||
3 years ago
|
this.deleteId = id;
|
||
3 years ago
|
}
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
3 years ago
|
this.dialogShow = true;
|
||
3 years ago
|
} else if (action === 'hideDialog') {
|
||
3 years ago
|
this.dialogShow = false;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
try {
|
||
3 years ago
|
const meta = await this.$store.dispatch('meta/ActLoadMeta', { id: this.deleteId });
|
||
3 years ago
|
|
||
3 years ago
|
const relationColumns = meta.columns.filter(c => c.uidt === UITypes.LinkToAnotherRecord);
|
||
3 years ago
|
|
||
|
if (relationColumns.length) {
|
||
3 years ago
|
const refColMsgs = await Promise.all(
|
||
|
relationColumns.map(async (c, i) => {
|
||
|
const refMeta = await this.$store.dispatch('meta/ActLoadMeta', {
|
||
|
id: c.colOptions.fk_related_model_id,
|
||
|
});
|
||
|
return `${i + 1}. ${c.title} is a LinkToAnotherRecord of ${(refMeta && refMeta.title) || c.title}`;
|
||
|
})
|
||
|
);
|
||
|
this.$toast
|
||
|
.info(
|
||
|
`<div style="padding:10px 4px">Unable to delete tables because of the following.
|
||
3 years ago
|
<br><br>${refColMsgs.join('<br>')}<br><br>
|
||
|
Delete them & try again</div>
|
||
3 years ago
|
`
|
||
|
)
|
||
|
.goAway(10000);
|
||
|
this.dialogShow = false;
|
||
|
return;
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
await this.$api.dbTable.delete(this.deleteId);
|
||
3 years ago
|
|
||
|
this.removeTableTab({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
3 years ago
|
table_name: this.nodes.table_name,
|
||
|
});
|
||
3 years ago
|
|
||
|
await this.loadTablesFromParentTreeNode({
|
||
|
_nodes: {
|
||
3 years ago
|
...this.nodes,
|
||
|
},
|
||
|
});
|
||
3 years ago
|
|
||
3 years ago
|
this.$store.commit('meta/MutMeta', {
|
||
3 years ago
|
key: this.nodes.table_name,
|
||
3 years ago
|
value: null,
|
||
|
});
|
||
3 years ago
|
this.$store.commit('meta/MutMeta', {
|
||
3 years ago
|
key: this.deleteId,
|
||
3 years ago
|
value: null,
|
||
|
});
|
||
|
this.$toast.info(`Deleted table ${this.nodes.title} successfully`).goAway(3000);
|
||
3 years ago
|
} catch (e) {
|
||
3 years ago
|
const msg = await this._extractSdkResponseErrorMsg(e);
|
||
|
this.$toast.error(msg).goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.dialogShow = false;
|
||
|
this.$e('a:table:delete');
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
onTabChange() {
|
||
3 years ago
|
this.$emit('update:hideLogWindows', this.active === 2);
|
||
|
},
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
isMetaTable() {
|
||
3 years ago
|
return isMetaTable(this.nodes.table_name);
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
3 years ago
|
this.onTabChange();
|
||
4 years ago
|
},
|
||
3 years ago
|
props: {
|
||
|
nodes: Object,
|
||
|
hideLogWindows: Boolean,
|
||
|
tabId: String,
|
||
|
isActive: Boolean,
|
||
3 years ago
|
isView: Boolean,
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
3 years ago
|
/*/deep/ .table-tabs > .v-tabs-items {
|
||
4 years ago
|
border-top: 1px solid #7F828B33;
|
||
3 years ago
|
}*/
|
||
4 years ago
|
|
||
|
/deep/ .scaffoldOnSave .v-input__control {
|
||
|
margin-top: -2px;
|
||
|
}
|
||
|
|
||
3 years ago
|
.table-tabs,
|
||
|
/deep/ .table-tabs > .v-windows {
|
||
4 years ago
|
height: 100%;
|
||
|
}
|
||
4 years ago
|
|
||
4 years ago
|
/deep/ .v-window-item {
|
||
3 years ago
|
height: 100%;
|
||
4 years ago
|
}
|
||
|
|
||
|
.rel-row-parent {
|
||
|
text-align: center;
|
||
|
left: 0;
|
||
|
padding: 2px 3px;
|
||
|
text-transform: none;
|
||
|
display: inline-block;
|
||
|
position: absolute;
|
||
|
top: 0;
|
||
|
font-size: 8px;
|
||
|
white-space: nowrap;
|
||
|
text-overflow: ellipsis;
|
||
|
width: 100%;
|
||
|
overflow: hidden;
|
||
|
color: grey;
|
||
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|