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.
226 lines
6.3 KiB
226 lines
6.3 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
|
||
3 years ago
|
:rules="[validateTableName, validateDuplicateAlias]"
|
||
3 years ago
|
:hint="$t('msg.info.enterTableName')"
|
||
3 years ago
|
class="mt-4 caption nc-table-name"
|
||
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<!--hint="Table name as saved in database"-->
|
||
3 years ago
|
<v-text-field
|
||
|
v-if="!projectPrefix"
|
||
|
v-model="table.name"
|
||
|
solo
|
||
|
flat
|
||
|
dense
|
||
|
persistent-hint
|
||
3 years ago
|
:rules="[validateDuplicate]"
|
||
3 years ago
|
:hint="$t('msg.info.tableNameInDb')"
|
||
3 years ago
|
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">
|
||
|
<v-checkbox
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
|
class="mt-0 "
|
||
|
color="info"
|
||
|
hide-details
|
||
|
value="id"
|
||
|
@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');
|
||
|
}
|
||
|
}"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">id</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
|
class="mt-0 "
|
||
|
color="info"
|
||
|
hide-details
|
||
|
value="title"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">title</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
|
class="mt-0 "
|
||
|
color="info"
|
||
|
hide-details
|
||
|
value="created_at"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">created_at</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
<v-checkbox
|
||
|
v-model="table.columns"
|
||
|
dense
|
||
|
class="mt-0 "
|
||
|
color="info"
|
||
|
hide-details
|
||
|
value="updated_at"
|
||
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">updated_at</span>
|
||
|
</template>
|
||
|
</v-checkbox>
|
||
|
</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"
|
||
|
@click="$emit('create',table)"
|
||
|
>
|
||
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 inflection from 'inflection'
|
||
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 {
|
||
|
table: {
|
||
|
name: '',
|
||
|
columns: ['id',
|
||
|
'title',
|
||
|
'created_at',
|
||
|
'updated_at']
|
||
3 years ago
|
},
|
||
3 years ago
|
valid: false
|
||
3 years ago
|
}
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
|
dialogShow: {
|
||
3 years ago
|
get() {
|
||
4 years ago
|
return this.value
|
||
3 years ago
|
},
|
||
3 years ago
|
set(v) {
|
||
4 years ago
|
this.$emit('input', v)
|
||
|
}
|
||
|
},
|
||
3 years ago
|
projectPrefix() {
|
||
4 years ago
|
return this.$store.getters['project/GtrProjectPrefix']
|
||
|
}
|
||
3 years ago
|
},
|
||
|
watch: {
|
||
3 years ago
|
'table.alias'(v) {
|
||
4 years ago
|
this.$set(this.table, 'name', `${this.projectPrefix || ''}${inflection.underscore(v)}`)
|
||
|
}
|
||
|
},
|
||
3 years ago
|
mounted() {
|
||
4 years ago
|
setTimeout(() => {
|
||
3 years ago
|
this.$refs.input.$el.querySelector('input').focus()
|
||
4 years ago
|
}, 100)
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
|
validateTableName(v) {
|
||
|
return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql'])
|
||
|
},
|
||
|
validateDuplicateAlias(v) {
|
||
|
return (this.$store.state.project.tables || []).every(t => t.title !== (v || '')) || 'Duplicate table alias'
|
||
|
},
|
||
|
validateDuplicate(v) {
|
||
|
return (this.$store.state.project.tables || []).every(t => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
|
||
|
}
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
|
::v-deep{
|
||
|
.v-text-field__details {
|
||
|
padding:0 2px !important;
|
||
3 years ago
|
.v-messages:not(.error--text) {
|
||
|
.v-messages__message {
|
||
|
color: grey;
|
||
|
font-size: .65rem;
|
||
|
}
|
||
4 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
.add-default-title{
|
||
|
font-size: .65rem;
|
||
|
}
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|