Browse Source

adjust to PR comments

pull/4641/head
flisowna 2 years ago
parent
commit
27f3d53ca6
  1. 24
      packages/nc-gui/components/smartsheet/column/BarcodeOptions.vue
  2. 10
      packages/nc-gui/components/virtual-cell/barcode/JsBarcodeWrapper.vue
  3. 1
      packages/nocodb/src/lib/migrations/v2/nc_023_barcode_column_type.ts
  4. 3
      packages/nocodb/src/lib/models/BarcodeColumn.ts

24
packages/nc-gui/components/smartsheet/column/BarcodeOptions.vue

@ -2,7 +2,7 @@
import type { UITypes } from 'nocodb-sdk'
import { AllowedColumnTypesForQrAndBarcodes } from 'nocodb-sdk'
import type { SelectProps } from 'ant-design-vue'
import { useVModel } from '#imports'
import { onMounted, useVModel, watch } from '#imports'
const props = defineProps<{
modelValue: any
@ -22,7 +22,7 @@ const vModel = useVModel(props, 'modelValue', emit)
const { setAdditionalValidations, validateInfos, column } = useColumnCreateStoreOrThrow()
const columnsAllowedAsQrValue = computed<SelectProps['options']>(() => {
const columnsAllowedAsBarcodeValue = computed<SelectProps['options']>(() => {
return fields.value
?.filter(
(el) =>
@ -52,7 +52,18 @@ const supportedBarcodeFormats = [
onMounted(() => {
// set default value
vModel.value.fk_barcode_value_column_id = (column?.value?.colOptions as Record<string, any>)?.fk_barcode_value_column_id || ''
vModel.value.meta = {
barcodeFormat: supportedBarcodeFormats[0].value,
...vModel.value.meta,
}
vModel.value.fk_barcode_value_column_id =
(column?.value?.colOptions as Record<string, any>)?.fk_barcode_value_column_id || columnsAllowedAsBarcodeValue.value?.[0]
})
watch(columnsAllowedAsBarcodeValue, (newColumnsAllowedAsBarcodeValue) => {
if (vModel.value.fk_barcode_value_column_id == null) {
vModel.value.fk_barcode_value_column_id = newColumnsAllowedAsBarcodeValue?.[0].value
}
})
setAdditionalValidations({
@ -61,10 +72,6 @@ setAdditionalValidations({
})
// set default meta value
vModel.value.meta = {
barcodeFormat: supportedBarcodeFormats[0].value,
...vModel.value.meta,
}
</script>
<template>
@ -77,8 +84,9 @@ vModel.value.meta = {
>
<a-select
v-model:value="vModel.fk_barcode_value_column_id"
:options="columnsAllowedAsQrValue"
:options="columnsAllowedAsBarcodeValue"
placeholder="Select a column for the Barcode value"
not-found-content="No valid Column Type can be found. The valid Column Types are: Number, Single Line Text, Long Text, Phone Number, URL, Email, Decimal. Please create one first."
@click.stop
/>
</a-form-item>

10
packages/nc-gui/components/virtual-cell/barcode/JsBarcodeWrapper.vue

@ -5,9 +5,11 @@ const props = defineProps({
barcodeValue: { type: String, required: true },
barcodeFormat: { type: String, required: true },
})
const emit = defineEmits(['onClickBarcode'])
const barcodeSvgRef = ref(null)
const errorForCurrentInput = ref(false)
const generate = () => {
try {
JsBarcode(barcodeSvgRef.value, String(props.barcodeValue), {
@ -31,12 +33,6 @@ onMounted(generate)
</script>
<template>
<svg data-testid="barcode" v-show="!errorForCurrentInput" ref="barcodeSvgRef" @click="onBarcodeClick"></svg>
<svg class="w-full" data-testid="barcode" v-show="!errorForCurrentInput" ref="barcodeSvgRef" @click="onBarcodeClick"></svg>
<slot v-if="errorForCurrentInput" name="barcodeRenderError" />
</template>
<style scoped>
svg {
width: 100%;
}
</style>

1
packages/nocodb/src/lib/migrations/v2/nc_023_barcode_column_type.ts

@ -15,7 +15,6 @@ const up = async (knex: Knex) => {
table.string('barcode_format', 15);
table.boolean('deleted');
table.float('order');
table.timestamps(true, true);
});
};

3
packages/nocodb/src/lib/models/BarcodeColumn.ts

@ -4,6 +4,7 @@ import NocoCache from '../cache/NocoCache';
import { extractProps } from '../meta/helpers/extractProps';
export default class BarcodeColumn {
id: string;
fk_column_id: string;
fk_barcode_value_column_id: string;
barcode_format: string;
@ -44,8 +45,6 @@ export default class BarcodeColumn {
return column ? new BarcodeColumn(column) : null;
}
id: string;
static async update(
id: string,
barcode: Partial<BarcodeColumn>,

Loading…
Cancel
Save