mirror of https://github.com/nocodb/nocodb
Daniel Spaude
2 years ago
22 changed files with 4501 additions and 209 deletions
@ -0,0 +1,66 @@
|
||||
<script setup lang="ts"> |
||||
import { UITypes } from 'nocodb-sdk' |
||||
import type { SelectProps } from 'ant-design-vue' |
||||
import { useVModel } from '#imports' |
||||
|
||||
const props = defineProps<{ |
||||
value: any |
||||
}>() |
||||
const emit = defineEmits(['update:value']) |
||||
|
||||
const meta = inject(MetaInj, ref()) |
||||
|
||||
const activeView = inject(ActiveViewInj, ref()) |
||||
|
||||
const reloadDataHook = inject(ReloadViewDataHookInj)! |
||||
|
||||
const { fields, metaColumnById } = useViewColumns(activeView, meta, () => reloadDataHook.trigger()) |
||||
|
||||
const vModel = useVModel(props, 'value', emit) |
||||
|
||||
const { column } = useColumnCreateStoreOrThrow() |
||||
|
||||
const allowedColumnTypesForQrValue = [UITypes.Formula, UITypes.SingleLineText, UITypes.LongText] as string[] |
||||
|
||||
const columnsAllowedAsQrValue = computed<SelectProps['options']>(() => { |
||||
return fields.value |
||||
?.filter((el) => el.fk_column_id && allowedColumnTypesForQrValue.includes(metaColumnById.value[el.fk_column_id].uidt)) |
||||
.map((field) => { |
||||
return { |
||||
value: field.fk_column_id, |
||||
label: field.title, |
||||
} |
||||
}) |
||||
}) |
||||
|
||||
// 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" /> |
||||
</div> |
||||
<div class="nc-fields-list py-1"> |
||||
<div class="grouping-field"> |
||||
<a-select |
||||
v-model:value="vModel.fk_qr_value_column_id" |
||||
class="w-full nc-kanban-grouping-field-select" |
||||
:options="columnsAllowedAsQrValue" |
||||
placeholder="Select a Grouping Field" |
||||
@click.stop |
||||
/> |
||||
</div> |
||||
</div> |
||||
</a-col> |
||||
</a-row> |
||||
</template> |
@ -0,0 +1,15 @@
|
||||
<script setup lang="ts"> |
||||
import { useQRCode } from '@vueuse/integrations/useQRCode' |
||||
|
||||
const value = inject(CellValueInj) |
||||
|
||||
const qrCode = |
||||
value?.value && |
||||
useQRCode(value?.value, { |
||||
width: 150, |
||||
}) |
||||
</script> |
||||
|
||||
<template> |
||||
<img v-if="qrCode" :src="qrCode" alt="QR Code" class="qr-code" /> |
||||
</template> |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,26 @@
|
||||
import Knex from 'knex'; |
||||
import { MetaTable } from '../../utils/globals'; |
||||
|
||||
const up = async (knex: Knex) => { |
||||
await knex.schema.createTable(MetaTable.COL_QRCODE, (table) => { |
||||
table.string('id', 20).primary().notNullable(); |
||||
|
||||
table.string('fk_column_id', 20); |
||||
table.foreign('fk_column_id').references(`${MetaTable.COLUMNS}.id`); |
||||
|
||||
table.string('fk_qr_value_column_id', 20); |
||||
table |
||||
.foreign('fk_qr_value_column_id') |
||||
.references(`${MetaTable.COLUMNS}.id`); |
||||
|
||||
table.boolean('deleted'); |
||||
table.float('order'); |
||||
table.timestamps(true, true); |
||||
}); |
||||
}; |
||||
|
||||
const down = async (knex: Knex) => { |
||||
await knex.schema.dropTable(MetaTable.COL_QRCODE); |
||||
}; |
||||
|
||||
export { up, down }; |
@ -0,0 +1,68 @@
|
||||
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 QrCodeColumn { |
||||
fk_column_id: string; |
||||
fk_qr_value_column_id: string; |
||||
|
||||
constructor(data: Partial<QrCodeColumn>) { |
||||
Object.assign(this, data); |
||||
} |
||||
|
||||
public static async insert( |
||||
data: Partial<QrCodeColumn>, |
||||
ncMeta = Noco.ncMeta |
||||
) { |
||||
// BOOKMARK
|
||||
await ncMeta.metaInsert2(null, null, MetaTable.COL_QRCODE, { |
||||
fk_column_id: data.fk_column_id, |
||||
fk_qr_value_column_id: data.fk_qr_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_QRCODE}:${columnId}`, |
||||
CacheGetType.TYPE_OBJECT |
||||
)); |
||||
if (!column) { |
||||
column = await ncMeta.metaGet2( |
||||
null, //,
|
||||
null, //model.db_alias,
|
||||
MetaTable.COL_QRCODE, |
||||
{ fk_column_id: columnId } |
||||
); |
||||
await NocoCache.set(`${CacheScope.COL_QRCODE}:${columnId}`, column); |
||||
} |
||||
|
||||
return column ? new QrCodeColumn(column) : null; |
||||
} |
||||
|
||||
id: string; |
||||
|
||||
static async update( |
||||
id: string, |
||||
qrCode: Partial<QrCodeColumn>, |
||||
ncMeta = Noco.ncMeta |
||||
) { |
||||
const updateObj = extractProps(qrCode, [ |
||||
'fk_column_id', |
||||
'fk_qr_value_column_id', |
||||
]); |
||||
// get existing cache
|
||||
const key = `${CacheScope.COL_QRCODE}:${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_QRCODE, updateObj, id); |
||||
} |
||||
} |
Loading…
Reference in new issue