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}"
2021-04-20 17:39:15 +02:00
title = "CTRL+S"
2020-11-13 12:39:40 +01:00
@ click = "saveChanges"
>
2021-07-09 15:51:02 +02:00
< 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
2020-11-13 12:39:40 +01:00
: disabled = "!isChanged"
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
>
2021-07-09 15:51:02 +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
class = "btn btn-dark btn-sm"
: title = "$t('message.addNewField')"
@ click = "addField"
>
2021-07-09 15:51:02 +02:00
< 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
class = "btn btn-dark btn-sm"
: title = "$t('message.manageIndexes')"
@ click = "showIntdexesModal"
>
2021-07-09 15:51:02 +02:00
< 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 >
2020-12-15 17:08:36 +01:00
< button class = "btn btn-dark btn-sm" @click ="showForeignModal" >
2021-07-09 15:51:02 +02:00
< i class = "mdi mdi-24px mdi-key-link mr-1" / >
2020-10-24 14:47:35 +02:00
< span > { { $t ( 'word.foreignKeys' ) } } < / span >
< / button >
2020-11-16 17:16:39 +01:00
< button class = "btn btn-dark btn-sm" @click ="showOptionsModal" >
2021-07-09 15:51:02 +02:00
< i class = "mdi mdi-24px mdi-cogs mr-1" / >
2020-10-24 14:47:35 +02:00
< span > { { $t ( 'word.options' ) } } < / 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 >
2021-01-22 18:27:45 +01:00
< div class = "workspace-query-results column col-12 p-relative" >
< BaseLoader v -if = " isLoading " / >
2020-10-24 14:47:35 +02:00
< WorkspacePropsTable
v - if = "localFields"
2020-12-01 16:48:20 +01:00
ref = "indexTable"
2020-11-13 12:39:40 +01:00
: fields = "localFields"
2020-11-20 17:24:02 +01:00
: 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"
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"
2021-04-16 17:42:16 +02:00
@ rename - field = "renameField"
2020-10-24 14:47:35 +02:00
/ >
< / div >
2020-11-23 12:25:44 +01:00
< WorkspacePropsOptionsModal
2020-11-16 17:16:39 +01:00
v - if = "isOptionsModal"
2020-11-23 12:25:44 +01:00
: local - options = "localOptions"
: table = "table"
: workspace = "workspace"
2020-11-16 17:16:39 +01:00
@ hide = "hideOptionsModal"
2020-11-23 12:25:44 +01:00
@ options - update = "optionsUpdate"
/ >
2020-12-01 16:48:20 +01:00
< WorkspacePropsIndexesModal
v - if = "isIndexesModal"
: local - indexes = "localIndexes"
: table = "table"
: fields = "localFields"
: index - types = "workspace.indexTypes"
: workspace = "workspace"
@ hide = "hideIndexesModal"
@ indexes - update = "indexesUpdate"
/ >
2020-12-15 17:08:36 +01:00
< WorkspacePropsForeignModal
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' ;
2021-01-22 18:27:45 +01:00
import BaseLoader from '@/components/BaseLoader' ;
2020-10-24 14:47:35 +02:00
import WorkspacePropsTable from '@/components/WorkspacePropsTable' ;
2020-11-23 12:25:44 +01:00
import WorkspacePropsOptionsModal from '@/components/WorkspacePropsOptionsModal' ;
2020-12-01 16:48:20 +01:00
import WorkspacePropsIndexesModal from '@/components/WorkspacePropsIndexesModal' ;
2020-12-15 17:08:36 +01:00
import WorkspacePropsForeignModal from '@/components/WorkspacePropsForeignModal' ;
2020-10-24 14:47:35 +02:00
export default {
name : 'WorkspacePropsTab' ,
components : {
2021-01-22 18:27:45 +01:00
BaseLoader ,
2020-11-16 17:16:39 +01:00
WorkspacePropsTable ,
2020-12-01 16:48:20 +01:00
WorkspacePropsOptionsModal ,
2020-12-15 17:08:36 +01:00
WorkspacePropsIndexesModal ,
WorkspacePropsForeignModal
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 {
2021-07-15 19:51:18 +02:00
tabUid : 'prop' , // ???
2021-01-22 18:27:45 +01:00
isLoading : false ,
2020-11-13 12:39:40 +01:00
isSaving : false ,
2020-11-16 17:16:39 +01:00
isOptionsModal : 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 : [ ] ,
2020-11-20 17:24:02 +01:00
originalIndexes : [ ] ,
localIndexes : [ ] ,
2020-11-23 12:25:44 +01:00
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' ,
2021-04-20 17:39:15 +02:00
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 ) ;
} ,
2020-11-16 17:16:39 +01:00
tableOptions ( ) {
const db = this . workspace . structure . find ( db => db . name === this . schema ) ;
2020-12-04 11:19:16 +01:00
return db && this . table ? db . tables . find ( table => table . name === this . table ) : { } ;
2020-11-16 17:16:39 +01:00
} ,
defaultEngine ( ) {
return this . getDatabaseVariable ( this . connection . uid , 'default_storage_engine' ) . value || '' ;
} ,
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 ) {
if ( this . isSelected && this . lastTable === this . table && this . table !== null )
this . setUnsavedChanges ( val ) ;
2020-10-24 14:47:35 +02:00
}
} ,
2021-04-20 17:39:15 +02:00
created ( ) {
2021-07-15 19:51:18 +02:00
this . getFieldsData ( ) ;
2021-04-20 17:39:15 +02:00
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' ,
2020-12-27 13:08:13 +01:00
setUnsavedChanges : 'workspaces/setUnsavedChanges' ,
2021-07-15 19:51:18 +02:00
newTab : 'workspaces/newTab' ,
2020-12-27 13:08:13 +01:00
changeBreadcrumbs : 'workspaces/changeBreadcrumbs'
2020-10-24 14:47:35 +02:00
} ) ,
async getFieldsData ( ) {
if ( ! this . table ) return ;
2021-01-22 18:27:45 +01:00
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 ;
2021-01-22 18:27:45 +01:00
this . isLoading = true ;
2020-11-16 17:16:39 +01:00
this . localOptions = JSON . parse ( JSON . stringify ( this . tableOptions ) ) ;
2020-10-24 14:47:35 +02:00
const params = {
uid : this . connection . uid ,
schema : this . schema ,
table : this . workspace . breadcrumbs . table
} ;
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 => {
2021-05-06 22:21:42 +02:00
if ( field . autoIncrement )
field . defaultType = 'autoincrement' ;
else if ( field . default === null )
field . defaultType = 'noval' ;
else if ( field . default === 'NULL' )
field . defaultType = 'null' ;
2021-05-25 16:54:13 +02:00
else if ( isNaN ( + field . default ) && field . default . charAt ( 0 ) !== '\'' )
2021-05-06 22:21:42 +02:00
field . defaultType = 'expression' ;
else {
field . defaultType = 'custom' ;
2021-05-25 16:54:13 +02:00
if ( isNaN ( + field . default ) && ! field . default . includes ( '\'' ) )
2021-05-06 22:21:42 +02:00
field . default = ` ' ${ field . default } ' ` ;
}
2020-11-13 12:39:40 +01:00
return { ... field , _id : uidGen ( ) } ;
} ) ;
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 } ) ;
}
2020-11-20 17:24:02 +01:00
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 {
_id : uidGen ( ) ,
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 ) ) ;
2020-11-20 17:24:02 +01:00
}
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 {
_id : uidGen ( ) ,
... 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 } ) ;
}
2021-01-22 18:27:45 +01:00
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
2020-11-13 12:39:40 +01:00
const originalIDs = this . originalFields . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
const localIDs = this . localFields . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
2020-11-13 15:04:51 +01:00
2020-12-01 16:48:20 +01:00
// Fields Additions
2020-11-13 15:04:51 +01:00
const additions = this . localFields . filter ( ( field , i ) => ! originalIDs . includes ( field . _id ) ) . map ( field => {
const lI = this . localFields . findIndex ( localField => localField . _id === field . _id ) ;
const after = lI > 0 ? this . localFields [ lI - 1 ] . name : false ;
return { ... field , after } ;
} ) ;
2020-12-01 16:48:20 +01:00
// Fields Deletions
2020-11-13 12:39:40 +01:00
const deletions = this . originalFields . filter ( field => ! localIDs . includes ( field . _id ) ) ;
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 ) => {
const lI = this . localFields . findIndex ( localField => localField . _id === originalField . _id ) ;
const originalSibling = oI > 0 ? this . originalFields [ oI - 1 ] . _id : false ;
const localSibling = lI > 0 ? this . localFields [ lI - 1 ] . _id : false ;
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 : [ ]
} ;
const originalIndexIDs = this . originalIndexes . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
const localIndexIDs = this . localIndexes . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
// Index Additions
indexChanges . additions = this . localIndexes . filter ( index => ! originalIndexIDs . includes ( index . _id ) ) ;
// Index Changes
this . originalIndexes . forEach ( originalIndex => {
const lI = this . localIndexes . findIndex ( localIndex => localIndex . _id === originalIndex . _id ) ;
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
indexChanges . deletions = this . originalIndexes . filter ( index => ! localIndexIDs . includes ( index . _id ) ) ;
2020-12-15 17:08:36 +01:00
// FOREIGN KEYS
const foreignChanges = {
additions : [ ] ,
changes : [ ] ,
deletions : [ ]
} ;
const originalForeignIDs = this . originalKeyUsage . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
const localForeignIDs = this . localKeyUsage . reduce ( ( acc , curr ) => [ ... acc , curr . _id ] , [ ] ) ;
// Foreigns Additions
foreignChanges . additions = this . localKeyUsage . filter ( foreign => ! originalForeignIDs . includes ( foreign . _id ) ) ;
// Foreigns Changes
this . originalKeyUsage . forEach ( originalForeign => {
const lI = this . localKeyUsage . findIndex ( localForeign => localForeign . _id === originalForeign . _id ) ;
if ( JSON . stringify ( originalForeign ) !== JSON . stringify ( this . localKeyUsage [ lI ] ) ) {
if ( this . localKeyUsage [ lI ] ) {
foreignChanges . changes . push ( {
... this . localKeyUsage [ lI ] ,
oldName : originalForeign . constraintName
} ) ;
}
}
} ) ;
// Foreigns Deletions
foreignChanges . deletions = this . originalKeyUsage . filter ( foreign => ! localForeignIDs . includes ( foreign . _id ) ) ;
// ALTER
2020-11-13 12:39:40 +01:00
const params = {
uid : this . connection . uid ,
schema : this . schema ,
table : this . workspace . breadcrumbs . table ,
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' ) {
2020-12-27 13:08:13 +01:00
const oldName = this . tableOptions . name ;
2020-11-16 17:16:39 +01:00
await this . refreshStructure ( this . connection . uid ) ;
2020-12-27 13:08:13 +01:00
if ( oldName !== this . localOptions . name ) {
this . setUnsavedChanges ( false ) ;
2021-07-15 19:51:18 +02:00
this . newTab ( { uid : this . connection . uid , schema : this . schema , table : this . localOptions . name , type : 'table-props' } ) ; // TODO: rename function that gets new and old name and change it on all opened tables
2020-12-27 13:08:13 +01:00
this . changeBreadcrumbs ( { schema : this . schema , table : this . localOptions . name } ) ;
}
2020-11-13 12:39:40 +01:00
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 ( {
_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
} ,
2021-04-16 17:42:16 +02: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 ;
} ) ;
} ,
2020-11-13 15:04:51 +01:00
removeField ( uid ) {
this . localFields = this . localFields . filter ( field => field . _id !== uid ) ;
} ,
2020-12-01 16:48:20 +01:00
addNewIndex ( payload ) {
this . localIndexes = [ ... this . localIndexes , {
_id : uidGen ( ) ,
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 => {
if ( index . _id === payload . index ) index . fields . push ( payload . field ) ;
return index ;
} ) ;
} ,
2020-11-16 17:16:39 +01:00
showOptionsModal ( ) {
this . isOptionsModal = true ;
} ,
hideOptionsModal ( ) {
this . isOptionsModal = false ;
} ,
2020-11-23 12:25:44 +01:00
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 ;
2021-04-20 17:39:15 +02:00
} ,
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 >