From 209ce39c4d584944ad94a1c72eb9313b05b4e767 Mon Sep 17 00:00:00 2001 From: Daniel Spaude Date: Wed, 21 Dec 2022 20:59:58 +0100 Subject: [PATCH] qr scanner POC - WIP (open expanded form for scanned row) --- .../qr-scanner-button/QrScannerButton.vue | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/qr-scanner-button/QrScannerButton.vue b/packages/nc-gui/components/smartsheet/qr-scanner-button/QrScannerButton.vue index bc98ad586a..d96812de5a 100644 --- a/packages/nc-gui/components/smartsheet/qr-scanner-button/QrScannerButton.vue +++ b/packages/nc-gui/components/smartsheet/qr-scanner-button/QrScannerButton.vue @@ -24,6 +24,9 @@ const meta = inject(MetaInj, ref()) // const tableName = meta.value?.table_name! // const tableName = view. +const route = useRoute() +const router = useRouter() + const { $api } = useNuxtApp() const { project } = useProject() // const projectName = project.value.title! @@ -40,21 +43,24 @@ interface Entry { onBeforeMount(init) async function init() { + // export const isPrimary = (column: ColumnType) => !!column.pv + console.log('meta.value?.id', meta.value?.id) + + // meta.value?.columns[0].pv + // const FOO = await $api.dbViewColumn.list(view.value?.id as string, { // // query: { // // }, // }) // console.log('FOO', FOO) // const foundRowForQrCode = await $api. - const foundRowForQrCode = await $api.dbViewRow.findOne(NOCO, project.value!.id!, meta.value!.id!, view.value!.title!, { - where: '(Title,eq,1)', - }) + // const foundRowForQrCode = await $api.dbTableRow.findOne(NOCO, projectName, tableName, { // fields: [''] // where: 'title5 == "Row 1"', // }) - console.log('foundRowForQrCode', foundRowForQrCode) + // console.log('foundRowForQrCode', foundRowForQrCode) // debugger qrCodeFieldOptions.value = meta?.value @@ -70,12 +76,45 @@ async function init() { const showQrCodeScanner = ref(false) const entry = ref(null) -const onDecode = async (qrCode: string) => { +const selectedCodeColumnIdToScanFor = ref('') + +const expandedFormOnRowIdDlg = computed({ + get() { + return !!route.query.rowId + }, + set(val) { + if (!val) + router.push({ + query: { + ...route.query, + rowId: undefined, + }, + }) + }, +}) + + +const onDecode = async (qrCodeValue: string) => { try { - alert(qrCode) + alert(qrCodeValue) showQrCodeScanner.value = false + const whereClause = `(${selectedCodeColumnIdToScanFor.value},eq,${qrCodeValue})` + const foundRowForQrCode = await $api.dbViewRow.findOne(NOCO, project.value!.id!, meta.value!.id!, view.value!.title!, { + where: whereClause, + }) + + const rowIdOfFoundRow = meta.value?.id && foundRowForQrCode[meta.value.id] + + const primaryKeyValueForFoundRow = extractPkFromRow(foundRowForQrCode, meta!.value!.columns!) + + console.log('foundRowForQrCode', foundRowForQrCode) + + console.log('rowIdOfFoundRow', rowIdOfFoundRow) + + console.log('primaryKeyValueForFoundRow', primaryKeyValueForFoundRow) + // const foundRowForQrCode = await $api.dbTableRow.findOne(NOCO, projectName, tableName, { // // fields: [''] // where: 'title5 == "Row 1"', @@ -119,6 +158,7 @@ const onDecode = async (qrCode: string) => { >