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.
950 lines
27 KiB
950 lines
27 KiB
4 years ago
|
<template>
|
||
|
<div class="">
|
||
|
<p>Mock</p>
|
||
|
<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.table_name + ' (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 />
|
||
4 years ago
|
<v-btn
|
||
|
color="primary"
|
||
|
small
|
||
|
@click="loadColumnList"
|
||
|
>
|
||
3 years ago
|
<v-icon left>
|
||
|
refresh
|
||
|
</v-icon>
|
||
4 years ago
|
Refresh
|
||
|
</v-btn>
|
||
|
<v-btn
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
small
|
||
|
@click="addColumn"
|
||
|
>
|
||
3 years ago
|
New Column
|
||
|
</v-btn>
|
||
4 years ago
|
|
||
|
<v-btn
|
||
|
color="primary"
|
||
|
class="primary"
|
||
|
small
|
||
|
:disabled="!edited && !newTable"
|
||
3 years ago
|
@click="applyChanges"
|
||
|
>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
<v-progress-circular
|
||
|
v-if="progress.save"
|
||
|
:indeterminate="progress.save"
|
||
|
:size="20"
|
||
|
color="secondary"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</v-btn>
|
||
|
<v-btn
|
||
|
small
|
||
|
color="error "
|
||
3 years ago
|
class="error text-right"
|
||
|
@click="deleteTable('showDialog')"
|
||
|
>
|
||
3 years ago
|
{{ $t('activity.deleteTable') }}
|
||
4 years ago
|
|
||
|
<v-progress-circular
|
||
|
v-if="progress.deleteTable"
|
||
|
:indeterminate="progress.deleteTable"
|
||
|
:size="20"
|
||
|
color="secondary"
|
||
3 years ago
|
/>
|
||
|
</v-btn>
|
||
4 years ago
|
<v-btn
|
||
|
icon
|
||
3 years ago
|
class="text-right"
|
||
|
>
|
||
4 years ago
|
<v-icon>mdi-help-circle-outline</v-icon>
|
||
|
</v-btn>
|
||
|
</v-toolbar>
|
||
|
<v-card style="">
|
||
|
<v-data-table
|
||
|
dense
|
||
|
:headers="headers"
|
||
|
:items="columns"
|
||
|
hide-default-header
|
||
|
footer-props.items-per-page-options="30"
|
||
|
class="elevation-20 column-table"
|
||
|
>
|
||
3 years ago
|
<template #header="{props:{headers}}">
|
||
|
<th v-for="header in headers" :key="header.title" class="pt-2 pb-0">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ header.text }}</span>
|
||
4 years ago
|
</template>
|
||
3 years ago
|
<span>{{ header.title }}</span>
|
||
4 years ago
|
</v-tooltip>
|
||
|
</th>
|
||
|
</template>
|
||
|
|
||
3 years ago
|
<template #item="props">
|
||
3 years ago
|
<tr :disabled="nodes.table_name==='_evolutions' || nodes.table_name==='nc_evolutions'">
|
||
4 years ago
|
<td>
|
||
|
<v-edit-dialog
|
||
3 years ago
|
:return-value.sync="props.item.column_name"
|
||
4 years ago
|
@save="saveColumnName(props.item)"
|
||
|
@cancel="cancel"
|
||
|
@open="open"
|
||
|
@close="close"
|
||
|
>
|
||
3 years ago
|
{{ props.item.column_name }}
|
||
3 years ago
|
<template #input>
|
||
4 years ago
|
<v-text-field
|
||
3 years ago
|
v-model="props.item.column_name"
|
||
3 years ago
|
:disabled="props.item.rcn"
|
||
4 years ago
|
:rules="[max25chars]"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
4 years ago
|
single-line
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
|
<!-- <v-autocomplete-->
|
||
|
<!-- :full-width="false"-->
|
||
|
<!-- v-model="props.item.dtx"-->
|
||
|
<!-- :items="dataTypes"-->
|
||
|
<!-- @change="onDataTypeChange(props.item,props.index)"-->
|
||
|
<!-- dense-->
|
||
|
<!-- ></v-autocomplete>-->
|
||
|
<v-autocomplete
|
||
|
v-model="props.item.dt"
|
||
3 years ago
|
:full-width="false"
|
||
4 years ago
|
:items="dataTypes"
|
||
|
dense
|
||
3 years ago
|
@change="onDataTypeChange(props.item,props.index)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
<!-- <td>-->
|
||
|
<!-- <v-edit-dialog-->
|
||
|
<!-- :return-value.sync="props.item.data_type_x_specific"-->
|
||
|
<!-- lazy-->
|
||
|
<!-- @save="save"-->
|
||
|
<!-- @cancel="cancel"-->
|
||
|
<!-- @open="open"-->
|
||
|
<!-- @close="close"-->
|
||
|
<!-- v-if="props.item.dtx==='specificType'"-->
|
||
|
<!-- >-->
|
||
|
<!-- {{ props.item.ct}}-->
|
||
|
<!-- <template v-slot:input>-->
|
||
|
<!-- <v-text-field-->
|
||
|
<!-- v-model="props.item.ct"-->
|
||
|
<!-- :rules="[max25chars]"-->
|
||
|
<!-- label="Edit"-->
|
||
|
<!-- single-line-->
|
||
|
<!-- ></v-text-field>-->
|
||
|
<!-- </template>-->
|
||
|
<!-- </v-edit-dialog>-->
|
||
|
<!-- </td>-->
|
||
|
<td>
|
||
|
<v-edit-dialog
|
||
|
v-if="props.item.dtxp"
|
||
|
:return-value.sync="props.item.dtxp"
|
||
|
lazy
|
||
|
@save="savePrecision(props.item)"
|
||
|
@cancel="cancelPrecision"
|
||
|
@open="openPrecision"
|
||
3 years ago
|
@close="closePrecision"
|
||
|
>
|
||
4 years ago
|
{{ props.item.dtxp }}
|
||
3 years ago
|
<template #input>
|
||
4 years ago
|
<v-text-field
|
||
|
v-model="props.item.dtxp"
|
||
|
:rules="[max25chars]"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
4 years ago
|
single-line
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-edit-dialog
|
||
|
v-if="props.item.dtxs"
|
||
|
:return-value.sync="props.item.dtxs"
|
||
|
lazy
|
||
|
@save="saveScale(props.item)"
|
||
|
@cancel="cancelScale"
|
||
|
@open="openScale"
|
||
|
@close="closeScale"
|
||
|
>
|
||
|
{{ props.item.dtxs }}
|
||
3 years ago
|
<template #input>
|
||
4 years ago
|
<v-text-field
|
||
|
v-model="props.item.dtxs"
|
||
|
:rules="[max25chars]"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
4 years ago
|
single-line
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.pk"
|
||
4 years ago
|
solo
|
||
|
height="44"
|
||
|
color=""
|
||
3 years ago
|
@change="onCheckboxChangePk(props.item)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.rqd"
|
||
4 years ago
|
solo
|
||
|
color=""
|
||
3 years ago
|
@change="onCheckboxChangeNN(props.item)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.un"
|
||
4 years ago
|
:disabled="colPropUNDisabled(props.item)"
|
||
|
solo
|
||
|
color=""
|
||
3 years ago
|
@change="onCheckboxChangeUN(props.item)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
<td>
|
||
|
<v-checkbox
|
||
3 years ago
|
v-model="props.item.ai"
|
||
4 years ago
|
:disabled="colPropAIDisabled(props.item)"
|
||
|
solo
|
||
|
color=""
|
||
3 years ago
|
@change="onCheckboxChangeAI(props.item)"
|
||
|
/>
|
||
4 years ago
|
</td>
|
||
|
|
||
|
<td>
|
||
|
<p v-if="props.item.rtn" row wrap>
|
||
|
{{ props.item.rtn }}
|
||
3 years ago
|
<v-icon
|
||
|
small
|
||
|
@click="createNewOrEditRelation(props.item)"
|
||
4 years ago
|
>
|
||
3 years ago
|
mdi-table-edit
|
||
|
</v-icon>
|
||
|
<v-icon
|
||
|
small
|
||
|
color="error"
|
||
|
@click="deleteRelation('showDialog', props.item)"
|
||
4 years ago
|
>
|
||
3 years ago
|
mdi-delete-forever
|
||
|
</v-icon>
|
||
4 years ago
|
</p>
|
||
|
|
||
|
<v-icon
|
||
|
v-else-if="!props.item.pk"
|
||
|
color=""
|
||
|
@click="createNewOrEditRelation(props.item)"
|
||
3 years ago
|
>
|
||
|
add
|
||
4 years ago
|
</v-icon>
|
||
|
|
||
|
<v-icon
|
||
|
v-else
|
||
|
disabled
|
||
|
color="grey"
|
||
3 years ago
|
>
|
||
|
add
|
||
4 years ago
|
</v-icon>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-edit-dialog
|
||
|
:return-value.sync="props.item.cdf"
|
||
|
large
|
||
|
lazy
|
||
|
persistent
|
||
|
@save="saveDefaultValue(props.item)"
|
||
|
@cancel="cancel"
|
||
|
@open="open"
|
||
|
@close="close"
|
||
|
>
|
||
|
<!-- <div v-if="props.item.rqd">{{ props.item.cdf }}</div>-->
|
||
3 years ago
|
<div v-if="props.item.pk" />
|
||
|
<div v-else-if="!props.item.cdf && !props.item.rqd">
|
||
|
NULL
|
||
|
</div>
|
||
|
<div v-else>
|
||
|
{{ props.item.cdf }}
|
||
|
</div>
|
||
|
<!-- <template #input>-->
|
||
|
<!-- <div class="mt-3 title">-->
|
||
|
<!-- Update column_default-->
|
||
|
<!-- </div>-->
|
||
|
<!-- </template>-->
|
||
|
<template #input>
|
||
4 years ago
|
<v-text-field
|
||
|
v-model="props.item.cdf"
|
||
3 years ago
|
:label="$t('general.edit')"
|
||
4 years ago
|
single-line
|
||
|
counter
|
||
|
autofocus
|
||
3 years ago
|
/>
|
||
4 years ago
|
</template>
|
||
|
</v-edit-dialog>
|
||
|
</td>
|
||
|
<td>
|
||
|
<v-icon
|
||
|
color="error"
|
||
|
icon
|
||
|
@click="deleteColumn('showDialog', props.index, props.item)"
|
||
|
>
|
||
3 years ago
|
mdi-delete-forever
|
||
|
</v-icon>
|
||
4 years ago
|
</td>
|
||
|
</tr>
|
||
|
</template>
|
||
|
</v-data-table>
|
||
|
</v-card>
|
||
|
<addRelationDlg
|
||
|
v-if="dialogShow"
|
||
|
:nodes="nodes"
|
||
|
:column="selectedColForNewRelation"
|
||
|
heading="Relation Column "
|
||
3 years ago
|
:dialog-show="dialogShow"
|
||
|
:mtd-dialog-submit="mtdNewRelationDlgSubmit"
|
||
|
:mtd-dialog-cancel="mtdNewRelationDlgCancel"
|
||
4 years ago
|
/>
|
||
3 years ago
|
<span v-else />
|
||
4 years ago
|
<dlgLabelSubmitCancel
|
||
|
v-if="columnDeleteDlg"
|
||
3 years ago
|
type="primary"
|
||
|
:dialog-show="columnDeleteDlg"
|
||
|
:actions-mtd="deleteColumn"
|
||
4 years ago
|
heading="Click Submit to Delete the Column"
|
||
|
/>
|
||
|
<dlgLabelSubmitCancel
|
||
|
v-if="relationDeleteDlg"
|
||
3 years ago
|
type="primary"
|
||
|
:dialog-show="relationDeleteDlg"
|
||
|
:actions-mtd="deleteRelation"
|
||
4 years ago
|
heading="Click Submit to Delete the Relation"
|
||
|
/>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { mapGetters, mapActions } from 'vuex'
|
||
3 years ago
|
import addRelationDlg from '../dlgs/DlgAddRelation.vue'
|
||
|
import dlgLabelSubmitCancel from '../../utils/DlgLabelSubmitCancel.vue'
|
||
3 years ago
|
|
||
|
export default {
|
||
|
components: { addRelationDlg, dlgLabelSubmitCancel },
|
||
3 years ago
|
data() {
|
||
3 years ago
|
return {
|
||
|
progress: {
|
||
|
save: false,
|
||
|
deleteTable: false,
|
||
|
refresh: false
|
||
|
},
|
||
|
edited: false,
|
||
|
columnDeleteDlg: false,
|
||
|
selectedColForDelete: null,
|
||
|
relationDeleteDlg: false,
|
||
|
selectedColForRelationDelete: null,
|
||
|
columns: [],
|
||
|
dataTypes: [],
|
||
|
headers: [
|
||
|
{
|
||
|
text: 'Column',
|
||
|
title: 'Column name',
|
||
|
value: 'cn',
|
||
|
sortable: false,
|
||
|
width: '1%'
|
||
4 years ago
|
},
|
||
3 years ago
|
{ text: 'Data Type', title: 'Data Type', value: 'dt', sortable: false, width: '10%' },
|
||
|
// {text: "Type",title:', value: "dt", sortable: false, width: "10%"},
|
||
|
{ text: 'Length/Values', title: 'Length/Values', value: 'dt', sortable: false, width: '10%' },
|
||
|
{ text: 'Scale', title: 'Scale', value: 'dt', sortable: false, width: '10%' },
|
||
|
{ text: 'PK', title: 'Primary Key', value: 'pk', sortable: false, width: '1%' },
|
||
|
{ text: 'NN', title: 'Not NULL', value: 'rqd', sortable: false, width: '1%' },
|
||
|
{ text: 'UN', title: 'Unsigned', value: 'unsigned', sortable: false, width: '1%' },
|
||
|
{ text: 'AI', title: 'Auto Increment', value: 'ai', sortable: false, width: '1%' },
|
||
|
{ text: 'Foreign Key', title: 'Foreign Key', value: '', sortable: false, width: '20%' },
|
||
|
{
|
||
|
text: 'Default',
|
||
|
title: 'Default Value',
|
||
|
value: 'cdf',
|
||
|
sortable: false,
|
||
|
width: '10%'
|
||
|
},
|
||
|
{ text: '', title: 'Action', value: '', sortable: false, width: '1%' }
|
||
|
],
|
||
|
max25chars: v => v.length <= 150 || 'Input too long!',
|
||
|
dialogShow: false,
|
||
|
selectedColForNewRelation: null
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
...mapActions({
|
||
|
loadTablesFromChildTreeNode: 'project/loadTablesFromChildTreeNode'
|
||
|
}),
|
||
3 years ago
|
async onCheckboxChange() {
|
||
3 years ago
|
this.edited = true
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async onCheckboxChangePk(col) {
|
||
3 years ago
|
this.edited = true
|
||
|
col.altered = col.altered || 2
|
||
4 years ago
|
|
||
3 years ago
|
col.cdf = null
|
||
|
col.rqd = true
|
||
|
},
|
||
3 years ago
|
colPropAIDisabled(col) {
|
||
3 years ago
|
if (col.dtx === 'integer' ||
|
||
4 years ago
|
col.dtx === 'bigInteger' ||
|
||
|
col.dtx === 'specificType') {
|
||
3 years ago
|
for (let i = 0; i < this.columns.length; ++i) {
|
||
3 years ago
|
if (this.columns[i].column_name !== col.column_name && this.columns[i].ai) {
|
||
3 years ago
|
return true
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
return false
|
||
|
} else {
|
||
|
return true
|
||
|
}
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
colPropUNDisabled(col) {
|
||
3 years ago
|
if (col.dtx === 'integer' ||
|
||
4 years ago
|
col.dtx === 'bigInteger' ||
|
||
3 years ago
|
col.dt.includes('int')) {
|
||
|
return false
|
||
|
} else {
|
||
|
return true
|
||
|
}
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
onCheckboxChangeAI(col) {
|
||
3 years ago
|
console.log(col)
|
||
|
if (col.dt === 'int' || col.dt === 'bigint' || col.dt === 'smallint' || col.dt === 'tinyint') {
|
||
|
col.altered = col.altered || 2
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
if (!col.ai) {
|
||
|
col.dtx = 'specificType'
|
||
|
} else {
|
||
|
col.dtx = ''
|
||
|
}
|
||
4 years ago
|
|
||
3 years ago
|
this.edited = true
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
onCheckboxChangeNN(col) {
|
||
3 years ago
|
col.altered = col.altered || 2
|
||
|
this.edited = true
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
onCheckboxChangeUN(col) {
|
||
3 years ago
|
col.altered = col.altered || 2
|
||
|
this.edited = true
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
async onDataTypeChange(column, index) {
|
||
3 years ago
|
this.edited = true
|
||
|
column.altered = column.altered || 2
|
||
|
column.rqd = false
|
||
|
column.pk = false
|
||
|
column.ai = false
|
||
|
column.cdf = null
|
||
|
column.dtxp = ' '
|
||
|
column.dtxs = ' '
|
||
4 years ago
|
|
||
3 years ago
|
column.dtx = 'specificType'
|
||
4 years ago
|
|
||
3 years ago
|
console.log('data type changed', index, column)
|
||
|
},
|
||
3 years ago
|
async loadColumnList() {
|
||
3 years ago
|
this.edited = false
|
||
|
if (this.newTable) {
|
||
|
this.columns = [
|
||
|
{
|
||
|
cn: 'id',
|
||
|
dt: 'int',
|
||
|
dtx: 'integer',
|
||
|
ct: 'int(11)',
|
||
|
nrqd: false,
|
||
|
rqd: true,
|
||
|
ck: false,
|
||
|
pk: true,
|
||
|
un: true,
|
||
|
ai: true,
|
||
|
cdf: null,
|
||
|
clen: null,
|
||
|
np: 10,
|
||
|
ns: 0,
|
||
|
// dp: null,
|
||
|
// data_type_x_specific: '',
|
||
|
dtxp: '10',
|
||
|
dtxs: ''
|
||
|
},
|
||
|
{
|
||
|
cn: 'title',
|
||
|
dt: 'varchar',
|
||
|
dtx: 'specificType',
|
||
|
ct: 'varchar(45)',
|
||
|
nrqd: true,
|
||
|
rqd: false,
|
||
|
ck: false,
|
||
|
pk: false,
|
||
|
un: false,
|
||
|
ai: false,
|
||
|
cdf: null,
|
||
|
clen: 45,
|
||
|
np: null,
|
||
|
ns: null,
|
||
|
// dp: null
|
||
|
// data_type_x_specific: 'specificType',
|
||
|
dtxp: '45',
|
||
|
dtxs: ''
|
||
|
}
|
||
|
]
|
||
|
return
|
||
|
}
|
||
|
// 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
|
||
3 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
|
||
3 years ago
|
})
|
||
|
|
||
|
console.log('table ', result.data.list)
|
||
|
const columns = result.data.list
|
||
|
|
||
|
// const relationsResult = await client.relationList({
|
||
3 years ago
|
// tn: this.nodes.table_name
|
||
3 years ago
|
// });
|
||
|
|
||
|
const relationsResult = await this.sqlMgr.sqlOp({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
}, 'relationList', {
|
||
3 years ago
|
tn: this.nodes.table_name
|
||
3 years ago
|
})
|
||
|
|
||
|
const relations = relationsResult.data.list
|
||
|
console.log('relations: ', relations)
|
||
|
|
||
|
for (let i = 0; i < relations.length; i++) {
|
||
|
const relation = relations[i]
|
||
|
for (let i = 0; i < columns.length; i++) {
|
||
|
const column = columns[i]
|
||
|
|
||
3 years ago
|
if (column.column_name === relation.column_name) {
|
||
3 years ago
|
// column.rcn = relation.rcn;
|
||
|
// column.rtn = relation.rtn;
|
||
|
columns[i] = { ...column, ...relation }
|
||
4 years ago
|
}
|
||
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
this.columns = JSON.parse(JSON.stringify(columns))
|
||
|
this.originalColumns = [...columns]
|
||
|
console.log(this.columns)
|
||
|
},
|
||
3 years ago
|
async loadDataTypes() {
|
||
3 years ago
|
const client = await this.sqlMgr.projectGetSqlClient({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
})
|
||
|
const result = client.getKnexDataTypes()
|
||
|
this.dataTypes = result.data.list
|
||
|
},
|
||
3 years ago
|
saveColumnName(col) {
|
||
3 years ago
|
this.edited = true
|
||
|
col.altered = col.altered || 8
|
||
4 years ago
|
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
|
},
|
||
3 years ago
|
save(col) {
|
||
3 years ago
|
this.edited = true
|
||
|
col.altered = col.altered || 2
|
||
4 years ago
|
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
|
},
|
||
3 years ago
|
cancel() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'error'
|
||
|
this.snackText = 'Canceled'
|
||
|
},
|
||
3 years ago
|
open() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'info'
|
||
|
this.snackText = 'Dialog opened'
|
||
|
},
|
||
3 years ago
|
close() {
|
||
3 years ago
|
console.log('Dialog closed')
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
saveDefaultValue(col) {
|
||
3 years ago
|
this.edited = true
|
||
|
col.altered = col.altered || 2
|
||
|
// col.rqd = false;
|
||
4 years ago
|
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
savePrecision(col) {
|
||
3 years ago
|
console.log(col)
|
||
|
col.altered = col.altered || 2
|
||
|
this.edited = true
|
||
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
|
},
|
||
3 years ago
|
cancelPrecision() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'error'
|
||
|
this.snackText = 'Canceled'
|
||
|
},
|
||
3 years ago
|
openPrecision() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'info'
|
||
|
this.snackText = 'Dialog opened'
|
||
|
},
|
||
3 years ago
|
closePrecision() {
|
||
3 years ago
|
console.log('Dialog closed')
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
saveScale(col) {
|
||
3 years ago
|
if (col.dtx === 'float' || col.dtx === 'decimal' || col.dtx === 'specifcType') {
|
||
|
col.altered = col.altered || 2
|
||
|
this.edited = true
|
||
|
this.snack = true
|
||
|
this.snackColor = 'success'
|
||
|
this.snackText = 'Data saved'
|
||
|
}
|
||
|
},
|
||
3 years ago
|
cancelScale() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'error'
|
||
|
this.snackText = 'Canceled'
|
||
|
},
|
||
3 years ago
|
openScale() {
|
||
3 years ago
|
this.snack = true
|
||
|
this.snackColor = 'info'
|
||
|
this.snackText = 'Dialog opened'
|
||
|
},
|
||
3 years ago
|
closeScale() {
|
||
3 years ago
|
console.log('Dialog closed')
|
||
|
},
|
||
4 years ago
|
|
||
3 years ago
|
removeUnsigned(columns) {
|
||
3 years ago
|
for (let i = 0; i < columns.length; ++i) {
|
||
|
if (columns[i].altered === 1 && (!(columns[i].dt === 'int' || columns[i].dt === 'bigint'))) {
|
||
|
columns[i].un = false
|
||
3 years ago
|
console.log('>> resetting unsigned value', columns[i].column_name)
|
||
4 years ago
|
}
|
||
3 years ago
|
console.log(columns[i].column_name)
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
addColumn() {
|
||
3 years ago
|
this.edited = true
|
||
|
this.columns.push({
|
||
|
cn: 'title' + this.columns.length,
|
||
|
dt: 'int',
|
||
|
dtx: 'specificType',
|
||
|
ct: 'integer(10)',
|
||
|
nrqd: true,
|
||
|
rqd: false,
|
||
|
ck: false,
|
||
|
pk: false,
|
||
|
un: false,
|
||
|
ai: false,
|
||
|
cdf: null,
|
||
|
clen: 45,
|
||
|
np: null,
|
||
|
ns: null,
|
||
|
// data_type_x_specific: ' ',
|
||
|
dtxp: '10',
|
||
|
dtxs: ' ',
|
||
|
altered: 1
|
||
|
})
|
||
|
},
|
||
3 years ago
|
async deleteColumn(action = '', index, column) {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
|
this.columnDeleteDlg = true
|
||
|
this.selectedColForDelete = { index, column }
|
||
|
} else if (action === 'hideDialog') {
|
||
|
this.columnDeleteDlg = false
|
||
|
} else {
|
||
|
if (this.columns[this.selectedColForDelete.index].altered === 1) {
|
||
|
// newly added column no need to remove fromd db
|
||
|
this.columns.splice(this.selectedColForDelete.index, 1)
|
||
4 years ago
|
} else {
|
||
3 years ago
|
const columns = JSON.parse(JSON.stringify(this.columns))
|
||
|
columns[this.selectedColForDelete.index].altered = 4
|
||
|
await this.sqlMgr.sqlOpPlus(
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'tableUpdate',
|
||
4 years ago
|
{
|
||
3 years ago
|
tn: this.nodes.table_name,
|
||
4 years ago
|
originalColumns: this.originalColumns,
|
||
3 years ago
|
columns
|
||
|
}
|
||
|
)
|
||
|
this.columns.splice(this.selectedColForDelete.index, 1)
|
||
4 years ago
|
}
|
||
3 years ago
|
this.columnDeleteDlg = false
|
||
|
this.selectedColForDelete = null
|
||
|
}
|
||
|
},
|
||
3 years ago
|
async applyChanges() {
|
||
3 years ago
|
this.progress.save = true
|
||
|
await this.sqlMgr.projectGetSqlClient({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
})
|
||
|
if (this.newTable) {
|
||
|
this.removeUnsigned(this.columns)
|
||
|
// let result = await this.sqlMgr.sqlOpPlus(
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// },
|
||
|
// "tableCreate",
|
||
|
// {
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// columns: this.columns
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
}, 'tableCreate',
|
||
|
{
|
||
3 years ago
|
tn: this.nodes.table_name,
|
||
3 years ago
|
columns: this.columns
|
||
|
}])
|
||
|
// const result = await client.tableCreate({
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// columns: this.columns
|
||
|
// });
|
||
|
this.mtdNewTableUpdate(false)
|
||
|
// console.log("result", result, this.nodes);
|
||
|
await this.loadTablesFromChildTreeNode({
|
||
|
_nodes: {
|
||
|
...this.nodes
|
||
|
}
|
||
|
})
|
||
|
} else {
|
||
|
console.log('this.columns[index].altered before', this.columns)
|
||
|
// const result = await client.tableUpdate({
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// originalColumns: this.originalColumns,
|
||
|
// columns: this.columns
|
||
|
// });
|
||
|
this.removeUnsigned(this.columns)
|
||
|
// let result = await this.sqlMgr.sqlOpPlus(
|
||
|
// {
|
||
|
// env: this.nodes.env,
|
||
|
// dbAlias: this.nodes.dbAlias
|
||
|
// },
|
||
|
// "tableUpdate",
|
||
|
// {
|
||
3 years ago
|
// tn: this.nodes.table_name,
|
||
3 years ago
|
// originalColumns: this.originalColumns,
|
||
|
// columns: this.columns
|
||
|
// }
|
||
|
// );
|
||
|
|
||
|
const result = await this.$store.dispatch('sqlMgr/ActSqlOpPlus', [
|
||
|
{
|
||
4 years ago
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
3 years ago
|
},
|
||
|
'tableUpdate',
|
||
|
{
|
||
3 years ago
|
tn: this.nodes.table_name,
|
||
3 years ago
|
originalColumns: this.originalColumns,
|
||
|
columns: this.columns
|
||
|
}])
|
||
|
console.log('update table result', result)
|
||
|
}
|
||
|
this.progress.save = false
|
||
|
await this.loadColumnList()
|
||
|
},
|
||
3 years ago
|
createNewOrEditRelation(column) {
|
||
3 years ago
|
console.log(column)
|
||
|
this.selectedColForNewRelation = { ...column }
|
||
|
this.dialogShow = true
|
||
|
},
|
||
3 years ago
|
async mtdNewRelationDlgSubmit(relationObject) {
|
||
3 years ago
|
try {
|
||
|
await this.sqlMgr.projectGetSqlClient({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
})
|
||
4 years ago
|
|
||
3 years ago
|
if (relationObject.updateRelation) {
|
||
|
// update existing relation
|
||
|
alert('Not Implemented yet')
|
||
4 years ago
|
} else {
|
||
3 years ago
|
// const result = await client.relationCreate(relationObject);
|
||
|
|
||
|
const result = await this.sqlMgr.sqlOpPlus(
|
||
4 years ago
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
3 years ago
|
'relationCreate',
|
||
|
relationObject
|
||
|
)
|
||
|
console.log('relationCreate result: ', result)
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
await this.loadColumnList()
|
||
|
this.selectedColForNewRelation = null
|
||
|
this.dialogShow = false
|
||
|
} catch (error) {
|
||
|
console.error('relationCreate error: ', error)
|
||
|
}
|
||
4 years ago
|
},
|
||
3 years ago
|
mtdNewRelationDlgCancel() {
|
||
3 years ago
|
this.dialogShow = false
|
||
|
this.selectedColNameForNewRelation = ''
|
||
4 years ago
|
},
|
||
3 years ago
|
async deleteRelation(action = '', column) {
|
||
3 years ago
|
if (action === 'showDialog') {
|
||
|
this.relationDeleteDlg = true
|
||
|
this.selectedColForRelationDelete = column
|
||
|
} else if (action === 'hideDialog') {
|
||
|
this.relationDeleteDlg = false
|
||
|
this.selectedColForRelationDelete = null
|
||
|
} else {
|
||
|
await this.sqlMgr.projectGetSqlClient({
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
})
|
||
|
|
||
|
// const result = await client.relationDelete({
|
||
3 years ago
|
// childColumn: column.column_name,
|
||
|
// childTable: this.nodes.table_name,
|
||
3 years ago
|
// parentTable: column.rtn,
|
||
|
// parentColumn: column.rcn,
|
||
|
// foreignKeyName: column.cstn
|
||
|
// });
|
||
|
const result = await this.sqlMgr.sqlOpPlus(
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias
|
||
|
},
|
||
|
'relationDelete',
|
||
|
{
|
||
3 years ago
|
childColumn: this.selectedColForRelationDelete.column_name,
|
||
|
childTable: this.nodes.table_name,
|
||
3 years ago
|
parentTable: this.selectedColForRelationDelete
|
||
|
.rtn,
|
||
|
parentColumn: this.selectedColForRelationDelete
|
||
|
.rcn,
|
||
|
foreignKeyName: this.selectedColForRelationDelete.cstn
|
||
|
}
|
||
|
)
|
||
|
console.log('relationDelete result ', result)
|
||
|
await this.loadColumnList()
|
||
|
this.relationDeleteDlg = false
|
||
|
this.selectedColForRelationDelete = null
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
computed: { ...mapGetters({ sqlMgr: 'sqlMgr/sqlMgr' }) },
|
||
|
|
||
3 years ago
|
beforeCreated() {
|
||
3 years ago
|
},
|
||
|
watch: {},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadColumnList()
|
||
|
this.loadDataTypes()
|
||
|
},
|
||
3 years ago
|
mounted() {
|
||
3 years ago
|
},
|
||
3 years ago
|
beforeDestroy() {
|
||
3 years ago
|
},
|
||
3 years ago
|
destroy() {
|
||
3 years ago
|
},
|
||
|
directives: {},
|
||
3 years ago
|
validate({ params }) {
|
||
3 years ago
|
return true
|
||
|
},
|
||
3 years ago
|
head() {
|
||
3 years ago
|
return {}
|
||
|
},
|
||
|
props: ['nodes', 'newTable', 'mtdNewTableUpdate', 'deleteTable']
|
||
|
}
|
||
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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|