Browse Source

code scanner for forms - WIP (only show scanner button if editor has enabled it)

pull/5114/head
Daniel Spaude 2 years ago
parent
commit
110dd079af
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 2
      packages/nc-gui/components/smartsheet/Form.vue
  2. 2
      packages/nc-gui/composables/useSharedFormViewStore.ts
  3. 7
      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].includes(elementType) const columnSupportsScanning = (elementType: UITypes) => [UITypes.SingleLineText, UITypes.Number].includes(elementType)
onClickOutside(draggableRef, () => { onClickOutside(draggableRef, () => {
activeRow.value = '' activeRow.value = ''

2
packages/nc-gui/composables/useSharedFormViewStore.ts

@ -35,7 +35,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share
const sharedView = ref<ViewType>() const sharedView = ref<ViewType>()
const sharedFormView = ref<FormType>() const sharedFormView = ref<FormType>()
const meta = ref<TableType>() const meta = ref<TableType>()
const columns = ref<(ColumnType & { required?: boolean; show?: boolean; label?: string })[]>() const columns = ref<(ColumnType & { required?: boolean; show?: boolean; label?: string; enable_scanner?: boolean })[]>()
const sharedViewMeta = ref<SharedViewMeta>({}) const sharedViewMeta = ref<SharedViewMeta>({})
const formResetHook = createEventHook<void>() const formResetHook = createEventHook<void>()

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

@ -32,10 +32,13 @@ const onLoaded = async () => {
} }
const showCodeScannerForFieldTitle = (fieldTitle: string) => { const showCodeScannerForFieldTitle = (fieldTitle: string) => {
// findColumnByTitle(fieldTitle)?.enable_scanner
showCodeScannerOverlay.value = true showCodeScannerOverlay.value = true
fieldTitleForCurrentScan.value = fieldTitle fieldTitleForCurrentScan.value = fieldTitle
} }
const findColumnByTitle = (title: string) => formColumns.value?.find((el: ColumnType) => el.title === title)
const getScannedValueTransformerByFieldType = (fieldType: UITypes) => { const getScannedValueTransformerByFieldType = (fieldType: UITypes) => {
switch (fieldType) { switch (fieldType) {
case UITypes.Number: case UITypes.Number:
@ -50,7 +53,7 @@ const onDecode = async (scannedCodeValue: string) => {
return return
} }
try { try {
const fieldForCurrentScan = formColumns.value?.find((el: ColumnType) => el.title === fieldTitleForCurrentScan.value) const fieldForCurrentScan = findColumnByTitle(fieldTitleForCurrentScan.value)
if (fieldForCurrentScan == null) { if (fieldForCurrentScan == null) {
throw new Error(`Field with title ${fieldTitleForCurrentScan.value} not found`) throw new Error(`Field with title ${fieldTitleForCurrentScan.value} not found`)
} }
@ -170,7 +173,7 @@ const onDecode = async (scannedCodeValue: string) => {
{{ field.description }} {{ field.description }}
</div> </div>
<div> <div v-if="field.enable_scanner">
<a-button class="nc-btn-find-row-by-scan nc-toolbar-btn" @click="showCodeScannerForFieldTitle(field.title)"> <a-button class="nc-btn-find-row-by-scan nc-toolbar-btn" @click="showCodeScannerForFieldTitle(field.title)">
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<QrCodeScan /> <QrCodeScan />

Loading…
Cancel
Save