Browse Source

qrcode: delete qr code if referenced column is deleted

* plus some cleanup
pull/4142/head
Daniel Spaude 2 years ago
parent
commit
7aa49ab9b7
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 6
      packages/nc-gui/components/smartsheet/column/QrCodeOptions.vue
  2. 2
      packages/nc-gui/components/virtual-cell/QrCode.vue
  3. 13
      packages/nocodb/src/lib/models/Column.ts

6
packages/nc-gui/components/smartsheet/column/QrCodeOptions.vue

@ -35,17 +35,11 @@ const columnsAllowedAsQrValue = computed<SelectProps['options']>(() => {
// set default value
vModel.value.fk_qr_value_column_id = (column?.value?.colOptions as Record<string, any>)?.fk_qr_value_column_id || ''
// console.log('vModel.value.fk_qr_value_column_id', vModel.value.fk_qr_value_column_id)
const jsonstr = computed(() => {
return JSON.stringify(vModel.value, null, 2)
})
</script>
<template>
<a-row>
<a-col :span="24">
<textarea v-model="jsonstr" rows="8" cols="40"></textarea>
<div>
<span class="font-bold"> {{ $t('labels.chooseQrValueColumn') }}</span>
<a-divider class="!my-2" />

2
packages/nc-gui/components/virtual-cell/QrCode.vue

@ -3,7 +3,7 @@ import { useQRCode } from '@vueuse/integrations/useQRCode'
const value = inject(CellValueInj)
const qrValue = computed(() => value?.value)
const qrValue = computed(() => String(value?.value))
const qrCode = useQRCode(qrValue, {
width: 150,
})

13
packages/nocodb/src/lib/models/Column.ts

@ -576,6 +576,19 @@ export default class Column<T = any> implements ColumnType {
// todo: or instead of delete reset related foreign key value to null and handle in BaseModel
// get qr code columns and delete
{
let qrCodeCols = await NocoCache.getList(CacheScope.COL_QRCODE, [id]);
if (!qrCodeCols.length) {
qrCodeCols = await ncMeta.metaList2(null, null, MetaTable.COL_QRCODE, {
condition: { fk_qr_value_column_id: id },
});
}
for (const qrCodeCol of qrCodeCols) {
await Column.delete(qrCodeCol.fk_column_id, ncMeta);
}
}
// get lookup columns and delete
{
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);

Loading…
Cancel
Save