Browse Source

code scanner for forms - WIP

pull/5114/head
Daniel Spaude 2 years ago
parent
commit
b8299475a5
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 2
      packages/nc-gui/components/smartsheet/Form.vue
  2. 23
      packages/nc-gui/pages/[projectType]/form/[viewId]/index/index.vue

2
packages/nc-gui/components/smartsheet/Form.vue

@ -361,7 +361,7 @@ function handleMouseUp(col: Record<string, any>, hiddenColIndex: number) {
}
}
const columnSupportsScanning = (elementType: UITypes) => [UITypes.SingleLineText, UITypes.Number].includes(elementType)
const columnSupportsScanning = (elementType: UITypes) => [UITypes.SingleLineText].includes(elementType)
onClickOutside(draggableRef, () => {
activeRow.value = ''

23
packages/nc-gui/pages/[projectType]/form/[viewId]/index/index.vue

@ -1,4 +1,5 @@
<script lang="ts" setup>
import type { ColumnType } from 'nocodb-sdk'
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
import { ref } from 'vue'
import { StreamBarcodeReader } from 'vue-barcode-reader'
@ -35,13 +36,27 @@ const showCodeScannerForFieldTitle = (fieldTitle: string) => {
fieldTitleForCurrentScan.value = fieldTitle
}
const onDecode = async (codeValue: string) => {
const getScannedValueTransformerByFieldType = (fieldType: UITypes) => {
switch (fieldType) {
case UITypes.Number:
return (originalVal: string) => parseInt(originalVal)
default:
return (originalVal: string) => originalVal
}
}
const onDecode = async (scannedCodeValue: string) => {
if (!showCodeScannerOverlay.value) {
return
}
// TODO: remove try catch
try {
formState.value[fieldTitleForCurrentScan.value] = codeValue
const fieldForCurrentScan = formColumns.value?.find((el: ColumnType) => el.title === fieldTitleForCurrentScan.value)
if (fieldForCurrentScan == null) {
throw new Error(`Field with title ${fieldTitleForCurrentScan.value} not found`)
}
const transformedVal =
getScannedValueTransformerByFieldType(fieldForCurrentScan.uidt as UITypes)(scannedCodeValue) || scannedCodeValue
formState.value[fieldTitleForCurrentScan.value] = transformedVal
fieldTitleForCurrentScan.value = ''
showCodeScannerOverlay.value = false
} catch (error) {
@ -98,7 +113,7 @@ const onDecode = async (codeValue: string) => {
>
<div class="relative flex flex-col h-full">
<StreamBarcodeReader v-show="scannerIsReady" @decode="onDecode" @loaded="onLoaded"> </StreamBarcodeReader>
<a-button @click="() => onDecode('ABC')">Simulate scan</a-button>
<a-button @click="() => onDecode('1234')">Simulate scan</a-button>
</div>
</a-modal>
<GeneralOverlay class="bg-gray-400/75" :model-value="isLoading" inline transition>

Loading…
Cancel
Save