|
|
|
@ -18,6 +18,7 @@ export default class FormViewColumn implements FormColumnType {
|
|
|
|
|
fk_column_id?: string; |
|
|
|
|
project_id?: string; |
|
|
|
|
base_id?: string; |
|
|
|
|
meta?: string | Record<string, any>; |
|
|
|
|
|
|
|
|
|
constructor(data: FormViewColumn) { |
|
|
|
|
Object.assign(this, data); |
|
|
|
@ -25,28 +26,35 @@ export default class FormViewColumn implements FormColumnType {
|
|
|
|
|
|
|
|
|
|
uuid?: any; |
|
|
|
|
|
|
|
|
|
public static async get(formViewId: string, ncMeta = Noco.ncMeta) { |
|
|
|
|
let view = |
|
|
|
|
formViewId && |
|
|
|
|
public static async get(formViewColumnId: string, ncMeta = Noco.ncMeta) { |
|
|
|
|
let viewColumn = |
|
|
|
|
formViewColumnId && |
|
|
|
|
(await NocoCache.get( |
|
|
|
|
`${CacheScope.FORM_VIEW_COLUMN}:${formViewId}`, |
|
|
|
|
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`, |
|
|
|
|
CacheGetType.TYPE_OBJECT |
|
|
|
|
)); |
|
|
|
|
if (!view) { |
|
|
|
|
view = await ncMeta.metaGet2( |
|
|
|
|
if (!viewColumn) { |
|
|
|
|
viewColumn = await ncMeta.metaGet2( |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.FORM_VIEW_COLUMNS, |
|
|
|
|
formViewId |
|
|
|
|
formViewColumnId |
|
|
|
|
); |
|
|
|
|
viewColumn.meta = |
|
|
|
|
viewColumn.meta && typeof viewColumn.meta === 'string' |
|
|
|
|
? JSON.parse(viewColumn.meta) |
|
|
|
|
: viewColumn.meta; |
|
|
|
|
} |
|
|
|
|
await NocoCache.set(`${CacheScope.FORM_VIEW_COLUMN}:${formViewId}`, view); |
|
|
|
|
await NocoCache.set( |
|
|
|
|
`${CacheScope.FORM_VIEW_COLUMN}:${formViewColumnId}`, |
|
|
|
|
viewColumn |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return view && new FormViewColumn(view); |
|
|
|
|
return viewColumn && new FormViewColumn(viewColumn); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static async insert(column: Partial<FormViewColumn>, ncMeta = Noco.ncMeta) { |
|
|
|
|
const insertObj = { |
|
|
|
|
const insertObj: Partial<FormViewColumn> = { |
|
|
|
|
fk_view_id: column.fk_view_id, |
|
|
|
|
fk_column_id: column.fk_column_id, |
|
|
|
|
order: await ncMeta.metaGetNextOrder(MetaTable.FORM_VIEW_COLUMNS, { |
|
|
|
@ -61,6 +69,13 @@ export default class FormViewColumn implements FormColumnType {
|
|
|
|
|
required: column.required, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (insertObj.meta) { |
|
|
|
|
insertObj.meta = |
|
|
|
|
typeof insertObj.meta === 'object' |
|
|
|
|
? JSON.stringify(insertObj.meta) |
|
|
|
|
: insertObj.meta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!(column.project_id && column.base_id)) { |
|
|
|
|
const viewRef = await View.get(column.fk_view_id, ncMeta); |
|
|
|
|
insertObj.project_id = viewRef.project_id; |
|
|
|
@ -113,6 +128,14 @@ export default class FormViewColumn implements FormColumnType {
|
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
for (const viewColumn of viewColumns) { |
|
|
|
|
viewColumn.meta = |
|
|
|
|
viewColumn.meta && typeof viewColumn.meta === 'string' |
|
|
|
|
? JSON.parse(viewColumn.meta) |
|
|
|
|
: viewColumn.meta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await NocoCache.setList( |
|
|
|
|
CacheScope.FORM_VIEW_COLUMN, |
|
|
|
|
[viewId], |
|
|
|
@ -139,7 +162,16 @@ export default class FormViewColumn implements FormColumnType {
|
|
|
|
|
'required', |
|
|
|
|
'show', |
|
|
|
|
'order', |
|
|
|
|
'meta', |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
if (insertObj.meta) { |
|
|
|
|
insertObj.meta = |
|
|
|
|
insertObj.meta && typeof insertObj.meta === 'object' |
|
|
|
|
? JSON.stringify(insertObj.meta) |
|
|
|
|
: insertObj.meta; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// get existing cache
|
|
|
|
|
const key = `${CacheScope.FORM_VIEW_COLUMN}:${columnId}`; |
|
|
|
|
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
|