@@ -21,7 +29,7 @@
{{ showMore ? 'Hide' : 'Show' }} more
- mdi-menu-{{ showMore ? 'up':'down' }}
+ mdi-menu-{{ showMore ? 'up' : 'down' }}
@@ -124,15 +132,24 @@
Create template from Excel
-
+
-
-
+
+
+
+ Import Excel as Project : {{ filename }}
+
+
+ :valid="valid"
+ create-gql-text="Import as GQL Project"
+ create-rest-text="Import as REST Project"
+ >
+ Import Excel
+
@@ -150,13 +167,14 @@ import ExcelTemplateAdapter from '~/components/import/templateParsers/ExcelTempl
export default {
name: 'ExcelImport',
- components: { CreateProjectFromTemplateBtn, TemplateEditor },
+ components: {CreateProjectFromTemplateBtn, TemplateEditor},
props: {
hideLabel: Boolean,
value: Boolean
},
data() {
return {
+ templateEditorModal:false,
valid: null,
templateData: null,
importData: null,
@@ -165,7 +183,8 @@ export default {
showMore: false,
parserConfig: {
maxRowsToParse: 500
- }
+ },
+ filename: ''
}
},
computed: {
@@ -187,10 +206,11 @@ export default {
this.$refs.file.click()
},
- _change(file) {
- const files = file.target.files
+ _change(event) {
+ const files = event.target.files
if (files && files[0]) {
this._file(files[0])
+ event.target.value = ''
}
},
async _file(file) {
@@ -199,11 +219,10 @@ export default {
const int = setInterval(() => {
this.$store.commit('loader/MutMessage', `Loading excel file${'.'.repeat(++i % 4)}`)
}, 1000)
-
this.dropOrUpload = false
const reader = new FileReader()
-
- reader.onload = async(e) => {
+ this.filename = file.name
+ reader.onload = async (e) => {
const ab = e.target.result
await this.parseAndExtractData('file', ab, file.name)
this.$store.commit('loader/MutMessage', null)
@@ -216,7 +235,8 @@ export default {
}
reader.addEventListener('progress', handleEvent)
- reader.onerror = () => {
+ reader.onerror = (e) => {
+ console.log('error', e)
this.$store.commit('loader/MutClear')
}
reader.readAsArrayBuffer(file)
@@ -236,9 +256,11 @@ export default {
templateGenerator.parse()
this.templateData = templateGenerator.getTemplate()
this.importData = templateGenerator.getData()
+ this.templateEditorModal = true;
},
dropHandler(ev) {
+ this.dragOver = false;
console.log('File(s) dropped')
let file
if (ev.dataTransfer.items) {
@@ -250,12 +272,12 @@ export default {
file = ev.dataTransfer.files[0]
}
- if (file.type !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' && file.type !== 'application/vnd.ms-excel') {
- return this.$toast.error('Dropped file is not an accepted file type. The accepted file types are .xlsx,.xls!').goAway(3000)
- }
- if (file) {
- this._file(file)
+ if (!file) return
+
+ if (!/\.xls[xm]?$/.test(file.name)) {
+ return this.$toast.error('Dropped file is not an accepted file type. The accepted file types are .xlsx,.xls,.xlsm!').goAway(3000)
}
+ this._file(file)
},
dragOverHandler(ev) {
console.log('File(s) in drop zone')
@@ -303,8 +325,8 @@ export default {
width: 100%;
}
-.nc-excel-import-options{
- transition:.4s max-height;
+.nc-excel-import-options {
+ transition: .4s max-height;
overflow: hidden;
}
diff --git a/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js b/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js
index f95ab9f37d..b03d8628af 100644
--- a/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js
+++ b/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js
@@ -105,12 +105,12 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
}
}
} else if (column.uidt === UITypes.Number) {
- if (rows.slice(1, 500).some((v) => {
+ if (rows.slice(1, this.config.maxRowsToParse).some((v) => {
return v && v[col] && parseInt(+v[col]) !== +v[col]
})) {
column.uidt = UITypes.Decimal
}
- if (rows.slice(1, 500).every((v, i) => {
+ if (rows.slice(1, this.config.maxRowsToParse).every((v, i) => {
const cellId = XLSX.utils.encode_cell({
c: range.s.c + col,
r: i + 2
@@ -123,7 +123,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
column.uidt = UITypes.Currency
}
} else if (column.uidt === UITypes.DateTime) {
- if (rows.slice(1, 500).every((v, i) => {
+ if (rows.slice(1, this.config.maxRowsToParse).every((v, i) => {
const cellId = XLSX.utils.encode_cell({
c: range.s.c + col,
r: i + 2
diff --git a/packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue b/packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue
index 427ee9092a..544b454974 100644
--- a/packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue
+++ b/packages/nc-gui/components/templates/createProjectFromTemplateBtn.vue
@@ -9,7 +9,7 @@
x-large
v-on="on"
>
- Use template
+ Use template
mdi-menu-down
@@ -19,7 +19,7 @@
mdi-code-json
- Create REST Project
+ {{ createRestText }}
@@ -27,7 +27,7 @@
mdi-graphql
- Create GQL Project
+ {{ createGqlText }}
@@ -44,7 +44,23 @@ export default {
props: {
loading: Boolean,
templateData: [Array, Object],
- importData: [Array, Object]
+ importData: [Array, Object],
+ valid: {
+ default: true,
+ type: Boolean
+ },
+ validationErrorMsg: {
+ default: 'Please fill all the required values',
+ type: String
+ },
+ createGqlText: {
+ default: 'Create GQL Project',
+ type: String
+ },
+ createRestText: {
+ default: 'Create REST Project',
+ type: String
+ }
},
data() {
return {
@@ -76,6 +92,10 @@ export default {
},
methods: {
async useTemplate(projectType) {
+ if (!this.valid) {
+ return this.$toast.error(this.validationErrorMsg).goAway(3000)
+ }
+
// this.$emit('useTemplate', type)
this.projectCreation = true
@@ -118,7 +138,8 @@ export default {
// this.$store.commit('project/MutProjectId', projectId)
this.$ncApis.setProjectId(projectId)
- let total = 0; let progress = 0
+ let total = 0
+ let progress = 0
await Promise.all(Object.entries(this.importData).map(v => (async([table, data]) => {
await this.$store.dispatch('meta/ActLoadMeta', {
diff --git a/packages/nc-gui/components/templates/editor.vue b/packages/nc-gui/components/templates/editor.vue
index b199c36d14..3beee6a9a6 100644
--- a/packages/nc-gui/components/templates/editor.vue
+++ b/packages/nc-gui/components/templates/editor.vue
@@ -1,7 +1,7 @@
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -571,7 +577,8 @@ export default {
props: {
id: [Number, String],
viewMode: Boolean,
- projectTemplate: Object
+ projectTemplate: Object,
+ excelImport: Boolean
},
data: () => ({
loading: false,
@@ -1277,14 +1284,16 @@ export default {
if (oldVal === UITypes.LinkToAnotherRecord) {
rTable = this.project.tables.find(t => t.tn === col.rtn)
- if (col.type === 'hm') {
- index = rTable.columns.findIndex(c => c.uidt === UITypes.ForeignKey && c.rtn === table.tn)
- } else if (col.type === 'mm') {
- index = rTable.columns.findIndex(c => c.uidt === UITypes.LinkToAnotherRecord && c.rtn === table.tn && c.type === 'mm')
+ if (rTable) {
+ if (col.type === 'hm') {
+ index = rTable.columns.findIndex(c => c.uidt === UITypes.ForeignKey && c.rtn === table.tn)
+ } else if (col.type === 'mm') {
+ index = rTable.columns.findIndex(c => c.uidt === UITypes.LinkToAnotherRecord && c.rtn === table.tn && c.type === 'mm')
+ }
}
} else if (oldVal === UITypes.ForeignKey) {
rTable = this.project.tables.find(t => t.tn === col.rtn)
- index = rTable.columns.findIndex(c => c.uidt === UITypes.LinkToAnotherRecord && c.rtn === table.tn && c.type === 'hm')
+ if (rTable) { index = rTable.columns.findIndex(c => c.uidt === UITypes.LinkToAnotherRecord && c.rtn === table.tn && c.type === 'hm') }
}
if (rTable && index > -1) {
rTable.columns.splice(index, 1)
@@ -1303,4 +1312,7 @@ export default {