Browse Source

WIP barcode column type

pull/4641/head
flisowna 2 years ago
parent
commit
a9e34339f5
  1. 13
      packages/noco-docs/content/en/setup-and-usages/column-types.md
  2. 1
      packages/nocodb-sdk/src/lib/UITypes.ts
  3. 0
      packages/nocodb-sdk/src/lib/columnRules/QrAndBarcodeRules.ts
  4. 67
      packages/nocodb/src/lib/models/BarcodeColumn.ts
  5. 56
      packages/nocodb/src/lib/models/Column.ts
  6. 2
      packages/nocodb/src/lib/utils/globals.ts
  7. 30
      packages/nocodb/tests/unit/factory/column.ts

13
packages/noco-docs/content/en/setup-and-usages/column-types.md

@ -33,6 +33,7 @@ menuTitle: 'Column Types'
|[Rating](#rating)| Rating |
|[Formula](#formula)| Formula based generated column |
|[QR Code](#qr-code)| QR Code visualization of another referenced column |
|[Barcode](#barcode)| Barcode visualization of another referenced column |
| [Count](#count) | |
|[DateTime](#datetime)| Date & Time selector |
|[CreateTime](#createtime)| |
@ -279,6 +280,18 @@ Encodes the value of a reference column as QR code. The following column types a
* Email
Since it's a virtual column, the cell content (QR code) cannot be changed directly.
### Barcode
Encodes the value of a reference column as Barcode. Supported barcode formats: CODE128, EAN, EAN-13, EAN-8, EAN-5, EAN-2, UPC (A), CODE39, ITF-14, MSI, Pharmacode, Codabar. The following column types are supported for the for reference column:
* Formula
* Single Line Text
* Long Text
* Phone Number
* URL
* Email
Since it's a virtual column, the cell content (Barcode) cannot be changed directly.
### Count
#### Available Database Types

1
packages/nocodb-sdk/src/lib/UITypes.ts

@ -52,6 +52,7 @@ export function isVirtualCol(
UITypes.LinkToAnotherRecord,
UITypes.Formula,
UITypes.QrCode,
UITypes.Barcode,
UITypes.Rollup,
UITypes.Lookup,
// UITypes.Count,

0
packages/nocodb-sdk/src/lib/columnRules/QrCodeRules.ts → packages/nocodb-sdk/src/lib/columnRules/QrAndBarcodeRules.ts

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

@ -0,0 +1,67 @@
import Noco from '../Noco';
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
import NocoCache from '../cache/NocoCache';
import { extractProps } from '../meta/helpers/extractProps';
export default class BarcodeColumn {
fk_column_id: string;
fk_barcode_value_column_id: string;
constructor(data: Partial<BarcodeColumn>) {
Object.assign(this, data);
}
public static async insert(
data: Partial<BarcodeColumn>,
ncMeta = Noco.ncMeta
) {
await ncMeta.metaInsert2(null, null, MetaTable.COL_BARCODE, {
fk_column_id: data.fk_column_id,
fk_barcode_value_column_id: data.fk_barcode_value_column_id,
});
return this.read(data.fk_column_id, ncMeta);
}
public static async read(columnId: string, ncMeta = Noco.ncMeta) {
let column =
columnId &&
(await NocoCache.get(
`${CacheScope.COL_BARCODE}:${columnId}`,
CacheGetType.TYPE_OBJECT
));
if (!column) {
column = await ncMeta.metaGet2(
null, //,
null, //model.db_alias,
MetaTable.COL_BARCODE,
{ fk_column_id: columnId }
);
await NocoCache.set(`${CacheScope.COL_BARCODE}:${columnId}`, column);
}
return column ? new BarcodeColumn(column) : null;
}
id: string;
static async update(
id: string,
barcode: Partial<BarcodeColumn>,
ncMeta = Noco.ncMeta
) {
const updateObj = extractProps(barcode, [
'fk_column_id',
'fk_barcode_value_column_id',
]);
// get existing cache
const key = `${CacheScope.COL_BARCODE}:${id}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(key, o);
}
// set meta
await ncMeta.metaUpdate(null, null, MetaTable.COL_BARCODE, updateObj, id);
}
}

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

@ -24,6 +24,7 @@ import Filter from './Filter';
import addFormulaErrorIfMissingColumn from '../meta/helpers/addFormulaErrorIfMissingColumn';
import { NcError } from '../meta/helpers/catchError';
import QrCodeColumn from './QrCodeColumn';
import BarcodeColumn from './BarcodeColumn';
export default class Column<T = any> implements ColumnType {
public fk_model_id: string;
@ -234,6 +235,16 @@ export default class Column<T = any> implements ColumnType {
);
break;
}
case UITypes.Barcode: {
await BarcodeColumn.insert(
{
fk_column_id: colId,
fk_barcode_value_column_id: column.fk_barcode_value_column_id,
},
ncMeta
);
break;
}
case UITypes.Formula: {
await FormulaColumn.insert(
{
@ -413,6 +424,9 @@ export default class Column<T = any> implements ColumnType {
case UITypes.QrCode:
res = await QrCodeColumn.read(this.id, ncMeta);
break;
case UITypes.Barcode:
res = await BarcodeColumn.read(this.id, ncMeta);
break;
// default:
// res = await DbColumn.read(this.id);
// break;
@ -590,6 +604,20 @@ export default class Column<T = any> implements ColumnType {
}
}
{
const barcodeCols = await ncMeta.metaList2(
null,
null,
MetaTable.COL_BARCODE,
{
condition: { fk_barcode_value_column_id: id },
}
);
for (const barcodeCol of barcodeCols) {
await Column.delete(barcodeCol.fk_column_id, ncMeta);
}
}
// get lookup columns and delete
{
let lookups = await NocoCache.getList(CacheScope.COL_LOOKUP, [id]);
@ -728,6 +756,10 @@ export default class Column<T = any> implements ColumnType {
colOptionTableName = MetaTable.COL_QRCODE;
cacheScopeName = CacheScope.COL_QRCODE;
break;
case UITypes.Barcode:
colOptionTableName = MetaTable.COL_BARCODE;
cacheScopeName = CacheScope.COL_BARCODE;
break;
}
if (colOptionTableName && cacheScopeName) {
@ -905,6 +937,19 @@ export default class Column<T = any> implements ColumnType {
break;
}
case UITypes.Barcode: {
await ncMeta.metaDelete(null, null, MetaTable.COL_BARCODE, {
fk_column_id: colId,
});
await NocoCache.deepDel(
CacheScope.COL_BARCODE,
`${CacheScope.COL_BARCODE}:${colId}`,
CacheDelDirection.CHILD_TO_PARENT
);
break;
}
case UITypes.MultiSelect:
case UITypes.SingleSelect: {
await ncMeta.metaDelete(null, null, MetaTable.COL_SELECT_OPTIONS, {
@ -963,9 +1008,20 @@ export default class Column<T = any> implements ColumnType {
condition: { fk_qr_value_column_id: colId },
}
);
const barcodeCols = await ncMeta.metaList2(
null,
null,
MetaTable.COL_BARCODE,
{
condition: { fk_barcode_value_column_id: colId },
}
);
for (const qrCodeCol of qrCodeCols) {
await Column.delete(qrCodeCol.fk_column_id, ncMeta);
}
for (const barcodeCol of barcodeCols) {
await Column.delete(barcodeCol.fk_column_id, ncMeta);
}
}
// get existing cache

2
packages/nocodb/src/lib/utils/globals.ts

@ -11,6 +11,7 @@ export enum MetaTable {
COL_ROLLUP = 'nc_col_rollup_v2',
COL_FORMULA = 'nc_col_formula_v2',
COL_QRCODE = 'nc_col_qrcode_v2',
COL_BARCODE = 'nc_col_barcode_v2',
FILTER_EXP = 'nc_filter_exp_v2',
// HOOK_FILTER_EXP = 'nc_hook_filter_exp_v2',
SORT = 'nc_sort_v2',
@ -114,6 +115,7 @@ export enum CacheScope {
COL_ROLLUP = 'colRollup',
COL_FORMULA = 'colFormula',
COL_QRCODE = 'colQRCode',
COL_BARCODE = 'colBarcode',
FILTER_EXP = 'filterExp',
SORT = 'sort',
SHARED_VIEW = 'sharedView',

30
packages/nocodb/tests/unit/factory/column.ts

@ -184,6 +184,36 @@ const createQrCodeColumn = async (
return qrCodeColumn;
};
const createBarcodeColumn = async (
context,
{
title,
table,
referencedBarcodeValueTableColumnTitle,
}: {
title: string;
table: Model;
referencedBarcodeValueTableColumnTitle: string;
}
) => {
const referencedBarcodeValueTableColumnId = await table
.getColumns()
.then(
(cols) =>
cols.find(
(column) => column.title == referencedBarcodeValueTableColumnTitle
)['id']
);
const barcodeColumn = await createColumn(context, table, {
title: title,
uidt: UITypes.Barcode,
column_name: title,
fk_barcode_value_column_id: referencedBarcodeValueTableColumnId,
});
return barcodeColumn;
};
const createLtarColumn = async (
context,
{

Loading…
Cancel
Save