Browse Source

fix: allow different boolean values for checkbox type

Signed-off-by: Wing-Kam Wong <wingkwong.code@gmail.com>
pull/1148/head
Wing-Kam Wong 3 years ago
parent
commit
4404232d4d
  1. 22
      packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue
  2. 15
      packages/nc-gui/components/project/spreadsheet/components/moreActions.vue

22
packages/nc-gui/components/project/spreadsheet/components/importExport/columnMappingModal.vue

@ -158,8 +158,28 @@ export default {
return 'Source data contains some invalid numbers' return 'Source data contains some invalid numbers'
} }
break break
case UITypes.Checkbox:
if (
this.parsedCsv && this.parsedCsv.data && this.parsedCsv.data.slice(0, 500)
.some((r) => {
if (r => r[row.sourceCn] !== null && r[row.sourceCn] !== undefined) {
var input = r[row.sourceCn]
if (typeof input === 'string') {
input = input.replace(/["']/g, "").toLowerCase().trim()
return (
input == "false" || input == "no" || input == "n" || input == "0" ||
input == "true" || input == "yes" || input == "y" || input == "1"
) ? false : true
}
return input != 1 && input != 0 && input != true && input != false
}
return false
})
) {
return 'Source data contains some invalid boolean values'
}
break
} }
return true return true
}, },
mapDefaultColumns() { mapDefaultColumns() {

15
packages/nc-gui/components/project/spreadsheet/components/moreActions.vue

@ -106,6 +106,7 @@ import FileSaver from 'file-saver'
import DropOrSelectFileModal from '~/components/import/dropOrSelectFileModal' import DropOrSelectFileModal from '~/components/import/dropOrSelectFileModal'
import ColumnMappingModal from '~/components/project/spreadsheet/components/importExport/columnMappingModal' import ColumnMappingModal from '~/components/project/spreadsheet/components/importExport/columnMappingModal'
import CSVTemplateAdapter from '~/components/import/templateParsers/CSVTemplateAdapter' import CSVTemplateAdapter from '~/components/import/templateParsers/CSVTemplateAdapter'
import { UITypes } from '~/components/project/spreadsheet/helpers/uiTypes'
export default { export default {
name: 'ExportImport', name: 'ExportImport',
@ -276,9 +277,19 @@ export default {
for (let i = 0, progress = 0; i < data.length; i += 500) { for (let i = 0, progress = 0; i < data.length; i += 500) {
const batchData = data.slice(i, i + 500).map(row => columnMappings.reduce((res, col) => { const batchData = data.slice(i, i + 500).map(row => columnMappings.reduce((res, col) => {
// todo: parse data // todo: parse data
if (col.enabled && col.destCn) { if (col.enabled && col.destCn) {
res[col.destCn] = row[col.sourceCn] const v = this.meta && this.meta.columns.find(c => c._cn === col.destCn)
var input = row[col.sourceCn]
// parse potential boolean values
if (v.uidt == UITypes.Checkbox) {
input = input.replace(/["']/g, "").toLowerCase().trim()
if (input == "false" || input == "no" || input == "n") {
input = "0"
} else if (input == "true" || input == "yes" || input == "y") {
input = "1"
}
}
res[col.destCn] = input
} }
return res return res
}, {})) }, {}))

Loading…
Cancel
Save