mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
822 lines
25 KiB
822 lines
25 KiB
4 years ago
|
<template>
|
||
|
<v-container fluid class="pa-0 ma-0" style="height: 100%">
|
||
3 years ago
|
<v-overlay v-if="isMetaTable" absolute>
|
||
2 years ago
|
<v-alert type="info"> Meta tables are not editable </v-alert>
|
||
4 years ago
|
</v-overlay>
|
||
|
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<v-toolbar-title>
|
||
3 years ago
|
<v-breadcrumbs
|
||
2 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.title + ' (table)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
2 years ago
|
<v-icon small color="grey lighten-2"> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
|
|
||
|
<x-btn
|
||
2 years ago
|
v-ge="['indexes', 'reload']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload Indexes"
|
||
|
small
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
@click="mtdRefreshIndexList"
|
||
4 years ago
|
>
|
||
2 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
|
v-if="indexCreationAllowed"
|
||
2 years ago
|
v-ge="['indexes', 'new']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Add New Index"
|
||
|
icon="mdi-plus"
|
||
|
small
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
@click="mtdAddIndex"
|
||
4 years ago
|
>
|
||
|
New Index
|
||
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
2 years ago
|
v-ge="['indexes', 'delete-table']"
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('activity.deleteTable')"
|
||
3 years ago
|
small
|
||
|
color="error "
|
||
|
class="error text-right"
|
||
|
@click="deleteTable('showDialog')"
|
||
4 years ago
|
>
|
||
2 years ago
|
<v-icon small> mdi-delete-outline </v-icon> Delete Table
|
||
4 years ago
|
</x-btn>
|
||
|
<!-- <x-btn outlined tooltip=""-->
|
||
|
<!-- icon-->
|
||
|
<!-- class="text-right">-->
|
||
|
<!-- <v-icon>mdi-help-circle-outline</v-icon>-->
|
||
|
<!-- </x-btn>-->
|
||
|
</v-toolbar>
|
||
|
|
||
|
<!-- <v-row class="pa-0 ma-0">-->
|
||
|
<!-- <v-col class="pr-0 ma-0" cols="8">-->
|
||
|
|
||
2 years ago
|
<splitpanes style="height: calc(100% - 42px)" class="xc-theme">
|
||
4 years ago
|
<pane min-size="33" size="66" style="overflow: auto">
|
||
|
<v-card class="elevation-0" style="">
|
||
2 years ago
|
<v-card-title class="headline justify-center"> Indexes </v-card-title>
|
||
4 years ago
|
<v-col>
|
||
3 years ago
|
<v-skeleton-loader v-if="loading" type="table" />
|
||
4 years ago
|
|
||
|
<v-data-table
|
||
|
v-else
|
||
|
dense
|
||
|
:headers="indexHeaders"
|
||
|
:items="aggregatedIndexes"
|
||
3 years ago
|
footer-props.items-per-page-options="30"
|
||
|
>
|
||
|
<template #item="props">
|
||
4 years ago
|
<tr>
|
||
|
<td>
|
||
|
<v-radio-group
|
||
|
v-model="selected"
|
||
2 years ago
|
v-ge="['indexes', 'radio']"
|
||
4 years ago
|
name="rowSelector"
|
||
|
dense
|
||
|
@change="mtdSelectColumnsForIndex(props.item, props.index)"
|
||
|
>
|
||
3 years ago
|
<v-radio :value="props.index" color="primary" />
|
||
4 years ago
|
</v-radio-group>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-edit-dialog
|
||
2 years ago
|
v-ge="['indexes', 'name']"
|
||
4 years ago
|
@save="save(props.item)"
|
||
|
@cancel="cancel"
|
||
|
@open="open"
|
||
|
@close="close(props.item)"
|
||
|
>
|
||
|
{{ props.item.key_name }}
|
||
3 years ago
|
<template #input>
|
||
4 years ago
|
<v-text-field
|
||
3 years ago
|
v-model="props.item.key_name"
|
||
4 years ago
|
:disabled="props.index !== selected"
|
||
|
class="body-2"
|
||
|
:rules="[max25chars]"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
4 years ago
|
single-line
|
||
|
counter
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.non_unique"
|
||
2 years ago
|
v-ge="['indexes', 'unique']"
|
||
4 years ago
|
:disabled="props.index !== selected"
|
||
|
dense
|
||
|
color="primary lighten-1"
|
||
|
:true-value="0"
|
||
|
:false-value="1"
|
||
3 years ago
|
@change="mtdToggleNonUniqueStatus(props.item)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
<td>
|
||
3 years ago
|
<v-hover v-slot="{ hover }">
|
||
4 years ago
|
<v-icon
|
||
2 years ago
|
v-ge="['indexes', 'delete']"
|
||
4 years ago
|
small
|
||
|
:color="hover ? 'error' : 'grey'"
|
||
2 years ago
|
@click="mtdIndexDelete('showDialog', props.item, props.index)"
|
||
3 years ago
|
>
|
||
|
mdi-delete
|
||
4 years ago
|
</v-icon>
|
||
|
</v-hover>
|
||
3 years ago
|
<x-btn
|
||
|
v-if="props.item.edited && props.index === selected"
|
||
2 years ago
|
v-ge="['indexes', 'create']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Index Create"
|
||
|
color="primary"
|
||
|
small
|
||
|
@click="mtdIndexCreate(props.item)"
|
||
4 years ago
|
>
|
||
2 years ago
|
<v-icon small> mdi-content-save </v-icon> Save
|
||
3 years ago
|
</x-btn>
|
||
4 years ago
|
</td>
|
||
|
</tr>
|
||
|
</template>
|
||
|
</v-data-table>
|
||
|
</v-col>
|
||
|
</v-card>
|
||
|
</pane>
|
||
|
<pane min-size="25" size="33" style="overflow: auto">
|
||
|
<v-card class="elevation-0" style="">
|
||
2 years ago
|
<v-card-title class="headline justify-center"> Columns in Index </v-card-title>
|
||
4 years ago
|
<v-col>
|
||
3 years ago
|
<v-skeleton-loader v-if="columnLoading" type="table" />
|
||
4 years ago
|
<v-data-table
|
||
|
v-else
|
||
|
dense
|
||
|
:headers="columnHeaders"
|
||
|
:items="indexColumns"
|
||
|
footer-props.items-per-page-options="30"
|
||
|
>
|
||
3 years ago
|
<template #item="props">
|
||
4 years ago
|
<tr>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.is_index"
|
||
2 years ago
|
v-ge="['indexes', 'toggle-order']"
|
||
4 years ago
|
dense
|
||
|
color="primary lighten-1"
|
||
|
@change="mtdToggleColumnInIndex(props.item, props.index)"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</td>
|
||
3 years ago
|
<td>{{ props.item.column_name }}</td>
|
||
4 years ago
|
<td>{{ props.item.seq_in_index }}</td>
|
||
|
</tr>
|
||
|
</template>
|
||
|
</v-data-table>
|
||
|
</v-col>
|
||
|
</v-card>
|
||
|
</pane>
|
||
|
</splitpanes>
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="showIndexDeleteDialog"
|
||
3 years ago
|
type="error"
|
||
|
:dialog-show="showIndexDeleteDialog"
|
||
|
:actions-mtd="mtdIndexDelete"
|
||
4 years ago
|
heading="Click Submit to Delete the Index"
|
||
|
/>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import { mapGetters } from 'vuex';
|
||
|
import { Splitpanes, Pane } from 'splitpanes';
|
||
|
import dlgLabelSubmitCancel from '../../utils/DlgLabelSubmitCancel';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
components: { dlgLabelSubmitCancel, Splitpanes, Pane },
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
selected: [],
|
||
|
indexCreationAllowed: true,
|
||
|
applyChanges: true,
|
||
|
|
||
|
columns: [],
|
||
|
aggregatedIndexes: [],
|
||
|
indexes: [],
|
||
|
indexColumns: [],
|
||
|
|
||
|
indexHeaders: [
|
||
|
{
|
||
3 years ago
|
text: '#',
|
||
2 years ago
|
sortable: false,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Index',
|
||
2 years ago
|
sortable: false,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Unique',
|
||
2 years ago
|
sortable: false,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Actions',
|
||
2 years ago
|
sortable: false,
|
||
|
},
|
||
4 years ago
|
],
|
||
|
columnHeaders: [
|
||
|
{
|
||
3 years ago
|
text: '#',
|
||
2 years ago
|
sortable: false,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Column',
|
||
2 years ago
|
sortable: false,
|
||
4 years ago
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Sequence',
|
||
2 years ago
|
sortable: false,
|
||
|
},
|
||
4 years ago
|
],
|
||
3 years ago
|
max25chars: v => v.length <= 25 || 'Input too long!',
|
||
4 years ago
|
showIndexDeleteDialog: false,
|
||
|
selectedIndexForDelete: null,
|
||
|
columnLoading: false,
|
||
2 years ago
|
loading: false,
|
||
|
};
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
2 years ago
|
console.log(metaKey, key, altKey, shiftKey, ctrlKey);
|
||
4 years ago
|
// cmd + s -> save
|
||
|
// cmd + l -> reload
|
||
|
// cmd + n -> new
|
||
|
// cmd + d -> delete
|
||
|
// cmd + enter -> send api
|
||
|
|
||
|
switch ([metaKey, key].join('_')) {
|
||
|
// case 'true_s' :
|
||
|
// await this.applyChanges();
|
||
|
// break;
|
||
2 years ago
|
case 'true_l':
|
||
|
await this.mtdRefreshIndexList();
|
||
|
break;
|
||
|
case 'true_n':
|
||
|
this.addIndex();
|
||
|
break;
|
||
|
case 'true_d':
|
||
|
await this.deleteTable('showDialog');
|
||
|
break;
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async mtdRefreshIndexList() {
|
||
4 years ago
|
try {
|
||
2 years ago
|
this.$store.commit('notification/MutToggleProgressBar', true);
|
||
4 years ago
|
if (this.newTable) {
|
||
2 years ago
|
return;
|
||
4 years ago
|
}
|
||
2 years ago
|
await this.getColumnList();
|
||
|
await this.getIndexesAndCreateAggregatedIndexes();
|
||
|
this.mtdSelectColumnsForIndex();
|
||
|
this.calculateColumnSequenceValue();
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
4 years ago
|
} finally {
|
||
2 years ago
|
this.$store.commit('notification/MutToggleProgressBar', false);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
getColumnsForIndexCreation(columns) {
|
||
3 years ago
|
/** ************* START : get columns in this index ***************/
|
||
2 years ago
|
let tempIndexes = JSON.parse(JSON.stringify(columns));
|
||
|
console.log('columns in index', columns);
|
||
|
tempIndexes = tempIndexes.filter(function (a) {
|
||
|
return a.seq_in_index !== 0;
|
||
|
});
|
||
4 years ago
|
|
||
2 years ago
|
console.log('tempIndexes after filter', tempIndexes);
|
||
4 years ago
|
|
||
2 years ago
|
tempIndexes = tempIndexes.sort(function (a, b) {
|
||
|
return a.seq_in_index - b.seq_in_index;
|
||
|
});
|
||
|
console.log('tempIndexes after sort', tempIndexes);
|
||
4 years ago
|
|
||
2 years ago
|
const cols = [];
|
||
4 years ago
|
|
||
|
for (let i = 0; i < tempIndexes.length; i++) {
|
||
2 years ago
|
cols.push(tempIndexes[i].column_name);
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
return cols;
|
||
4 years ago
|
|
||
3 years ago
|
/** ************* END : get columns in this index ***************/
|
||
4 years ago
|
},
|
||
3 years ago
|
async mtdIndexCreate(aggregatedIndex) {
|
||
4 years ago
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
2 years ago
|
console.log(aggregatedIndex);
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.added) {
|
||
2 years ago
|
const cols = this.getColumnsForIndexCreation(aggregatedIndex.columns);
|
||
4 years ago
|
if (!cols.length) {
|
||
2 years ago
|
return;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
2 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'indexCreate',
|
||
4 years ago
|
{
|
||
3 years ago
|
table_name: this.nodes.table_name,
|
||
4 years ago
|
columns: cols,
|
||
|
indexName: aggregatedIndex.key_name,
|
||
2 years ago
|
non_unique: aggregatedIndex.non_unique,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
} else {
|
||
2 years ago
|
console.log('IndexCreation involves dropping existing index and creating new one');
|
||
|
const colsToRemove = this.getColumnsForIndexCreation(aggregatedIndex.oldColumns);
|
||
4 years ago
|
if (!aggregatedIndex.editedIndexAttr && !colsToRemove.length) {
|
||
2 years ago
|
return;
|
||
4 years ago
|
}
|
||
2 years ago
|
console.log('indexDelete for :', colsToRemove);
|
||
4 years ago
|
|
||
|
// let result = await this.sqlMgr.sqlOpPlus(
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// },
|
||
|
// "indexDelete",
|
||
|
// {
|
||
3 years ago
|
// table_name: this.nodes.table_name,
|
||
4 years ago
|
// columns: colsToRemove,
|
||
|
// indexName: aggregatedIndex.key_name,
|
||
|
// non_unique: aggregatedIndex.non_unique
|
||
|
// }
|
||
|
// );
|
||
|
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
2 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'indexDelete',
|
||
4 years ago
|
{
|
||
3 years ago
|
table_name: this.nodes.table_name,
|
||
4 years ago
|
columns: colsToRemove,
|
||
|
indexName: aggregatedIndex.key_name,
|
||
|
non_unique: aggregatedIndex.non_unique,
|
||
2 years ago
|
non_unique_original: aggregatedIndex.non_unique_original,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
2 years ago
|
const colsToCreate = this.getColumnsForIndexCreation(aggregatedIndex.columns);
|
||
4 years ago
|
if (!colsToCreate.length) {
|
||
2 years ago
|
return;
|
||
4 years ago
|
}
|
||
2 years ago
|
console.log('indexCreate for :', colsToCreate);
|
||
4 years ago
|
|
||
|
// result = await this.sqlMgr.sqlOpPlus(
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// },
|
||
|
// "indexCreate",
|
||
|
// {
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
4 years ago
|
// columns: colsToCreate,
|
||
|
// indexName: aggregatedIndex.key_name,
|
||
|
// non_unique: aggregatedIndex.non_unique
|
||
|
// }
|
||
|
// );
|
||
|
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
2 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
4 years ago
|
},
|
||
3 years ago
|
'indexCreate',
|
||
4 years ago
|
{
|
||
3 years ago
|
tn: this.nodes.table_name,
|
||
4 years ago
|
columns: colsToCreate,
|
||
|
indexName: aggregatedIndex.key_name,
|
||
2 years ago
|
non_unique: aggregatedIndex.non_unique,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
await this.mtdRefreshIndexList();
|
||
4 years ago
|
},
|
||
3 years ago
|
async mtdIndexDelete(action = '', aggregatedIndex, index) {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
2 years ago
|
this.showIndexDeleteDialog = true;
|
||
|
this.selectedIndexForDelete = { aggregatedIndex, index };
|
||
3 years ago
|
} else if (action === 'hideDialog') {
|
||
2 years ago
|
this.showIndexDeleteDialog = false;
|
||
|
this.selectedIndexForDelete = null;
|
||
4 years ago
|
} else {
|
||
|
if (this.selectedIndexForDelete.aggregatedIndex.added === 1) {
|
||
2 years ago
|
this.aggregatedIndexes.splice(this.selectedIndexForDelete.index, 1);
|
||
|
console.log('This was newly added index : deletign without going to lib');
|
||
4 years ago
|
} else {
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
|
||
3 years ago
|
/** ************* START : get columns in this index ***************/
|
||
2 years ago
|
let tempIndexes = JSON.parse(JSON.stringify(this.selectedIndexForDelete.aggregatedIndex.columns));
|
||
4 years ago
|
|
||
2 years ago
|
tempIndexes = tempIndexes.filter(function (a) {
|
||
|
return a.seq_in_index !== 0;
|
||
|
});
|
||
4 years ago
|
|
||
2 years ago
|
console.log('tempIndexes after filter', tempIndexes);
|
||
4 years ago
|
|
||
2 years ago
|
tempIndexes = tempIndexes.sort(function (a, b) {
|
||
|
return a.seq_in_index - b.seq_in_index;
|
||
|
});
|
||
|
console.log('tempIndexes after sort', tempIndexes);
|
||
4 years ago
|
|
||
2 years ago
|
const cols = [];
|
||
4 years ago
|
|
||
|
for (let i = 0; i < tempIndexes.length; i++) {
|
||
2 years ago
|
cols.push(tempIndexes[i].column_name);
|
||
4 years ago
|
}
|
||
3 years ago
|
/** ************* END : get columns in this index ***************/
|
||
|
|
||
|
// const result = await client.indexDelete({
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// columns: cols,
|
||
|
// indexName: this.selectedIndexForDelete.aggregatedIndex.key_name
|
||
|
// });
|
||
|
|
||
|
// let result = await this.sqlMgr.sqlOpPlus(
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// },
|
||
|
// "indexDelete",
|
||
|
// {
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// columns: cols,
|
||
|
// indexName: this.selectedIndexForDelete.aggregatedIndex.key_name,
|
||
|
// non_unique: this.selectedIndexForDelete.aggregatedIndex.non_unique
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
2 years ago
|
dbAlias: this.nodes.dbAlias,
|
||
3 years ago
|
},
|
||
|
'indexDelete',
|
||
|
{
|
||
3 years ago
|
tn: this.nodes.table_name,
|
||
3 years ago
|
columns: cols,
|
||
|
indexName: this.selectedIndexForDelete.aggregatedIndex.key_name,
|
||
|
non_unique: this.selectedIndexForDelete.aggregatedIndex.non_unique,
|
||
2 years ago
|
non_unique_original: this.selectedIndexForDelete.aggregatedIndex.non_unique_original,
|
||
|
},
|
||
|
]);
|
||
3 years ago
|
|
||
2 years ago
|
await this.mtdRefreshIndexList();
|
||
4 years ago
|
}
|
||
2 years ago
|
this.showIndexDeleteDialog = false;
|
||
|
this.selectedIndexForDelete = null;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdToggleNonUniqueStatus(aggregatedIndex) {
|
||
2 years ago
|
console.log('mtdToggleNonUniqueStatus', aggregatedIndex);
|
||
3 years ago
|
// aggregatedIndex.non_unique = aggregatedIndex.non_unique ? 0 : 1;
|
||
2 years ago
|
aggregatedIndex.edited = true;
|
||
|
aggregatedIndex.editedIndexAttr = true;
|
||
4 years ago
|
},
|
||
3 years ago
|
mtdToggleColumnInIndex(cn, index) {
|
||
2 years ago
|
console.log('Index being edited:', this.selected);
|
||
4 years ago
|
|
||
2 years ago
|
const aggregatedIndex = this.aggregatedIndexes.find((o, i) => i === this.selected);
|
||
4 years ago
|
|
||
2 years ago
|
console.log('aggregatedIndex on toggle of column', aggregatedIndex);
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.added) {
|
||
2 years ago
|
console.log('This was newly added index');
|
||
4 years ago
|
} else {
|
||
2 years ago
|
console.log('This is an existing index');
|
||
|
aggregatedIndex.edited = true;
|
||
4 years ago
|
if (!aggregatedIndex.oldColumns.length) {
|
||
2 years ago
|
console.log('Taking backup of old columns');
|
||
|
aggregatedIndex.oldColumns = JSON.parse(JSON.stringify(aggregatedIndex.columns));
|
||
4 years ago
|
} else {
|
||
2 years ago
|
console.log('Taking backup of old columns : old columns already exists');
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (cn.seq_in_index) {
|
||
|
for (let i = 0; i < this.indexColumns.length; i++) {
|
||
|
if (this.indexColumns[i].seq_in_index > cn.seq_in_index) {
|
||
2 years ago
|
this.indexColumns[i].seq_in_index -= 1;
|
||
4 years ago
|
}
|
||
|
}
|
||
2 years ago
|
cn.seq_in_index = 0;
|
||
4 years ago
|
} else {
|
||
|
const max = Math.max.apply(
|
||
|
Math,
|
||
2 years ago
|
this.indexColumns.map(function (o) {
|
||
|
return o.seq_in_index;
|
||
4 years ago
|
})
|
||
2 years ago
|
);
|
||
|
console.log('max value:', max);
|
||
|
cn.seq_in_index = max + 1;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdAddIndex() {
|
||
2 years ago
|
const itemIndex = this.aggregatedIndexes.length;
|
||
3 years ago
|
const index = {
|
||
|
cardinality: 'a',
|
||
|
collation: 'a',
|
||
|
cn: '',
|
||
|
comment: '',
|
||
|
expression: '',
|
||
|
index_comment: '',
|
||
|
index_type: 'BTREE',
|
||
|
key_name: 'idx_' + itemIndex,
|
||
4 years ago
|
non_unique: 1,
|
||
3 years ago
|
null: '',
|
||
|
packed: '',
|
||
4 years ago
|
seq_in_index: 0,
|
||
3 years ago
|
sub_part: '',
|
||
|
table: '',
|
||
|
visible: '',
|
||
4 years ago
|
added: 1,
|
||
|
edited: 1,
|
||
2 years ago
|
columns: JSON.parse(JSON.stringify(this.columns)),
|
||
|
};
|
||
|
this.aggregatedIndexes.push(index);
|
||
|
this.selected = itemIndex;
|
||
|
this.mtdSelectColumnsForIndex(index, itemIndex);
|
||
4 years ago
|
},
|
||
3 years ago
|
mtdResetColumnsIndexes() {
|
||
4 years ago
|
for (let j = 0; j < this.columns.length; j++) {
|
||
2 years ago
|
this.columns[j].seq_in_index = 0;
|
||
|
this.columns[j].is_index = false;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdSelectColumnsForIndex(indexObj = null, index = 0) {
|
||
2 years ago
|
console.log('selecting index', index);
|
||
4 years ago
|
|
||
|
if (!indexObj) {
|
||
|
if (this.aggregatedIndexes.length) {
|
||
2 years ago
|
indexObj = this.aggregatedIndexes[0];
|
||
|
this.selected = index;
|
||
4 years ago
|
// this.$nextTick(() => {
|
||
|
// this.selected = indexObj.key_name + ''
|
||
|
// })
|
||
|
}
|
||
|
}
|
||
|
//
|
||
|
//
|
||
|
// for (let i = 0; i < this.indexes.length; i++) {
|
||
|
// if (indexObj.key_name === this.indexes[i].key_name) {
|
||
|
// console.log(indexObj.key_name, this.indexes[i].key_name);
|
||
|
// for (let j = 0; j < this.columns.length; j++) {
|
||
3 years ago
|
// if (this.indexes[i].column_name === this.columns[j].column_name) {
|
||
4 years ago
|
// indexObj.columns[j].seq_in_index = this.indexes[i].seq_in_index;
|
||
|
// indexObj.columns[j].is_index = true;
|
||
|
// console.log("Column is in index: ", this.columns[j]);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
|
||
2 years ago
|
this.indexColumns = indexObj.columns;
|
||
4 years ago
|
},
|
||
3 years ago
|
calculateColumnSequenceValue() {
|
||
2 years ago
|
this.aggregatedIndexes.forEach(indexObj => {
|
||
4 years ago
|
for (let i = 0; i < this.indexes.length; i++) {
|
||
|
if (indexObj.key_name === this.indexes[i].key_name) {
|
||
2 years ago
|
console.log(indexObj.key_name, this.indexes[i].key_name);
|
||
4 years ago
|
for (let j = 0; j < this.columns.length; j++) {
|
||
3 years ago
|
if (this.indexes[i].column_name === this.columns[j].column_name) {
|
||
2 years ago
|
indexObj.columns[j].seq_in_index = this.indexes[i].seq_in_index;
|
||
|
indexObj.columns[j].is_index = true;
|
||
|
console.log('Column is in index: ', this.columns[j]);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
2 years ago
|
});
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
createAggregatedIndexesList(indexes) {
|
||
3 years ago
|
for (let i = 0; i < Indexes.length; i++) {
|
||
2 years ago
|
const index = { ...Indexes[i] };
|
||
|
let found = 0;
|
||
4 years ago
|
for (let j = 0; j < this.aggregatedIndexes.length; j++) {
|
||
2 years ago
|
const aggregatedIndex = this.aggregatedIndexes[j];
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.key_name === index.key_name) {
|
||
2 years ago
|
found = 1;
|
||
|
break;
|
||
4 years ago
|
}
|
||
|
}
|
||
|
if (!found) {
|
||
2 years ago
|
index.edited = false;
|
||
|
index.columns = [];
|
||
|
index.oldColumns = [];
|
||
|
index.columns = JSON.parse(JSON.stringify(this.columns));
|
||
|
this.aggregatedIndexes.push(index);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
3 years ago
|
async getIndexesAndCreateAggregatedIndexes() {
|
||
2 years ago
|
this.loading = true;
|
||
4 years ago
|
|
||
2 years ago
|
if (this.newTable) {
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
|
||
2 years ago
|
this.indexes = [];
|
||
|
this.aggregatedIndexes = [];
|
||
4 years ago
|
|
||
|
// console.log("env: this.nodes.env", this.nodes.env, this.nodes.dbAlias);
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.indexList({
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
4 years ago
|
// });
|
||
|
// const result = await this.sqlMgr.sqlOp({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'indexList', {
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
4 years ago
|
// })
|
||
|
|
||
2 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'indexList',
|
||
|
{
|
||
|
tn: this.nodes.table_name,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
2 years ago
|
this.createAggregatedIndexesList(result.data.list);
|
||
4 years ago
|
|
||
|
// this.indexes = JSON.parse(JSON.stringify(result.data.list));
|
||
2 years ago
|
this.indexes = [];
|
||
|
this.indexes = result.data.list;
|
||
|
console.log('Indexes List in table', this.indexes);
|
||
|
console.log('Aggregated Indexes in table', this.aggregatedIndexes);
|
||
4 years ago
|
|
||
2 years ago
|
this.loading = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
async getColumnList() {
|
||
2 years ago
|
this.columnLoading = true;
|
||
4 years ago
|
// console.log("env: this.nodes.env", this.nodes.env, this.nodes.dbAlias);
|
||
|
// const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// });
|
||
|
// const result = await client.columnList({
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
4 years ago
|
// });
|
||
|
|
||
|
// const result = await this.sqlMgr.sqlOp({
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// }, 'columnList', {
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
4 years ago
|
// })
|
||
|
|
||
2 years ago
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'columnList',
|
||
|
{
|
||
|
tn: this.nodes.table_name,
|
||
|
},
|
||
|
]);
|
||
4 years ago
|
|
||
2 years ago
|
this.columns = JSON.parse(JSON.stringify(result.data.list));
|
||
4 years ago
|
for (let i = 0; i < this.columns.length; i++) {
|
||
2 years ago
|
this.columns[i].seq_in_index = 0;
|
||
|
this.columns[i].is_index = false;
|
||
4 years ago
|
}
|
||
|
|
||
2 years ago
|
console.log('Columns in table:', this.columns);
|
||
|
this.columnLoading = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
save(aggregatedIndex) {
|
||
2 years ago
|
aggregatedIndex.edited = true;
|
||
4 years ago
|
|
||
2 years ago
|
this.snack = true;
|
||
|
this.snackColor = 'success';
|
||
|
this.snackText = 'Data saved';
|
||
4 years ago
|
},
|
||
3 years ago
|
cancel() {
|
||
2 years ago
|
this.snack = true;
|
||
|
this.snackColor = 'error';
|
||
|
this.snackText = 'Canceled';
|
||
|
console.log('Dialog Canceled');
|
||
4 years ago
|
},
|
||
3 years ago
|
open() {
|
||
2 years ago
|
this.snack = true;
|
||
|
this.snackColor = 'info';
|
||
|
this.snackText = 'Dialog opened';
|
||
4 years ago
|
},
|
||
3 years ago
|
close(aggregatedIndex) {
|
||
2 years ago
|
aggregatedIndex.edited = true;
|
||
|
},
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
2 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }),
|
||
4 years ago
|
},
|
||
|
|
||
2 years ago
|
beforeCreated() {},
|
||
3 years ago
|
watch: {
|
||
3 years ago
|
columns() {
|
||
2 years ago
|
return this.columns;
|
||
3 years ago
|
},
|
||
3 years ago
|
aggregatedIndexes(v, ov) {
|
||
2 years ago
|
console.log(v, ov);
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
2 years ago
|
await this.mtdRefreshIndexList();
|
||
4 years ago
|
},
|
||
2 years ago
|
mounted() {},
|
||
|
beforeDestroy() {},
|
||
|
destroy() {},
|
||
3 years ago
|
directives: {},
|
||
3 years ago
|
validate({ params }) {
|
||
2 years ago
|
return true;
|
||
4 years ago
|
},
|
||
3 years ago
|
head() {
|
||
2 years ago
|
return {};
|
||
4 years ago
|
},
|
||
2 years ago
|
props: ['nodes', 'newTable', 'deleteTable', 'isMetaTable'],
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|
||
4 years ago
|
<!--
|
||
|
/**
|
||
|
* @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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|