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.
305 lines
9.1 KiB
305 lines
9.1 KiB
4 years ago
|
<template>
|
||
|
<v-dialog
|
||
3 years ago
|
v-model="dialogShow"
|
||
4 years ago
|
persistent
|
||
3 years ago
|
max-width="550"
|
||
4 years ago
|
@keydown.esc="dialogShow = false"
|
||
|
@keydown.enter="$emit('create', table)"
|
||
|
>
|
||
3 years ago
|
<!-- Create A New Table -->
|
||
3 years ago
|
<v-card class="elevation-1 backgroundColor nc-create-table-card">
|
||
3 years ago
|
<v-form ref="form" v-model="valid">
|
||
|
<v-card-title class="primary subheading white--text py-2">
|
||
3 years ago
|
{{ $t('activity.createTable') }}
|
||
3 years ago
|
</v-card-title>
|
||
4 years ago
|
|
||
3 years ago
|
<v-card-text class="py-6 px-10">
|
||
3 years ago
|
<!--hint="Enter table name"-->
|
||
3 years ago
|
<v-text-field
|
||
|
ref="input"
|
||
|
v-model="table.alias"
|
||
|
solo
|
||
|
flat
|
||
|
persistent-hint
|
||
|
dense
|
||
|
hide-details1
|
||
2 years ago
|
:rules="[validateTableName, validateDuplicateAlias, validateLength]"
|
||
3 years ago
|
:hint="$t('msg.info.enterTableName')"
|
||
3 years ago
|
class="mt-4 caption nc-table-name"
|
||
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<div class="d-flex justify-end">
|
||
|
<div class="grey--text caption pointer" @click="isAdvanceOptVisible = !isAdvanceOptVisible">
|
||
3 years ago
|
{{ isAdvanceOptVisible ? 'Hide' : 'Show' }} more
|
||
3 years ago
|
<v-icon x-small color="grey">
|
||
3 years ago
|
{{ isAdvanceOptVisible ? 'mdi-minus-circle-outline' : 'mdi-plus-circle-outline' }}
|
||
3 years ago
|
</v-icon>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
3 years ago
|
<div class="nc-table-advanced-options" :class="{ active: isAdvanceOptVisible }">
|
||
3 years ago
|
<!--hint="Table name as saved in database"-->
|
||
|
<v-text-field
|
||
|
v-if="!projectPrefix"
|
||
|
v-model="table.name"
|
||
|
solo
|
||
|
flat
|
||
|
dense
|
||
|
persistent-hint
|
||
|
:rules="[validateDuplicate]"
|
||
|
:hint="$t('msg.info.tableNameInDb')"
|
||
|
class="mt-4 caption nc-table-name-alias"
|
||
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<div class="mt-5">
|
||
3 years ago
|
<label class="add-default-title grey--text">
|
||
|
<!--Add Default Columns-->
|
||
|
{{ $t('msg.info.addDefaultColumns') }}
|
||
|
</label>
|
||
4 years ago
|
|
||
3 years ago
|
<div class="d-flex caption justify-space-between align-center">
|
||
3 years ago
|
<v-checkbox
|
||
|
key="chk1"
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
3 years ago
|
class="mt-0"
|
||
3 years ago
|
color="info"
|
||
|
hide-details
|
||
|
value="id"
|
||
3 years ago
|
@click.capture.prevent.stop="
|
||
|
() => {
|
||
|
$toast.info('ID column is required, you can rename this later if required.').goAway(3000);
|
||
|
if (!table.columns.includes('id')) {
|
||
|
table.columns.push('id');
|
||
|
}
|
||
3 years ago
|
}
|
||
3 years ago
|
"
|
||
3 years ago
|
>
|
||
|
<template #label>
|
||
|
<div>
|
||
3 years ago
|
<span v-if="!isIdToggleAllowed" class="caption" @dblclick="isIdToggleAllowed = true">id</span>
|
||
3 years ago
|
<v-select
|
||
|
v-else
|
||
|
v-model="idType"
|
||
3 years ago
|
style="max-width: 100px"
|
||
3 years ago
|
class="caption"
|
||
|
outlined
|
||
|
dense
|
||
|
hide-details
|
||
|
:items="idTypes"
|
||
|
/>
|
||
|
</div>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
key="chk2"
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
3 years ago
|
class="mt-0"
|
||
3 years ago
|
color="info"
|
||
|
hide-details
|
||
|
value="title"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">title</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
key="chk3"
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
3 years ago
|
class="mt-0"
|
||
3 years ago
|
color="info"
|
||
|
hide-details
|
||
|
value="created_at"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">created_at</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
key="chk4"
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
3 years ago
|
class="mt-0"
|
||
3 years ago
|
color="info"
|
||
|
hide-details
|
||
|
value="updated_at"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">updated_at</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
</div>
|
||
3 years ago
|
</div>
|
||
4 years ago
|
</div>
|
||
3 years ago
|
</v-card-text>
|
||
|
<v-divider />
|
||
4 years ago
|
|
||
3 years ago
|
<v-card-actions class="py-4 px-10">
|
||
|
<v-spacer />
|
||
|
<v-btn class="" @click="dialogShow = false">
|
||
3 years ago
|
{{ $t('general.cancel') }}
|
||
3 years ago
|
</v-btn>
|
||
|
<v-btn
|
||
|
:disabled="!(table.name && table.name.length) || !(table.alias && table.alias.length) || !valid"
|
||
|
color="primary"
|
||
|
class="nc-create-table-submit"
|
||
3 years ago
|
@click="onCreateBtnClick"
|
||
3 years ago
|
>
|
||
3 years ago
|
{{ $t('general.submit') }}
|
||
3 years ago
|
</v-btn>
|
||
|
</v-card-actions>
|
||
|
</v-form>
|
||
4 years ago
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { validateTableName } from '~/helpers';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'DlgTableCreate',
|
||
|
props: ['value'],
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
3 years ago
|
isAdvanceOptVisible: false,
|
||
4 years ago
|
table: {
|
||
|
name: '',
|
||
3 years ago
|
columns: ['id', 'title', 'created_at', 'updated_at'],
|
||
3 years ago
|
},
|
||
3 years ago
|
isIdToggleAllowed: false,
|
||
|
valid: false,
|
||
|
idType: 'AI',
|
||
3 years ago
|
idTypes: [
|
||
|
{ value: 'AI', text: 'Auto increment number' },
|
||
|
{ value: 'AG', text: 'Auto generated string' },
|
||
|
],
|
||
|
};
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
|
dialogShow: {
|
||
3 years ago
|
get() {
|
||
3 years ago
|
return this.value;
|
||
3 years ago
|
},
|
||
3 years ago
|
set(v) {
|
||
3 years ago
|
this.$emit('input', v);
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
projectPrefix() {
|
||
3 years ago
|
return this.$store.getters['project/GtrProjectPrefix'];
|
||
3 years ago
|
},
|
||
|
tables() {
|
||
3 years ago
|
return this.$store.state.project.tables || [];
|
||
|
},
|
||
3 years ago
|
},
|
||
|
watch: {
|
||
3 years ago
|
'table.alias'(alias) {
|
||
3 years ago
|
this.$set(this.table, 'name', `${this.projectPrefix || ''}${alias}`);
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
created() {
|
||
3 years ago
|
this.populateDefaultTitle();
|
||
3 years ago
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
setTimeout(() => {
|
||
3 years ago
|
const el = this.$refs.input.$el;
|
||
|
el.querySelector('input').focus();
|
||
|
el.querySelector('input').select();
|
||
|
}, 100);
|
||
3 years ago
|
},
|
||
3 years ago
|
|
||
3 years ago
|
methods: {
|
||
3 years ago
|
populateDefaultTitle() {
|
||
3 years ago
|
let c = 1;
|
||
|
while (this.tables.some(t => t.title === `Sheet${c}`)) {
|
||
|
c++;
|
||
|
}
|
||
|
this.$set(this.table, 'alias', `Sheet${c}`);
|
||
3 years ago
|
},
|
||
3 years ago
|
validateTableName(v) {
|
||
3 years ago
|
return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql']);
|
||
3 years ago
|
},
|
||
|
validateDuplicateAlias(v) {
|
||
3 years ago
|
return (this.tables || []).every(t => t.title !== (v || '')) || 'Duplicate table alias';
|
||
3 years ago
|
},
|
||
3 years ago
|
validateLedingOrTrailingWhiteSpace(v) {
|
||
3 years ago
|
return !/^\s+|\s+$/.test(v) || 'Leading or trailing whitespace not allowed in table name';
|
||
3 years ago
|
},
|
||
3 years ago
|
validateDuplicate(v) {
|
||
3 years ago
|
return (
|
||
|
(this.tables || []).every(t => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
|
||
|
);
|
||
3 years ago
|
},
|
||
2 years ago
|
validateLength(v) {
|
||
|
let tableNameLengthLimit = 255;
|
||
|
const sqlClientType = this.$store.getters['project/GtrClientType'];
|
||
|
if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') {
|
||
|
tableNameLengthLimit = 64;
|
||
|
} else if (sqlClientType === 'pg') {
|
||
|
tableNameLengthLimit = 63;
|
||
|
} else if (sqlClientType === 'mssql') {
|
||
|
tableNameLengthLimit = 128;
|
||
|
}
|
||
|
return v.length <= tableNameLengthLimit || `Table name exceeds ${tableNameLengthLimit} characters`;
|
||
|
},
|
||
3 years ago
|
onCreateBtnClick() {
|
||
|
this.$emit('create', {
|
||
|
...this.table,
|
||
3 years ago
|
columns: this.table.columns.map(c => (c === 'id' && this.idType === 'AG' ? 'id_ag' : c)),
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
3 years ago
|
::v-deep {
|
||
4 years ago
|
.v-text-field__details {
|
||
3 years ago
|
padding: 0 2px !important;
|
||
3 years ago
|
.v-messages:not(.error--text) {
|
||
|
.v-messages__message {
|
||
|
color: grey;
|
||
3 years ago
|
font-size: 0.65rem;
|
||
3 years ago
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
3 years ago
|
.add-default-title {
|
||
|
font-size: 0.65rem;
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
.nc-table-advanced-options {
|
||
|
max-height: 0;
|
||
|
transition: 0.3s max-height;
|
||
3 years ago
|
overflow: hidden;
|
||
3 years ago
|
&.active {
|
||
|
max-height: 200px;
|
||
3 years ago
|
}
|
||
|
}
|
||
4 years ago
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|