antares/src/renderer/components/WorkspaceTabPropsTable.vue

671 lines
24 KiB
Vue
Raw Normal View History

2020-10-24 14:47:35 +02:00
<template>
2021-07-15 19:51:18 +02:00
<div v-show="isSelected" class="workspace-query-tab column col-12 columns col-gapless">
2020-10-24 14:47:35 +02:00
<div class="workspace-query-runner column col-12">
<div class="workspace-query-runner-footer">
<div class="workspace-query-buttons">
2020-11-13 12:39:40 +01:00
<button
class="btn btn-primary btn-sm"
:disabled="!isChanged"
:class="{'loading':isSaving}"
title="CTRL+S"
2020-11-13 12:39:40 +01:00
@click="saveChanges"
>
<i class="mdi mdi-24px mdi-content-save mr-1" />
2020-10-24 14:47:35 +02:00
<span>{{ $t('word.save') }}</span>
</button>
<button
:disabled="!isChanged || isSaving"
2020-10-24 14:47:35 +02:00
class="btn btn-link btn-sm mr-0"
:title="$t('message.clearChanges')"
2020-11-13 12:39:40 +01:00
@click="clearChanges"
2020-10-24 14:47:35 +02:00
>
<i class="mdi mdi-24px mdi-delete-sweep mr-1" />
2020-10-24 14:47:35 +02:00
<span>{{ $t('word.clear') }}</span>
</button>
<div class="divider-vert py-3" />
2020-11-13 15:04:51 +01:00
<button
:disabled="isSaving"
2020-11-13 15:04:51 +01:00
class="btn btn-dark btn-sm"
:title="$t('message.addNewField')"
@click="addField"
>
<i class="mdi mdi-24px mdi-playlist-plus mr-1" />
2020-10-24 14:47:35 +02:00
<span>{{ $t('word.add') }}</span>
</button>
2020-12-01 16:48:20 +01:00
<button
:disabled="isSaving"
2020-12-01 16:48:20 +01:00
class="btn btn-dark btn-sm"
:title="$t('message.manageIndexes')"
@click="showIntdexesModal"
>
<i class="mdi mdi-24px mdi-key mdi-rotate-45 mr-1" />
2020-10-24 14:47:35 +02:00
<span>{{ $t('word.indexes') }}</span>
</button>
<button
class="btn btn-dark btn-sm"
:disabled="isSaving"
@click="showForeignModal"
>
<i class="mdi mdi-24px mdi-key-link mr-1" />
2020-10-24 14:47:35 +02:00
<span>{{ $t('word.foreignKeys') }}</span>
</button>
</div>
2021-07-15 19:51:18 +02:00
<div class="workspace-query-info">
<div class="d-flex" :title="$t('word.schema')">
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
</div>
</div>
2020-10-24 14:47:35 +02:00
</div>
</div>
<div class="container">
<div class="columns mb-4">
<div class="column col-auto">
<div class="form-group">
<label class="form-label">{{ $t('word.name') }}</label>
<input
v-model="localOptions.name"
class="form-input"
type="text"
>
</div>
</div>
<div v-if="workspace.customizations.comment" class="column">
<div class="form-group">
<label class="form-label">{{ $t('word.comment') }}</label>
<input
v-model="localOptions.comment"
class="form-input"
type="text"
>
</div>
</div>
<div v-if="workspace.customizations.autoIncrement" class="column col-auto">
<div class="form-group">
<label class="form-label">
{{ $t('word.autoIncrement') }}
</label>
<input
ref="firstInput"
v-model="localOptions.autoIncrement"
class="form-input"
type="number"
:disabled="localOptions.autoIncrement === null"
>
</div>
</div>
<div v-if="workspace.customizations.collations" class="column col-auto">
<div class="form-group">
<label class="form-label">
{{ $t('word.collation') }}
</label>
<select v-model="localOptions.collation" class="form-select">
<option
v-for="collation in workspace.collations"
:key="collation.id"
:value="collation.collation"
>
{{ collation.collation }}
</option>
</select>
</div>
</div>
<div v-if="workspace.customizations.engines" class="column col-auto">
<div class="form-group">
<label class="form-label">
{{ $t('word.engine') }}
</label>
<select v-model="localOptions.engine" class="form-select">
<option
v-for="engine in workspace.engines"
:key="engine.name"
:value="engine.name"
>
{{ engine.name }}
</option>
</select>
</div>
</div>
</div>
</div>
<div class="workspace-query-results column col-12 p-relative">
<BaseLoader v-if="isLoading" />
2021-08-18 17:28:41 +02:00
<WorkspaceTabPropsTableFields
2020-10-24 14:47:35 +02:00
v-if="localFields"
2020-12-01 16:48:20 +01:00
ref="indexTable"
2020-11-13 12:39:40 +01:00
:fields="localFields"
:indexes="localIndexes"
2020-12-15 17:08:36 +01:00
:foreigns="localKeyUsage"
2020-10-24 14:47:35 +02:00
:tab-uid="tabUid"
:conn-uid="connection.uid"
2020-12-01 16:48:20 +01:00
:index-types="workspace.indexTypes"
2020-10-24 14:47:35 +02:00
:table="table"
:schema="schema"
mode="table"
@duplicate-field="duplicateField"
2020-11-13 16:19:59 +01:00
@remove-field="removeField"
2020-12-01 16:48:20 +01:00
@add-new-index="addNewIndex"
@add-to-index="addToIndex"
@rename-field="renameField"
2020-10-24 14:47:35 +02:00
/>
</div>
2021-08-12 09:54:13 +02:00
<WorkspaceTabPropsTableIndexesModal
2020-12-01 16:48:20 +01:00
v-if="isIndexesModal"
:local-indexes="localIndexes"
:table="table"
:fields="localFields"
:index-types="workspace.indexTypes"
:workspace="workspace"
@hide="hideIndexesModal"
@indexes-update="indexesUpdate"
/>
2021-08-12 09:54:13 +02:00
<WorkspaceTabPropsTableForeignModal
2020-12-15 17:08:36 +01:00
v-if="isForeignModal"
:local-key-usage="localKeyUsage"
:connection="connection"
:table="table"
:schema="schema"
:schema-tables="schemaTables"
:fields="localFields"
:workspace="workspace"
@hide="hideForeignModal"
@foreigns-update="foreignsUpdate"
/>
2020-10-24 14:47:35 +02:00
</div>
</template>
<script>
2020-11-13 12:39:40 +01:00
import { mapGetters, mapActions } from 'vuex';
import { uidGen } from 'common/libs/uidGen';
2020-10-24 14:47:35 +02:00
import Tables from '@/ipc-api/Tables';
import BaseLoader from '@/components/BaseLoader';
2021-08-18 17:28:41 +02:00
import WorkspaceTabPropsTableFields from '@/components/WorkspaceTabPropsTableFields';
2021-08-12 09:54:13 +02:00
import WorkspaceTabPropsTableIndexesModal from '@/components/WorkspaceTabPropsTableIndexesModal';
import WorkspaceTabPropsTableForeignModal from '@/components/WorkspaceTabPropsTableForeignModal';
2020-10-24 14:47:35 +02:00
export default {
2021-08-12 09:54:13 +02:00
name: 'WorkspaceTabPropsTable',
2020-10-24 14:47:35 +02:00
components: {
BaseLoader,
2021-08-18 17:28:41 +02:00
WorkspaceTabPropsTableFields,
2021-08-12 09:54:13 +02:00
WorkspaceTabPropsTableIndexesModal,
WorkspaceTabPropsTableForeignModal
2020-10-24 14:47:35 +02:00
},
props: {
connection: Object,
2021-07-15 19:51:18 +02:00
isSelected: Boolean,
table: String,
schema: String
2020-10-24 14:47:35 +02:00
},
data () {
return {
isLoading: false,
2020-11-13 12:39:40 +01:00
isSaving: false,
2020-12-01 16:48:20 +01:00
isIndexesModal: false,
2020-12-15 17:08:36 +01:00
isForeignModal: false,
2020-11-16 17:16:39 +01:00
isOptionsChanging: false,
2020-11-13 12:39:40 +01:00
originalFields: [],
2020-10-24 14:47:35 +02:00
localFields: [],
2020-11-13 12:39:40 +01:00
originalKeyUsage: [],
2020-10-24 14:47:35 +02:00
localKeyUsage: [],
originalIndexes: [],
localIndexes: [],
tableOptions: {},
localOptions: {},
2020-12-01 16:48:20 +01:00
lastTable: null,
newFieldsCounter: 0
2020-10-24 14:47:35 +02:00
};
},
computed: {
...mapGetters({
2020-11-16 17:16:39 +01:00
getWorkspace: 'workspaces/getWorkspace',
selectedWorkspace: 'workspaces/getSelected',
2020-11-16 17:16:39 +01:00
getDatabaseVariable: 'workspaces/getDatabaseVariable'
2020-10-24 14:47:35 +02:00
}),
workspace () {
return this.getWorkspace(this.connection.uid);
},
2021-07-16 23:24:55 +02:00
tabUid () {
return this.$vnode.key;
},
2020-11-16 17:16:39 +01:00
defaultEngine () {
const engine = this.getDatabaseVariable(this.connection.uid, 'default_storage_engine');
return engine ? engine.value : '';
2020-11-16 17:16:39 +01:00
},
2020-12-15 17:08:36 +01:00
schemaTables () {
const schemaTables = this.workspace.structure
.filter(schema => schema.name === this.schema)
.map(schema => schema.tables);
return schemaTables.length ? schemaTables[0].filter(table => table.type === 'table') : [];
},
2020-11-13 12:39:40 +01:00
isChanged () {
2020-11-16 17:16:39 +01:00
return JSON.stringify(this.originalFields) !== JSON.stringify(this.localFields) ||
JSON.stringify(this.originalKeyUsage) !== JSON.stringify(this.localKeyUsage) ||
2020-12-01 16:48:20 +01:00
JSON.stringify(this.originalIndexes) !== JSON.stringify(this.localIndexes) ||
2020-11-16 17:16:39 +01:00
JSON.stringify(this.tableOptions) !== JSON.stringify(this.localOptions);
2020-10-24 14:47:35 +02:00
}
},
watch: {
2021-07-13 16:53:47 +02:00
schema () {
if (this.isSelected) {
this.getFieldsData();
this.lastTable = this.table;
}
},
2020-10-24 14:47:35 +02:00
table () {
if (this.isSelected) {
this.getFieldsData();
this.lastTable = this.table;
}
},
isSelected (val) {
2021-07-15 19:51:18 +02:00
if (val) {
this.changeBreadcrumbs({ schema: this.schema, table: this.table });
if (this.lastTable !== this.table)
this.getFieldsData();
2020-10-24 14:47:35 +02:00
}
2020-12-04 11:19:16 +01:00
},
isChanged (val) {
2021-07-16 23:24:55 +02:00
this.setUnsavedChanges({ uid: this.connection.uid, tUid: this.tabUid, isChanged: val });
2020-10-24 14:47:35 +02:00
}
},
created () {
2021-07-15 19:51:18 +02:00
this.getFieldsData();
window.addEventListener('keydown', this.onKey);
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);
},
2020-10-24 14:47:35 +02:00
methods: {
...mapActions({
2020-11-16 17:16:39 +01:00
addNotification: 'notifications/addNotification',
2020-12-04 11:19:16 +01:00
refreshStructure: 'workspaces/refreshStructure',
setUnsavedChanges: 'workspaces/setUnsavedChanges',
renameTabs: 'workspaces/renameTabs',
changeBreadcrumbs: 'workspaces/changeBreadcrumbs'
2020-10-24 14:47:35 +02:00
}),
async getTableOptions (params) {
const db = this.workspace.structure.find(db => db.name === this.schema);
if (db && db.tables.length && this.table)
this.tableOptions = db.tables.find(table => table.name === this.table);
else {
const { status, response } = await Tables.getTableOptions(params);
if (status === 'success')
this.tableOptions = response;
else
this.addNotification({ status: 'error', message: response });
}
},
2020-10-24 14:47:35 +02:00
async getFieldsData () {
if (!this.table) return;
this.localFields = [];
2021-07-15 19:51:18 +02:00
this.lastTable = this.table;
2020-12-01 16:48:20 +01:00
this.newFieldsCounter = 0;
this.isLoading = true;
2020-10-24 14:47:35 +02:00
const params = {
uid: this.connection.uid,
schema: this.schema,
2021-07-16 18:52:18 +02:00
table: this.table
2020-10-24 14:47:35 +02:00
};
try {
await this.getTableOptions(params);
this.localOptions = JSON.parse(JSON.stringify(this.tableOptions));
}
catch (err) {
console.error(err);
}
2020-10-24 14:47:35 +02:00
try { // Columns data
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
2020-11-13 12:39:40 +01:00
this.originalFields = response.map(field => {
if (field.autoIncrement)
field.defaultType = 'autoincrement';
else if (field.default === null)
field.defaultType = 'noval';
else if (field.default === 'NULL')
field.defaultType = 'null';
else if (isNaN(+field.default) && field.default.charAt(0) !== '\'')
field.defaultType = 'expression';
else {
field.defaultType = 'custom';
if (isNaN(+field.default) && !field.default.includes('\''))
field.default = `'${field.default}'`;
}
2021-11-08 15:12:37 +01:00
return { ...field, _antares_id: uidGen() };
2020-11-13 12:39:40 +01:00
});
this.localFields = JSON.parse(JSON.stringify(this.originalFields));
2020-10-24 14:47:35 +02:00
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
try { // Indexes
const { status, response } = await Tables.getTableIndexes(params);
if (status === 'success') {
2020-12-01 16:48:20 +01:00
const indexesObj = response.reduce((acc, curr) => {
acc[curr.name] = acc[curr.name] || [];
acc[curr.name].push(curr);
return acc;
}, {});
this.originalIndexes = Object.keys(indexesObj).map(index => {
return {
2021-11-08 15:12:37 +01:00
_antares_id: uidGen(),
2020-12-01 16:48:20 +01:00
name: index,
fields: indexesObj[index].map(field => field.column),
type: indexesObj[index][0].type,
comment: indexesObj[index][0].comment,
indexType: indexesObj[index][0].indexType,
indexComment: indexesObj[index][0].indexComment,
cardinality: indexesObj[index][0].cardinality
};
});
this.localIndexes = JSON.parse(JSON.stringify(this.originalIndexes));
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
2020-10-24 14:47:35 +02:00
try { // Key usage (foreign keys)
const { status, response } = await Tables.getKeyUsage(params);
if (status === 'success') {
2020-12-15 17:08:36 +01:00
this.originalKeyUsage = response.map(foreign => {
return {
2021-11-08 15:12:37 +01:00
_antares_id: uidGen(),
2020-12-15 17:08:36 +01:00
...foreign
};
});
this.localKeyUsage = JSON.parse(JSON.stringify(this.originalKeyUsage));
2020-10-24 14:47:35 +02:00
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
this.isLoading = false;
2020-10-24 14:47:35 +02:00
},
2020-11-13 12:39:40 +01:00
async saveChanges () {
if (this.isSaving) return;
this.isSaving = true;
2020-12-01 16:48:20 +01:00
// FIELDS
2021-11-08 15:12:37 +01:00
const originalIDs = this.originalFields.reduce((acc, curr) => [...acc, curr._antares_id], []);
const localIDs = this.localFields.reduce((acc, curr) => [...acc, curr._antares_id], []);
2020-11-13 15:04:51 +01:00
2020-12-01 16:48:20 +01:00
// Fields Additions
2021-11-08 15:12:37 +01:00
const additions = this.localFields.filter((field, i) => !originalIDs.includes(field._antares_id)).map(field => {
const lI = this.localFields.findIndex(localField => localField._antares_id === field._antares_id);
2020-11-13 15:04:51 +01:00
const after = lI > 0 ? this.localFields[lI - 1].name : false;
return { ...field, after };
});
2020-12-01 16:48:20 +01:00
// Fields Deletions
2021-11-08 15:12:37 +01:00
const deletions = this.originalFields.filter(field => !localIDs.includes(field._antares_id));
2020-11-13 12:39:40 +01:00
2020-12-01 16:48:20 +01:00
// Fields Changes
2020-11-13 12:39:40 +01:00
const changes = [];
this.originalFields.forEach((originalField, oI) => {
2021-11-08 15:12:37 +01:00
const lI = this.localFields.findIndex(localField => localField._antares_id === originalField._antares_id);
const originalSibling = oI > 0 ? this.originalFields[oI - 1]._antares_id : false;
const localSibling = lI > 0 ? this.localFields[lI - 1]._antares_id : false;
2020-11-13 12:39:40 +01:00
const after = lI > 0 ? this.localFields[lI - 1].name : false;
const orgName = originalField.name;
if (JSON.stringify(originalField) !== JSON.stringify(this.localFields[lI]) || originalSibling !== localSibling)
2020-11-13 16:19:59 +01:00
if (this.localFields[lI]) changes.push({ ...this.localFields[lI], after, orgName });
2020-11-13 12:39:40 +01:00
});
2020-11-16 17:16:39 +01:00
// OPTIONS
const options = Object.keys(this.localOptions).reduce((acc, option) => {
if (this.localOptions[option] !== this.tableOptions[option])
acc[option] = this.localOptions[option];
return acc;
}, {});
2020-12-01 16:48:20 +01:00
// INDEXES
const indexChanges = {
additions: [],
changes: [],
deletions: []
};
2021-11-08 15:12:37 +01:00
const originalIndexIDs = this.originalIndexes.reduce((acc, curr) => [...acc, curr._antares_id], []);
const localIndexIDs = this.localIndexes.reduce((acc, curr) => [...acc, curr._antares_id], []);
2020-12-01 16:48:20 +01:00
// Index Additions
2021-11-08 15:12:37 +01:00
indexChanges.additions = this.localIndexes.filter(index => !originalIndexIDs.includes(index._antares_id));
2020-12-01 16:48:20 +01:00
// Index Changes
this.originalIndexes.forEach(originalIndex => {
2021-11-08 15:12:37 +01:00
const lI = this.localIndexes.findIndex(localIndex => localIndex._antares_id === originalIndex._antares_id);
2020-12-01 16:48:20 +01:00
if (JSON.stringify(originalIndex) !== JSON.stringify(this.localIndexes[lI])) {
2020-12-01 17:29:16 +01:00
if (this.localIndexes[lI]) {
indexChanges.changes.push({
...this.localIndexes[lI],
oldName: originalIndex.name,
oldType: originalIndex.type
});
}
2020-12-01 16:48:20 +01:00
}
});
// Index Deletions
2021-11-08 15:12:37 +01:00
indexChanges.deletions = this.originalIndexes.filter(index => !localIndexIDs.includes(index._antares_id));
2020-12-01 16:48:20 +01:00
2020-12-15 17:08:36 +01:00
// FOREIGN KEYS
const foreignChanges = {
additions: [],
changes: [],
deletions: []
};
2021-11-08 15:12:37 +01:00
const originalForeignIDs = this.originalKeyUsage.reduce((acc, curr) => [...acc, curr._antares_id], []);
const localForeignIDs = this.localKeyUsage.reduce((acc, curr) => [...acc, curr._antares_id], []);
2020-12-15 17:08:36 +01:00
// Foreigns Additions
2021-11-08 15:12:37 +01:00
foreignChanges.additions = this.localKeyUsage.filter(foreign => !originalForeignIDs.includes(foreign._antares_id));
2020-12-15 17:08:36 +01:00
// Foreigns Changes
this.originalKeyUsage.forEach(originalForeign => {
2021-11-08 15:12:37 +01:00
const lI = this.localKeyUsage.findIndex(localForeign => localForeign._antares_id === originalForeign._antares_id);
2020-12-15 17:08:36 +01:00
if (JSON.stringify(originalForeign) !== JSON.stringify(this.localKeyUsage[lI])) {
if (this.localKeyUsage[lI]) {
foreignChanges.changes.push({
...this.localKeyUsage[lI],
oldName: originalForeign.constraintName
});
}
}
});
// Foreigns Deletions
2021-11-08 15:12:37 +01:00
foreignChanges.deletions = this.originalKeyUsage.filter(foreign => !localForeignIDs.includes(foreign._antares_id));
2020-12-15 17:08:36 +01:00
// ALTER
2020-11-13 12:39:40 +01:00
const params = {
uid: this.connection.uid,
schema: this.schema,
2021-07-16 18:52:18 +02:00
table: this.table,
2021-11-18 11:36:46 +01:00
tableStructure: {
name: this.localOptions.name,
fields: this.localFields,
foreigns: this.localKeyUsage,
indexes: this.localIndexes
},
2020-11-13 12:39:40 +01:00
additions,
changes,
2020-11-16 17:16:39 +01:00
deletions,
2020-12-01 16:48:20 +01:00
indexChanges,
2020-12-15 17:08:36 +01:00
foreignChanges,
2020-11-16 17:16:39 +01:00
options
2020-11-13 12:39:40 +01:00
};
2020-12-15 17:08:36 +01:00
try {
2020-11-13 12:39:40 +01:00
const { status, response } = await Tables.alterTable(params);
2020-11-16 17:16:39 +01:00
if (status === 'success') {
const oldName = this.tableOptions.name;
2020-11-16 17:16:39 +01:00
await this.refreshStructure(this.connection.uid);
if (oldName !== this.localOptions.name) {
this.renameTabs({
uid: this.connection.uid,
schema: this.schema,
elementName: oldName,
elementNewName: this.localOptions.name,
elementType: 'table'
});
2021-07-18 16:10:36 +02:00
this.changeBreadcrumbs({ schema: this.schema, table: this.localOptions.name });
}
2021-07-21 18:50:22 +02:00
else
this.getFieldsData();
2020-11-16 17:16:39 +01:00
}
2020-11-13 12:39:40 +01:00
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
this.isSaving = false;
2020-12-01 16:48:20 +01:00
this.newFieldsCounter = 0;
2020-11-13 12:39:40 +01:00
},
clearChanges () {
this.localFields = JSON.parse(JSON.stringify(this.originalFields));
2020-12-01 16:48:20 +01:00
this.localIndexes = JSON.parse(JSON.stringify(this.originalIndexes));
2020-11-13 12:39:40 +01:00
this.localKeyUsage = JSON.parse(JSON.stringify(this.originalKeyUsage));
2020-11-16 17:16:39 +01:00
this.localOptions = JSON.parse(JSON.stringify(this.tableOptions));
2020-12-01 16:48:20 +01:00
this.newFieldsCounter = 0;
2020-10-24 14:47:35 +02:00
},
2020-11-13 15:04:51 +01:00
addField () {
this.localFields.push({
2021-11-08 15:12:37 +01:00
_antares_id: uidGen(),
2020-12-01 16:48:20 +01:00
name: `${this.$tc('word.field', 1)}_${++this.newFieldsCounter}`,
2020-11-13 15:04:51 +01:00
key: '',
2021-03-25 18:33:29 +01:00
type: this.workspace.dataTypes[0].types[0].name,
2020-11-13 15:04:51 +01:00
schema: this.schema,
table: this.table,
numPrecision: null,
2021-03-25 18:33:29 +01:00
numLength: this.workspace.dataTypes[0].types[0].length,
2020-11-13 15:04:51 +01:00
datePrecision: null,
charLength: null,
nullable: false,
unsigned: false,
zerofill: false,
order: this.localFields.length + 1,
default: null,
charset: null,
collation: null,
autoIncrement: false,
onUpdate: '',
comment: ''
});
2020-12-01 16:48:20 +01:00
setTimeout(() => {
const scrollable = this.$refs.indexTable.$refs.tableWrapper;
scrollable.scrollTop = scrollable.scrollHeight + 30;
}, 20);
2020-11-13 15:04:51 +01:00
},
renameField (payload) {
this.localIndexes = this.localIndexes.map(index => {
const fi = index.fields.findIndex(field => field === payload.old);
if (fi !== -1)
index.fields[fi] = payload.new;
return index;
});
this.localKeyUsage = this.localKeyUsage.map(key => {
if (key.field === payload.old)
key.field = payload.new;
return key;
});
},
duplicateField (uid) {
2021-11-08 15:12:37 +01:00
const fieldToClone = Object.assign({}, this.localFields.find(field => field._antares_id === uid));
fieldToClone._antares_id = uidGen();
fieldToClone.name = `${fieldToClone.name}_copy`;
fieldToClone.order = this.localFields.length + 1;
this.localFields = [...this.localFields, fieldToClone];
setTimeout(() => {
const scrollable = this.$refs.indexTable.$refs.tableWrapper;
scrollable.scrollTop = scrollable.scrollHeight + 30;
}, 20);
},
2020-11-13 15:04:51 +01:00
removeField (uid) {
2021-11-08 15:12:37 +01:00
this.localFields = this.localFields.filter(field => field._antares_id !== uid);
2020-11-13 15:04:51 +01:00
},
2020-12-01 16:48:20 +01:00
addNewIndex (payload) {
this.localIndexes = [...this.localIndexes, {
2021-11-08 15:12:37 +01:00
_antares_id: uidGen(),
2020-12-01 16:48:20 +01:00
name: payload.index === 'PRIMARY' ? 'PRIMARY' : payload.field,
fields: [payload.field],
type: payload.index,
comment: '',
indexType: 'BTREE',
indexComment: '',
cardinality: 0
}];
},
addToIndex (payload) {
this.localIndexes = this.localIndexes.map(index => {
2021-11-08 15:12:37 +01:00
if (index._antares_id === payload.index) index.fields.push(payload.field);
2020-12-01 16:48:20 +01:00
return index;
});
},
optionsUpdate (options) {
this.localOptions = options;
2020-12-01 16:48:20 +01:00
},
showIntdexesModal () {
this.isIndexesModal = true;
},
hideIndexesModal () {
this.isIndexesModal = false;
},
indexesUpdate (indexes) {
this.localIndexes = indexes;
2020-12-15 17:08:36 +01:00
},
showForeignModal () {
this.isForeignModal = true;
},
hideForeignModal () {
this.isForeignModal = false;
},
foreignsUpdate (foreigns) {
this.localKeyUsage = foreigns;
},
onKey (e) {
if (this.isSelected) {
e.stopPropagation();
if (e.ctrlKey && e.keyCode === 83) { // CTRL + S
if (this.isChanged)
this.saveChanges();
}
}
2020-10-24 14:47:35 +02:00
}
}
};
</script>