Browse Source

feat(nocodb): update calendarModel feat(nocodb): update swagger.json feat(nocodb): create calendarViewColumn model

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
8930a92c63
  1. 1
      packages/nocodb-sdk/src/lib/globals.ts
  2. 2
      packages/nocodb/src/meta/migrations/v2/nc_041_calander_view.ts
  3. 0
      packages/nocodb/src/models/CalanderView.ts
  4. 102
      packages/nocodb/src/models/CalendarView.ts
  5. 187
      packages/nocodb/src/models/CalendarViewColumn.ts
  6. 34
      packages/nocodb/src/schema/swagger.json
  7. 9
      packages/nocodb/src/utils/globals.ts

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

@ -6,6 +6,7 @@ export enum ViewTypes {
GRID = 3,
KANBAN = 4,
MAP = 5,
CALENDAR = 6,
}
export enum ProjectTypes {

2
packages/nocodb/src/meta/migrations/v2/nc_041_calander_view.ts

@ -2,7 +2,7 @@ import type { Knex } from 'knex';
import { MetaTable } from '~/utils/globals';
const up = async (knex: Knex) => {
await knex.schema.createTable(MetaTable.CALANDER_VIEW, (table) => {
await knex.schema.createTable(MetaTable.CALANDER, (table) => {
table.string('fk_view_id', 20).primary();
table.string('base_id', 20);

0
packages/nocodb/src/models/CalanderView.ts

102
packages/nocodb/src/models/CalendarView.ts

@ -0,0 +1,102 @@
import type { MetaType } from 'nocodb-sdk';
import type { CalendarType } from 'nocodb-sdk';
import View from '~/models/View';
import { extractProps } from '~/helpers/extractProps';
import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
export default class CalendarView implements CalendarType {
fk_view_id: string;
title: string;
base_id?: string;
source_id?: string;
meta?: MetaType;
// below fields are not in use at this moment
// keep them for time being
show?: boolean;
public?: boolean;
password?: string;
show_all_fields?: boolean;
constructor(data: CalendarView) {
Object.assign(this, data);
}
public static async get(viewId: string, ncMeta = Noco.ncMeta) {
let view =
viewId &&
(await NocoCache.get(
`${CacheScope.CALENDAR_VIEW}:${viewId}`,
CacheGetType.TYPE_OBJECT,
));
if (!view) {
view = await ncMeta.metaGet2(null, null, MetaTable.CALENDAR, {
fk_view_id: viewId,
});
await NocoCache.set(`${CacheScope.CALENDAR_VIEW}:${viewId}`, view);
}
return view && new CalendarView(view);
}
static async insert(view: Partial<CalendarView>, ncMeta = Noco.ncMeta) {
const insertObj = {
base_id: view.base_id,
source_id: view.source_id,
fk_view_id: view.fk_view_id,
meta: view.meta,
};
const viewRef = await View.get(view.fk_view_id);
if (!(view.base_id && view.source_id)) {
insertObj.base_id = viewRef.base_id;
insertObj.source_id = viewRef.source_id;
}
await ncMeta.metaInsert2(null, null, MetaTable.CALENDAR, insertObj, true);
return this.get(view.fk_view_id, ncMeta);
}
static async update(
calendarId: string,
body: Partial<CalendarView>,
ncMeta = Noco.ncMeta,
) {
// get existing cache
const key = `${CacheScope.CALENDAR_VIEW_COLUMN}:${calendarId}`;
let o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
const updateObj = extractProps(body, ['fk_cover_image_col_id', 'meta']);
if (updateObj.meta && typeof updateObj.meta === 'object') {
updateObj.meta = JSON.stringify(updateObj.meta ?? {});
}
if (o) {
o = { ...o, ...updateObj };
// set cache
await NocoCache.set(key, o);
}
// TODO: Update this when API is ready
/*if (body.fk_geo_data_col_id != null) {
const mapViewColumns = await MapViewColumn.list(mapId);
const mapViewMappedByColumn = mapViewColumns.find(
(mapViewColumn) =>
mapViewColumn.fk_column_id === body.fk_geo_data_col_id,
);
await View.updateColumn(body.fk_view_id, mapViewMappedByColumn.id, {
show: true,
});
}*/
// update meta
return await ncMeta.metaUpdate(null, null, MetaTable.CALENDAR, updateObj, {
fk_view_id: calendarId,
});
}
}

187
packages/nocodb/src/models/CalendarViewColumn.ts

@ -0,0 +1,187 @@
import type {
BoolType,
MetaType,
} from 'nocodb-sdk';
import View from '~/models/View';
import Noco from '~/Noco';
import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps';
import { deserializeJSON, serializeJSON } from '~/utils/serialize';
import { CacheGetType, CacheScope, MetaTable } from '~/utils/globals';
export default class CalendarViewColumn {
id?: string;
fk_view_id?: string;
fk_column_id?: string;
base_id?: string;
source_id?: string;
show?: BoolType;
underline?: BoolType;
bold?: BoolType;
italic?: BoolType;
order?: number;
meta?: MetaType;
constructor(data: CalendarViewColumn) {
Object.assign(this, data);
}
public static async get(calendarViewColumnId: string, ncMeta = Noco.ncMeta) {
let viewColumn =
calendarViewColumnId &&
(await NocoCache.get(
`${CacheScope.CALENDAR_VIEW_COLUMN}:${calendarViewColumnId}`,
CacheGetType.TYPE_OBJECT,
));
if (!viewColumn) {
viewColumn = await ncMeta.metaGet2(
null,
null,
MetaTable.CALENDAR_VIEW_COLUMNS,
calendarViewColumnId,
);
viewColumn.meta =
viewColumn.meta && typeof viewColumn.meta === 'string'
? JSON.parse(viewColumn.meta)
: viewColumn.meta;
}
await NocoCache.set(
`${CacheScope.CALENDAR_VIEW_COLUMN}:${calendarViewColumnId}`,
viewColumn,
);
return viewColumn && new CalendarViewColumn(viewColumn);
}
static async insert(column: Partial<CalendarViewColumn>, ncMeta = Noco.ncMeta) {
const insertObj = extractProps(column, [
'fk_view_id',
'fk_column_id',
'show',
'base_id',
'source_id',
'underline',
'bold',
'italic',
'meta',
]);
insertObj.order = await ncMeta.metaGetNextOrder(
MetaTable.CALENDAR_VIEW_COLUMNS,
{
fk_view_id: insertObj.fk_view_id,
},
);
if (insertObj.meta) {
insertObj.meta = serializeJSON(insertObj.meta);
}
if (!(insertObj.base_id && insertObj.source_id)) {
const viewRef = await View.get(insertObj.fk_view_id, ncMeta);
insertObj.base_id = viewRef.base_id;
insertObj.source_id = viewRef.source_id;
}
const { id, fk_column_id } = await ncMeta.metaInsert2(
null,
null,
MetaTable.CALENDAR_VIEW_COLUMNS,
insertObj,
);
await NocoCache.set(`${CacheScope.CALENDAR_VIEW_COLUMN}:${fk_column_id}`, id);
// if cache is not present skip pushing it into the list to avoid unexpected behaviour
const { list } = await NocoCache.getList(CacheScope.CALENDAR_VIEW_COLUMN, [
column.fk_view_id,
]);
if (list?.length)
await NocoCache.appendToList(
CacheScope.CALENDAR_VIEW_COLUMN,
[column.fk_view_id],
`${CacheScope.CALENDAR_VIEW_COLUMN}:${id}`,
);
return this.get(id, ncMeta);
}
public static async list(
viewId: string,
ncMeta = Noco.ncMeta,
): Promise<CalendarViewColumn[]> {
const cachedList = await NocoCache.getList(CacheScope.CALENDAR_VIEW_COLUMN, [
viewId,
]);
let { list: viewColumns } = cachedList;
const { isNoneList } = cachedList;
if (!isNoneList && !viewColumns.length) {
viewColumns = await ncMeta.metaList2(
null,
null,
MetaTable.CALENDAR_VIEW_COLUMNS,
{
condition: {
fk_view_id: viewId,
},
orderBy: {
order: 'asc',
},
},
);
for (const viewColumn of viewColumns) {
viewColumn.meta = deserializeJSON(viewColumn.meta);
}
await NocoCache.setList(
CacheScope.CALENDAR_VIEW_COLUMN,
[viewId],
viewColumns,
);
}
viewColumns.sort(
(a, b) =>
(a.order != null ? a.order : Infinity) -
(b.order != null ? b.order : Infinity),
);
return viewColumns?.map((v) => new CalendarViewColumn(v));
}
static async update(
columnId: string,
body: Partial<CalendarViewColumn>,
ncMeta = Noco.ncMeta,
) {
const updateObj = extractProps(body, [
'show',
'order',
'meta',
'underline',
'bold',
'italic',
]);
// get existing cache
const key = `${CacheScope.CALENDAR_VIEW_COLUMN}:${columnId}`;
const o = await NocoCache.get(key, CacheGetType.TYPE_OBJECT);
if (o) {
Object.assign(o, updateObj);
// set cache
await NocoCache.set(key, o);
}
if (updateObj.meta) {
updateObj.meta = serializeJSON(updateObj.meta);
}
// update meta
return await ncMeta.metaUpdate(
null,
null,
MetaTable.CALENDAR_VIEW_COLUMNS,
updateObj,
columnId,
);
}
}

34
packages/nocodb/src/schema/swagger.json

@ -14619,6 +14619,10 @@
"type": "integer",
"description": "Kanban Count"
},
"calendarCount": {
"type": "integer",
"description": "Calendar Count"
},
"total": {
"type": "integer",
"description": "Total View Count"
@ -14639,6 +14643,10 @@
"type": "integer",
"description": "Shared Kanban Count"
},
"sharedCalendarCount": {
"type": "integer",
"description": "Shared Calendar Count"
},
"sharedTotal": {
"type": "integer",
"description": "Shared Total View Count"
@ -14704,11 +14712,13 @@
"gridCount": 3,
"galleryCount": 0,
"kanbanCount": 0,
"calendarCount": 0,
"total": 3,
"sharedFormCount": 0,
"sharedGridCount": 0,
"sharedGalleryCount": 0,
"sharedKanbanCount": 0,
"sharedCalendarCount": 0,
"sharedTotal": 0,
"sharedLockedCount": 0
},
@ -14744,11 +14754,13 @@
"gridCount": 3,
"galleryCount": 0,
"kanbanCount": 0,
"calendarCount": 0,
"total": 3,
"sharedFormCount": 0,
"sharedGridCount": 0,
"sharedGalleryCount": 0,
"sharedKanbanCount": 0,
"sharedCalendarCount": 0,
"sharedTotal": 0,
"sharedLockedCount": 0
},
@ -20241,7 +20253,7 @@
"id": "psbv6c6y9qvbu"
}
},
"CalenderDateRange": {
"CalendarDateRange": {
"description": "Model for Calendar Date Range",
"examples": [
{
@ -20286,15 +20298,15 @@
"id": "psbv6c6y9qvbu"
}
},
"CalanderUpdateReq": {
"CalendarUpdateReq": {
"description": "Model for Calendar Update Request",
"examples": [
{
"fk_cover_image_col_id": "cl_ib8l4j1kiu1efx",
"title": "Calander 2"
"title": "Calendar 2"
}
],
"title": "Calander Update Request Model",
"title": "Calendar Update Request Model",
"type": "object",
"properties": {
"fk_cover_image_col_id": {
@ -20306,8 +20318,8 @@
},
"title": {
"type": "string",
"description": "Calander Title",
"example": "Calander 01"
"description": "Calendar Title",
"example": "Calendar 01"
},
"meta": {
"$ref": "#/components/schemas/Meta",
@ -23445,6 +23457,9 @@
},
{
"$ref": "#/components/schemas/Map"
},
{
"$ref": "#/components/schemas/Calendar"
}
],
"description": "Associated View Model"
@ -23627,6 +23642,13 @@
"fk_grp_col_id": "cl_g0a89q9xdry3lu",
"fk_geo_data_col_id": null
},
{
"title": "My Calendar View",
"type": 4,
"copy_from_id": null,
"fk_grp_col_id": null,
"fk_geo_data_col_id": null
},
{
"title": "My Map View",
"type": 5,

9
packages/nocodb/src/utils/globals.ts

@ -21,9 +21,9 @@ export enum MetaTable {
FORM_VIEW_COLUMNS = 'nc_form_view_columns_v2',
GALLERY_VIEW = 'nc_gallery_view_v2',
GALLERY_VIEW_COLUMNS = 'nc_gallery_view_columns_v2',
CALANDER_VIEW = 'nc_calendar_view_v2',
CALANDER_VIEW_COLUMNS = 'nc_calendar_view_columns_v2',
CALANDER_VIEW_RANGE = 'nc_calendar_view_range_v2',
CALENDAR = 'nc_calendar_view_v2',
CALENDAR_VIEW_COLUMNS = 'nc_calendar_view_columns_v2',
CALENDAR_VIEW_RANGE = 'nc_calendar_view_range_v2',
GRID_VIEW = 'nc_grid_view_v2',
GRID_VIEW_COLUMNS = 'nc_grid_view_columns_v2',
KANBAN_VIEW = 'nc_kanban_view_v2',
@ -141,6 +141,9 @@ export enum CacheScope {
GRID_VIEW = 'gridView',
GRID_VIEW_COLUMN = 'gridViewColumn',
KANBAN_VIEW = 'kanbanView',
CALENDAR_VIEW = 'calendarView',
CALENDAR_VIEW_COLUMN = 'calendarViewColumn',
CALENDAR_VIEW_RANGE = 'calendarViewRange',
MAP_VIEW = 'mapView',
MAP_VIEW_COLUMN = 'mapViewColumn',
KANBAN_VIEW_COLUMN = 'kanbanViewColumn',

Loading…
Cancel
Save