Browse Source

code scanner for forms - WIP

pull/5114/head
Daniel Spaude 2 years ago
parent
commit
5dec1b937f
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 2
      packages/nc-gui/components/smartsheet/toolbar/QrScannerButton.vue
  2. 3
      packages/nc-gui/lang/en.json
  3. 73
      packages/nc-gui/pages/[projectType]/form/[viewId]/index/index.vue

2
packages/nc-gui/components/smartsheet/toolbar/QrScannerButton.vue

@ -96,7 +96,7 @@ const onDecode = async (codeValue: string) => {
<a-button class="nc-btn-find-row-by-scan nc-toolbar-btn" @click="showCodeScannerOverlay = true"> <a-button class="nc-btn-find-row-by-scan nc-toolbar-btn" @click="showCodeScannerOverlay = true">
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<QrCodeScan /> <QrCodeScan />
<span v-if="!isMobileMode" class="!text-xs font-weight-normal"> {{ $t('activity.scanCode') }}</span> <span v-if="!isMobileMode" class="!text-xs font-weight-normal"> {{ $t('activity.findRowByCodeScan') }}</span>
</div> </div>
</a-button> </a-button>
<a-modal <a-modal

3
packages/nc-gui/lang/en.json

@ -404,7 +404,8 @@
"changePwd": "Change Password", "changePwd": "Change Password",
"createView": "Create a View", "createView": "Create a View",
"shareView": "Share View", "shareView": "Share View",
"scanCode": "Find row by scan", "findRowByCodeScan": "Find row by scan",
"fillByCodeScan": "Fill by scan",
"listSharedView": "Shared View List", "listSharedView": "Shared View List",
"ListView": "Views List", "ListView": "Views List",
"copyView": "Copy view", "copyView": "Copy view",

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

@ -1,22 +1,29 @@
<script lang="ts" setup> <script lang="ts" setup>
import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk'
import { useSharedFormStoreOrThrow } from '#imports' import { StreamBarcodeReader } from 'vue-barcode-reader'
import { NOCO, useSharedFormStoreOrThrow } from '#imports'
const { sharedFormView, submitForm, v$, formState, notFound, formColumns, submitted, secondsRemain, isLoading } = import QrCodeScan from '~icons/mdi/qrcode-scan'
useSharedFormStoreOrThrow()
function isRequired(_columnObj: Record<string, any>, required = false) { // const meta = inject(MetaInj, ref())
let columnObj = _columnObj
if ( // const { t } = useI18n()
columnObj.uidt === UITypes.LinkToAnotherRecord &&
columnObj.colOptions &&
columnObj.colOptions.type === RelationTypes.BELONGS_TO const showCodeScannerOverlay = ref(false)
) {
columnObj = formColumns.value?.find((c) => c.id === columnObj.colOptions.fk_child_column_id) as Record<string, any> const lastScannedCode = ref('')
}
const scannerIsReady = ref(false)
// TODO: better use directly scannerIsReady
const showScannerField = computed(() => scannerIsReady.value)
const { formColumns } =
useSharedFormStoreOrThrow()
return !!(required || (columnObj && columnObj.rqd && !columnObj.cdf))
}
</script> </script>
<template> <template>
@ -101,6 +108,44 @@ function isRequired(_columnObj: Record<string, any>, required = false) {
:edit-enabled="true" :edit-enabled="true"
/> />
<div>
SCANNER PLACEHOLDER
<a-button class="nc-btn-find-row-by-scan nc-toolbar-btn" @click="showCodeScannerOverlay = true">
<div class="flex items-center gap-1">
<QrCodeScan />
<span class="!text-xs font-weight-normal"> {{ $t('activity.fillByCodeScan') }}</span>
</div>
</a-button>
<a-modal
v-model:visible="showCodeScannerOverlay"
:closable="false"
width="28rem"
centered
:footer="null"
wrap-class-name="nc-modal-generate-token"
destroy-on-close
@cancel="scannerIsReady = false"
>
<div class="relative flex flex-col h-full">
<a-form-item :label="$t('labels.columnToScanFor')">
<a-select v-model:value="selectedCodeColumnIdToScanFor" class="w-full" :options="codeFieldOptions" />
</a-form-item>
<div>
<StreamBarcodeReader v-show="showScannerField" @decode="onDecode" @loaded="onLoaded">
</StreamBarcodeReader>
<div v-if="showPleaseSelectColumnMessage" class="text-left text-wrap mt-2 text-[#e65100] text-xs">
{{ $t('msg.info.codeScanner.selectColumn') }}
</div>
<div v-if="showScannerIsLoadingMessage" class="text-left text-wrap mt-2 text-[#e65100] text-xs">
{{ $t('msg.info.codeScanner.loadingScanner') }}
</div>
</div>
</div>
</a-modal>
</div>
<div class="flex flex-col gap-2 text-slate-500 dark:text-slate-300 text-[0.75rem] my-2 px-1"> <div class="flex flex-col gap-2 text-slate-500 dark:text-slate-300 text-[0.75rem] my-2 px-1">
<div v-for="error of v$.localState[field.title]?.$errors" :key="error" class="text-red-500"> <div v-for="error of v$.localState[field.title]?.$errors" :key="error" class="text-red-500">
{{ error.$message }} {{ error.$message }}

Loading…
Cancel
Save