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.
842 lines
25 KiB
842 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>
|
||
|
<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
|
||
|
:items="[{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#'
|
||
|
},{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#'
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: nodes.title + ' (table)',
|
||
3 years ago
|
disabled: true,
|
||
|
href: '#'
|
||
|
}]"
|
||
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
|
<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
|
||
|
v-ge="['indexes','reload']"
|
||
|
outlined
|
||
|
tooltip="Reload Indexes"
|
||
|
small
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
@click="mtdRefreshIndexList"
|
||
4 years ago
|
>
|
||
3 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"
|
||
|
v-ge="['indexes','new']"
|
||
|
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
|
||
|
v-ge="['indexes','delete-table']"
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('activity.deleteTable')"
|
||
3 years ago
|
small
|
||
|
color="error "
|
||
|
class="error text-right"
|
||
|
@click="deleteTable('showDialog')"
|
||
4 years ago
|
>
|
||
3 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">-->
|
||
|
|
||
|
<splitpanes style="height:calc(100% - 42px);" class="xc-theme">
|
||
|
<pane min-size="33" size="66" style="overflow: auto">
|
||
|
<v-card class="elevation-0" style="">
|
||
3 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"
|
||
3 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
|
||
3 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"
|
||
|
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
|
||
|
v-ge="['indexes','delete']"
|
||
|
small
|
||
|
:color="hover ? 'error' : 'grey'"
|
||
|
@click="
|
||
3 years ago
|
mtdIndexDelete('showDialog', props.item, props.index)
|
||
|
"
|
||
|
>
|
||
|
mdi-delete
|
||
4 years ago
|
</v-icon>
|
||
|
</v-hover>
|
||
3 years ago
|
<x-btn
|
||
|
v-if="props.item.edited && props.index === selected"
|
||
|
v-ge="['indexes','create']"
|
||
|
outlined
|
||
|
tooltip="Index Create"
|
||
|
color="primary"
|
||
|
small
|
||
|
@click="mtdIndexCreate(props.item)"
|
||
4 years ago
|
>
|
||
3 years ago
|
<v-icon small>
|
||
|
mdi-content-save
|
||
|
</v-icon> Save
|
||
|
</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="">
|
||
3 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"
|
||
4 years ago
|
v-ge="['indexes','toggle-order']"
|
||
|
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>
|
||
3 years ago
|
import { mapGetters } from 'vuex'
|
||
|
import { Splitpanes, Pane } from 'splitpanes'
|
||
3 years ago
|
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: '#',
|
||
4 years ago
|
sortable: false
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Index',
|
||
4 years ago
|
sortable: false
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Unique',
|
||
4 years ago
|
sortable: false
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Actions',
|
||
4 years ago
|
sortable: false
|
||
|
}
|
||
|
],
|
||
|
columnHeaders: [
|
||
|
{
|
||
3 years ago
|
text: '#',
|
||
4 years ago
|
sortable: false
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Column',
|
||
4 years ago
|
sortable: false
|
||
|
},
|
||
|
{
|
||
3 years ago
|
text: 'Sequence',
|
||
4 years ago
|
sortable: false
|
||
|
}
|
||
|
],
|
||
3 years ago
|
max25chars: v => v.length <= 25 || 'Input too long!',
|
||
4 years ago
|
showIndexDeleteDialog: false,
|
||
|
selectedIndexForDelete: null,
|
||
|
columnLoading: false,
|
||
|
loading: false
|
||
3 years ago
|
}
|
||
4 years ago
|
},
|
||
|
methods: {
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
4 years ago
|
console.log(metaKey, key, altKey, shiftKey, ctrlKey)
|
||
|
// 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;
|
||
|
case 'true_l' :
|
||
3 years ago
|
await this.mtdRefreshIndexList()
|
||
|
break
|
||
4 years ago
|
case 'true_n' :
|
||
3 years ago
|
this.addIndex()
|
||
|
break
|
||
4 years ago
|
case 'true_d' :
|
||
3 years ago
|
await this.deleteTable('showDialog')
|
||
|
break
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async mtdRefreshIndexList() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
this.$store.commit('notification/MutToggleProgressBar', true)
|
||
4 years ago
|
if (this.newTable) {
|
||
3 years ago
|
return
|
||
4 years ago
|
}
|
||
3 years ago
|
await this.getColumnList()
|
||
|
await this.getIndexesAndCreateAggregatedIndexes()
|
||
|
this.mtdSelectColumnsForIndex()
|
||
|
this.calculateColumnSequenceValue()
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
4 years ago
|
} finally {
|
||
3 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 ***************/
|
||
|
let tempIndexes = JSON.parse(JSON.stringify(columns))
|
||
|
console.log('columns in index', columns)
|
||
3 years ago
|
tempIndexes = tempIndexes.filter(function(a) {
|
||
3 years ago
|
return a.seq_in_index !== 0
|
||
|
})
|
||
4 years ago
|
|
||
3 years ago
|
console.log('tempIndexes after filter', tempIndexes)
|
||
4 years ago
|
|
||
3 years ago
|
tempIndexes = tempIndexes.sort(function(a, b) {
|
||
3 years ago
|
return a.seq_in_index - b.seq_in_index
|
||
|
})
|
||
|
console.log('tempIndexes after sort', tempIndexes)
|
||
4 years ago
|
|
||
3 years ago
|
const cols = []
|
||
4 years ago
|
|
||
|
for (let i = 0; i < tempIndexes.length; i++) {
|
||
3 years ago
|
cols.push(tempIndexes[i].column_name)
|
||
4 years ago
|
}
|
||
|
|
||
3 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
|
||
|
// });
|
||
3 years ago
|
console.log(aggregatedIndex)
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.added) {
|
||
3 years ago
|
const cols = this.getColumnsForIndexCreation(aggregatedIndex.columns)
|
||
4 years ago
|
if (!cols.length) {
|
||
3 years ago
|
return
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
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,
|
||
|
non_unique: aggregatedIndex.non_unique
|
||
3 years ago
|
}])
|
||
4 years ago
|
} else {
|
||
|
console.log(
|
||
3 years ago
|
'IndexCreation involves dropping existing index and creating new one'
|
||
|
)
|
||
|
const colsToRemove = this.getColumnsForIndexCreation(
|
||
4 years ago
|
aggregatedIndex.oldColumns
|
||
3 years ago
|
)
|
||
4 years ago
|
if (!aggregatedIndex.editedIndexAttr && !colsToRemove.length) {
|
||
3 years ago
|
return
|
||
4 years ago
|
}
|
||
3 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,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
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,
|
||
|
non_unique_original: aggregatedIndex.non_unique_original
|
||
3 years ago
|
}])
|
||
4 years ago
|
|
||
3 years ago
|
const colsToCreate = this.getColumnsForIndexCreation(
|
||
4 years ago
|
aggregatedIndex.columns
|
||
3 years ago
|
)
|
||
4 years ago
|
if (!colsToCreate.length) {
|
||
3 years ago
|
return
|
||
4 years ago
|
}
|
||
3 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,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'indexCreate',
|
||
4 years ago
|
{
|
||
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
|
}])
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
await this.mtdRefreshIndexList()
|
||
4 years ago
|
},
|
||
3 years ago
|
async mtdIndexDelete(action = '', aggregatedIndex, index) {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
|
this.showIndexDeleteDialog = true
|
||
|
this.selectedIndexForDelete = { aggregatedIndex, index }
|
||
|
} else if (action === 'hideDialog') {
|
||
|
this.showIndexDeleteDialog = false
|
||
|
this.selectedIndexForDelete = null
|
||
4 years ago
|
} else {
|
||
|
if (this.selectedIndexForDelete.aggregatedIndex.added === 1) {
|
||
3 years ago
|
this.aggregatedIndexes.splice(this.selectedIndexForDelete.index, 1)
|
||
4 years ago
|
console.log(
|
||
3 years ago
|
'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 ***************/
|
||
4 years ago
|
let tempIndexes = JSON.parse(
|
||
|
JSON.stringify(this.selectedIndexForDelete.aggregatedIndex.columns)
|
||
3 years ago
|
)
|
||
4 years ago
|
|
||
3 years ago
|
tempIndexes = tempIndexes.filter(function(a) {
|
||
3 years ago
|
return a.seq_in_index !== 0
|
||
|
})
|
||
4 years ago
|
|
||
3 years ago
|
console.log('tempIndexes after filter', tempIndexes)
|
||
4 years ago
|
|
||
3 years ago
|
tempIndexes = tempIndexes.sort(function(a, b) {
|
||
3 years ago
|
return a.seq_in_index - b.seq_in_index
|
||
|
})
|
||
|
console.log('tempIndexes after sort', tempIndexes)
|
||
4 years ago
|
|
||
3 years ago
|
const cols = []
|
||
4 years ago
|
|
||
|
for (let i = 0; i < tempIndexes.length; i++) {
|
||
3 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,
|
||
|
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,
|
||
|
non_unique_original: this.selectedIndexForDelete.aggregatedIndex.non_unique_original
|
||
|
}])
|
||
|
|
||
|
await this.mtdRefreshIndexList()
|
||
4 years ago
|
}
|
||
3 years ago
|
this.showIndexDeleteDialog = false
|
||
|
this.selectedIndexForDelete = null
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdToggleNonUniqueStatus(aggregatedIndex) {
|
||
3 years ago
|
console.log('mtdToggleNonUniqueStatus', aggregatedIndex)
|
||
|
// aggregatedIndex.non_unique = aggregatedIndex.non_unique ? 0 : 1;
|
||
|
aggregatedIndex.edited = true
|
||
|
aggregatedIndex.editedIndexAttr = true
|
||
4 years ago
|
},
|
||
3 years ago
|
mtdToggleColumnInIndex(cn, index) {
|
||
3 years ago
|
console.log('Index being edited:', this.selected)
|
||
4 years ago
|
|
||
3 years ago
|
const aggregatedIndex = this.aggregatedIndexes.find(
|
||
4 years ago
|
(o, i) => i === this.selected
|
||
3 years ago
|
)
|
||
4 years ago
|
|
||
3 years ago
|
console.log('aggregatedIndex on toggle of column', aggregatedIndex)
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.added) {
|
||
3 years ago
|
console.log('This was newly added index')
|
||
4 years ago
|
} else {
|
||
3 years ago
|
console.log('This is an existing index')
|
||
|
aggregatedIndex.edited = true
|
||
4 years ago
|
if (!aggregatedIndex.oldColumns.length) {
|
||
3 years ago
|
console.log('Taking backup of old columns')
|
||
4 years ago
|
aggregatedIndex.oldColumns = JSON.parse(
|
||
|
JSON.stringify(aggregatedIndex.columns)
|
||
3 years ago
|
)
|
||
4 years ago
|
} else {
|
||
|
console.log(
|
||
3 years ago
|
'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) {
|
||
3 years ago
|
this.indexColumns[i].seq_in_index -= 1
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
cn.seq_in_index = 0
|
||
4 years ago
|
} else {
|
||
|
const max = Math.max.apply(
|
||
|
Math,
|
||
3 years ago
|
this.indexColumns.map(function(o) {
|
||
3 years ago
|
return o.seq_in_index
|
||
4 years ago
|
})
|
||
3 years ago
|
)
|
||
|
console.log('max value:', max)
|
||
|
cn.seq_in_index = max + 1
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
mtdAddIndex() {
|
||
3 years ago
|
const itemIndex = this.aggregatedIndexes.length
|
||
|
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,
|
||
|
columns: JSON.parse(JSON.stringify(this.columns))
|
||
3 years ago
|
}
|
||
|
this.aggregatedIndexes.push(index)
|
||
|
this.selected = itemIndex
|
||
4 years ago
|
this.mtdSelectColumnsForIndex(index, itemIndex)
|
||
|
},
|
||
3 years ago
|
mtdResetColumnsIndexes() {
|
||
4 years ago
|
for (let j = 0; j < this.columns.length; j++) {
|
||
3 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) {
|
||
3 years ago
|
console.log('selecting index', index)
|
||
4 years ago
|
|
||
|
if (!indexObj) {
|
||
|
if (this.aggregatedIndexes.length) {
|
||
3 years ago
|
indexObj = this.aggregatedIndexes[0]
|
||
4 years ago
|
this.selected = index
|
||
|
// 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]);
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
|
||
3 years ago
|
this.indexColumns = indexObj.columns
|
||
4 years ago
|
},
|
||
3 years ago
|
calculateColumnSequenceValue() {
|
||
3 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) {
|
||
3 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) {
|
||
3 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
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
|
||
3 years ago
|
createAggregatedIndexesList(indexes) {
|
||
3 years ago
|
for (let i = 0; i < Indexes.length; i++) {
|
||
|
const index = { ...Indexes[i] }
|
||
3 years ago
|
let found = 0
|
||
4 years ago
|
for (let j = 0; j < this.aggregatedIndexes.length; j++) {
|
||
3 years ago
|
const aggregatedIndex = this.aggregatedIndexes[j]
|
||
4 years ago
|
|
||
|
if (aggregatedIndex.key_name === index.key_name) {
|
||
3 years ago
|
found = 1
|
||
|
break
|
||
4 years ago
|
}
|
||
|
}
|
||
|
if (!found) {
|
||
3 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() {
|
||
3 years ago
|
this.loading = true
|
||
4 years ago
|
|
||
3 years ago
|
if (this.newTable) { return }
|
||
4 years ago
|
|
||
3 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
|
// })
|
||
|
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
}, 'indexList', {
|
||
3 years ago
|
tn: this.nodes.table_name
|
||
4 years ago
|
}])
|
||
|
|
||
3 years ago
|
this.createAggregatedIndexesList(result.data.list)
|
||
4 years ago
|
|
||
|
// this.indexes = JSON.parse(JSON.stringify(result.data.list));
|
||
3 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
|
|
||
3 years ago
|
this.loading = false
|
||
4 years ago
|
},
|
||
3 years ago
|
async getColumnList() {
|
||
3 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
|
// })
|
||
|
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOp', [{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
}, 'columnList', {
|
||
3 years ago
|
tn: this.nodes.table_name
|
||
4 years ago
|
}])
|
||
|
|
||
3 years ago
|
this.columns = JSON.parse(JSON.stringify(result.data.list))
|
||
4 years ago
|
for (let i = 0; i < this.columns.length; i++) {
|
||
3 years ago
|
this.columns[i].seq_in_index = 0
|
||
|
this.columns[i].is_index = false
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
console.log('Columns in table:', this.columns)
|
||
|
this.columnLoading = false
|
||
4 years ago
|
},
|
||
3 years ago
|
save(aggregatedIndex) {
|
||
3 years ago
|
aggregatedIndex.edited = true
|
||
4 years ago
|
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
4 years ago
|
},
|
||
3 years ago
|
cancel() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'error'
|
||
|
this.snackText = 'Canceled'
|
||
|
console.log('Dialog Canceled')
|
||
4 years ago
|
},
|
||
3 years ago
|
open() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'info'
|
||
|
this.snackText = 'Dialog opened'
|
||
4 years ago
|
},
|
||
3 years ago
|
close(aggregatedIndex) {
|
||
3 years ago
|
aggregatedIndex.edited = true
|
||
4 years ago
|
}
|
||
|
},
|
||
|
computed: {
|
||
3 years ago
|
...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' })
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
beforeCreated() {
|
||
4 years ago
|
},
|
||
3 years ago
|
watch: {
|
||
3 years ago
|
columns() {
|
||
3 years ago
|
return this.columns
|
||
|
},
|
||
3 years ago
|
aggregatedIndexes(v, ov) {
|
||
3 years ago
|
console.log(v, ov)
|
||
|
}
|
||
4 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.mtdRefreshIndexList()
|
||
4 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
},
|
||
3 years ago
|
beforeDestroy() {
|
||
4 years ago
|
},
|
||
3 years ago
|
destroy() {
|
||
4 years ago
|
},
|
||
3 years ago
|
directives: {},
|
||
3 years ago
|
validate({ params }) {
|
||
3 years ago
|
return true
|
||
4 years ago
|
},
|
||
3 years ago
|
head() {
|
||
3 years ago
|
return {}
|
||
4 years ago
|
},
|
||
3 years ago
|
props: ['nodes', 'newTable', 'deleteTable', 'isMetaTable']
|
||
|
}
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|