mirror of https://github.com/nocodb/nocodb
Wing-Kam Wong
2 years ago
1 changed files with 76 additions and 7 deletions
@ -1,23 +1,92 @@
|
||||
import Noco from '../Noco'; |
||||
import { MetaTable } from '../utils/globals'; |
||||
import { KanbanType } from 'nocodb-sdk'; |
||||
import { CacheGetType, CacheScope, MetaTable } from '../utils/globals'; |
||||
import View from './View'; |
||||
import NocoCache from '../cache/NocoCache'; |
||||
import { isLeafType } from 'graphql'; |
||||
|
||||
export default class KanbanView { |
||||
export default class KanbanView implements KanbanType{ |
||||
fk_view_id: string; |
||||
title: string; |
||||
project_id?: string; |
||||
base_id?: string; |
||||
|
||||
// TODO: check these
|
||||
show: boolean; |
||||
is_default: boolean; |
||||
order: number; |
||||
|
||||
fk_view_id: string; |
||||
|
||||
constructor(data: KanbanView) { |
||||
Object.assign(this, data); |
||||
} |
||||
|
||||
public static async get(viewId: string, ncMeta = Noco.ncMeta) { |
||||
const view = await ncMeta.metaGet2(null, null, MetaTable.KANBAN_VIEW, { |
||||
let view = |
||||
viewId && |
||||
(await NocoCache.get( |
||||
`${CacheScope.KANBAN_VIEW}:${viewId}`, |
||||
CacheGetType.TYPE_OBJECT |
||||
)); |
||||
if (!view) { |
||||
view = await ncMeta.metaGet2(null, null, MetaTable.KANBAN_VIEW, { |
||||
fk_view_id: viewId, |
||||
}); |
||||
await NocoCache.set(`${CacheScope.KANBAN_VIEW}:${viewId}`, view); |
||||
} |
||||
|
||||
return view && new KanbanView(view); |
||||
} |
||||
|
||||
static async insert(view: Partial<KanbanView>, ncMeta = Noco.ncMeta) { |
||||
const insertObj = { |
||||
project_id: view.project_id, |
||||
base_id: view.base_id, |
||||
fk_view_id: view.fk_view_id, |
||||
// TODO: more
|
||||
}; |
||||
if (!(view.project_id && view.base_id)) { |
||||
const viewRef = await View.get(view.fk_view_id); |
||||
insertObj.project_id = viewRef.project_id; |
||||
insertObj.base_id = viewRef.base_id; |
||||
} |
||||
|
||||
await ncMeta.metaInsert2( |
||||
null, |
||||
null, |
||||
MetaTable.KANBAN_VIEW, |
||||
insertObj, |
||||
true |
||||
); |
||||
|
||||
return this.get(view.fk_view_id, ncMeta); |
||||
} |
||||
|
||||
static async update( |
||||
kanbanId: string, |
||||
body: Partial<KanbanView>, |
||||
ncMeta = Noco.ncMeta |
||||
) { |
||||
// get existing cache
|
||||
const key = `${CacheScope.KANBAN_VIEW}:${kanbanId}`; |
||||
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT); |
||||
const updateObj = { |
||||
// TODO:
|
||||
} |
||||
if (o) { |
||||
o = { ...o, ...updateObj }; |
||||
// set cache
|
||||
await NocoCache.set(key, o); |
||||
} |
||||
// update meta
|
||||
return await ncMeta.metaUpdate( |
||||
null, |
||||
null, |
||||
MetaTable.KANBAN_VIEW, |
||||
...updateObj, |
||||
{ |
||||
fk_view_id: kanbanId, |
||||
} |
||||
); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue