Browse Source

wip: edit column logic

pull/1931/head
Wing-Kam Wong 3 years ago
parent
commit
c0220b9de6
  1. 39
      packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue

39
packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue

@ -13,8 +13,8 @@
</template> </template>
<script> <script>
import { SqlUiFactory } from 'nocodb-sdk'
import colors from '~/mixins/colors' import colors from '~/mixins/colors'
import { SqlUiFactory } from 'nocodb-sdk';
export default { export default {
name: 'CreateProjectFromTemplateBtn', name: 'CreateProjectFromTemplateBtn',
@ -44,6 +44,7 @@ export default {
}, },
data() { data() {
return { return {
localTemplateData: null,
projectCreation: false, projectCreation: false,
tableCreation: false, tableCreation: false,
loaderMessagesIndex: 0, loaderMessagesIndex: 0,
@ -71,6 +72,18 @@ export default {
] ]
} }
}, },
watch: {
templateData: {
deep: true,
handler(data) {
this.localTemplateData = JSON.parse(JSON.stringify(data))
}
}
},
created() {
this.localTemplateData = JSON.parse(JSON.stringify(this.templateData))
},
methods: { methods: {
async useTemplate(projectType) { async useTemplate(projectType) {
if (!this.valid) { if (!this.valid) {
@ -78,7 +91,6 @@ export default {
} }
// this.$emit('useTemplate', type) // this.$emit('useTemplate', type)
// this.projectCreation = true // this.projectCreation = true
let interv let interv
try { try {
@ -140,15 +152,15 @@ export default {
// Create tables // Create tables
try { try {
for (var t of this.templateData.tables) { for (const t of this.localTemplateData.tables) {
// enrich system fields if not provided // enrich system fields if not provided
// e.g. id, created_at, updated_at // e.g. id, created_at, updated_at
const systemColumns = SqlUiFactory const systemColumns = SqlUiFactory
.create({client: 'sqlite3'}) .create({ client: 'sqlite3' })
.getNewTableColumns() .getNewTableColumns()
.filter(c => c.column_name != "title") .filter(c => c.column_name != 'title')
// mark updated column_name // mark updated column_name
t.columns.map(c => { t.columns.map((c) => {
if (c.cn) { if (c.cn) {
c.column_name = c.cn c.column_name = c.cn
c.ref_column_name = c.column_name c.ref_column_name = c.column_name
@ -158,11 +170,9 @@ export default {
const table = await this.$api.dbTable.create(project.id, { const table = await this.$api.dbTable.create(project.id, {
table_name: t.ref_table_name, table_name: t.ref_table_name,
title: '', title: '',
columns: [...t.columns, ...systemColumns], columns: [...t.columns, ...systemColumns]
}); })
console.log(table)
t.table_title = table.title t.table_title = table.title
console.log(t)
} }
this.tableCreation = true this.tableCreation = true
} catch (e) { } catch (e) {
@ -197,10 +207,7 @@ export default {
async importDataToProject(projectName, prefix) { async importDataToProject(projectName, prefix) {
let total = 0 let total = 0
let progress = 0 let progress = 0
console.log("projectName = " + projectName) await Promise.all(this.localTemplateData.tables.map(v => (async(tableMeta) => {
console.log(this.templateData.tables)
await Promise.all(this.templateData.tables.map(v => (async(tableMeta) => {
console.log(tableMeta)
const tableName = tableMeta.table_title const tableName = tableMeta.table_title
const data = this.importData[tableMeta.ref_table_name] const data = this.importData[tableMeta.ref_table_name]
total += data.length total += data.length
@ -233,4 +240,4 @@ export default {
<style scoped> <style scoped>
</style> </style>
Loading…
Cancel
Save