|
|
|
@ -3,6 +3,7 @@ import { CacheGetType, CacheScope, MetaTable } from '../utils/globals';
|
|
|
|
|
import { GalleryColumnType, GalleryType, UITypes } from 'nocodb-sdk'; |
|
|
|
|
import View from './View'; |
|
|
|
|
import NocoCache from '../cache/NocoCache'; |
|
|
|
|
import { extractProps } from '../meta/helpers/extractProps'; |
|
|
|
|
|
|
|
|
|
export default class GalleryView implements GalleryType { |
|
|
|
|
fk_view_id?: string; |
|
|
|
@ -51,21 +52,23 @@ export default class GalleryView implements GalleryType {
|
|
|
|
|
.then((v) => v?.getModel(ncMeta)) |
|
|
|
|
.then((m) => m.getColumns(ncMeta)); |
|
|
|
|
|
|
|
|
|
const insertObj = { |
|
|
|
|
project_id: view.project_id, |
|
|
|
|
base_id: view.base_id, |
|
|
|
|
fk_view_id: view.fk_view_id, |
|
|
|
|
fk_cover_image_col_id: |
|
|
|
|
view?.fk_cover_image_col_id || |
|
|
|
|
columns?.find((c) => c.uidt === UITypes.Attachment)?.id, |
|
|
|
|
next_enabled: view.next_enabled, |
|
|
|
|
prev_enabled: view.prev_enabled, |
|
|
|
|
cover_image_idx: view.cover_image_idx, |
|
|
|
|
cover_image: view.cover_image, |
|
|
|
|
restrict_types: view.restrict_types, |
|
|
|
|
restrict_size: view.restrict_size, |
|
|
|
|
restrict_number: view.restrict_number, |
|
|
|
|
}; |
|
|
|
|
const insertObj = extractProps(view, [ |
|
|
|
|
'project_id', |
|
|
|
|
'base_id', |
|
|
|
|
'fk_view_id', |
|
|
|
|
'next_enabled', |
|
|
|
|
'prev_enabled', |
|
|
|
|
'cover_image_idx', |
|
|
|
|
'cover_image', |
|
|
|
|
'restrict_types', |
|
|
|
|
'restrict_size', |
|
|
|
|
'restrict_number', |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
insertObj.fk_cover_image_col_id = |
|
|
|
|
view?.fk_cover_image_col_id || |
|
|
|
|
columns?.find((c) => c.uidt === UITypes.Attachment)?.id; |
|
|
|
|
|
|
|
|
|
if (!(view.project_id && view.base_id)) { |
|
|
|
|
const viewRef = await View.get(view.fk_view_id); |
|
|
|
|
insertObj.project_id = viewRef.project_id; |
|
|
|
@ -90,16 +93,19 @@ export default class GalleryView implements GalleryType {
|
|
|
|
|
) { |
|
|
|
|
// get existing cache
|
|
|
|
|
const key = `${CacheScope.GALLERY_VIEW}:${galleryId}`; |
|
|
|
|
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
|
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); |
|
|
|
|
const updateObj = extractProps(body, [ |
|
|
|
|
'next_enabled', |
|
|
|
|
'prev_enabled', |
|
|
|
|
'cover_image_idx', |
|
|
|
|
'cover_image', |
|
|
|
|
'restrict_types', |
|
|
|
|
'restrict_size', |
|
|
|
|
'restrict_number', |
|
|
|
|
'fk_cover_image_col_id', |
|
|
|
|
]); |
|
|
|
|
if (o) { |
|
|
|
|
o.next_enabled = body.next_enabled; |
|
|
|
|
o.prev_enabled = body.prev_enabled; |
|
|
|
|
o.cover_image_idx = body.cover_image_idx; |
|
|
|
|
o.cover_image = body.cover_image; |
|
|
|
|
o.restrict_types = body.restrict_types; |
|
|
|
|
o.restrict_size = body.restrict_size; |
|
|
|
|
o.restrict_number = body.restrict_number; |
|
|
|
|
o.fk_cover_image_col_id = body.fk_cover_image_col_id; |
|
|
|
|
o = { ...o, ...updateObj }; |
|
|
|
|
// set cache
|
|
|
|
|
await NocoCache.set(key, o); |
|
|
|
|
} |
|
|
|
@ -108,16 +114,7 @@ export default class GalleryView implements GalleryType {
|
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
MetaTable.GALLERY_VIEW, |
|
|
|
|
{ |
|
|
|
|
next_enabled: body.next_enabled, |
|
|
|
|
prev_enabled: body.prev_enabled, |
|
|
|
|
cover_image_idx: body.cover_image_idx, |
|
|
|
|
cover_image: body.cover_image, |
|
|
|
|
restrict_types: body.restrict_types, |
|
|
|
|
restrict_size: body.restrict_size, |
|
|
|
|
restrict_number: body.restrict_number, |
|
|
|
|
fk_cover_image_col_id: body.fk_cover_image_col_id, |
|
|
|
|
}, |
|
|
|
|
updateObj, |
|
|
|
|
{ |
|
|
|
|
fk_view_id: galleryId, |
|
|
|
|
} |
|
|
|
|