From 4dde683c35be632d0e8d70d101d432d960ed6d7e Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:15:47 +0000 Subject: [PATCH] fix(nocodb): fk_view_id missing in calendar_view_range --- .../src/controllers/calendars.controller.ts | 3 +- packages/nocodb/src/models/CalendarRange.ts | 2 +- packages/nocodb/src/models/CalendarView.ts | 38 ++++++++++++------- packages/nocodb/src/models/View.ts | 2 - packages/nocodb/src/schema/swagger.json | 9 ++++- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/packages/nocodb/src/controllers/calendars.controller.ts b/packages/nocodb/src/controllers/calendars.controller.ts index 3d0c14120e..2b71a8fab3 100644 --- a/packages/nocodb/src/controllers/calendars.controller.ts +++ b/packages/nocodb/src/controllers/calendars.controller.ts @@ -55,7 +55,8 @@ export class CalendarsController { '/api/v1/db/meta/calendars/:calendarViewId', '/api/v2/meta/calendars/:calendarViewId', ]) - @Acl('calendarViewUpdate') + // #TODO Enable ACL Later + // @Acl('calendarViewUpdate') async calendarViewUpdate( @Param('calendarViewId') calendarViewId: string, @Body() body, diff --git a/packages/nocodb/src/models/CalendarRange.ts b/packages/nocodb/src/models/CalendarRange.ts index f6bd4bde3e..53687bcbac 100644 --- a/packages/nocodb/src/models/CalendarRange.ts +++ b/packages/nocodb/src/models/CalendarRange.ts @@ -100,7 +100,7 @@ export default class CalendarRange implements CalendarRangeType { } public static async read(fk_view_id: string, ncMeta = Noco.ncMeta) { - const cachedList = await NocoCache.getList(CacheScope.CALENDAR_VIEW, [ + const cachedList = await NocoCache.getList(CacheScope.CALENDAR_VIEW_RANGE, [ fk_view_id, ]); let { list: ranges } = cachedList; diff --git a/packages/nocodb/src/models/CalendarView.ts b/packages/nocodb/src/models/CalendarView.ts index eb0fbc7ecd..e11b11993b 100644 --- a/packages/nocodb/src/models/CalendarView.ts +++ b/packages/nocodb/src/models/CalendarView.ts @@ -5,6 +5,7 @@ import {extractProps} from '~/helpers/extractProps'; import NocoCache from '~/cache/NocoCache'; import Noco from '~/Noco'; import {CacheGetType, CacheScope, MetaTable} from '~/utils/globals'; +import CalendarRange from "~/models/CalendarRange"; export default class CalendarView implements CalendarType { fk_view_id: string; @@ -12,7 +13,7 @@ export default class CalendarView implements CalendarType { base_id?: string; source_id?: string; meta?: MetaType; - + calendar_range?: Array> fk_cover_image_col_id?: string; // below fields are not in use at this moment // keep them for time being @@ -32,10 +33,21 @@ export default class CalendarView implements CalendarType { `${CacheScope.CALENDAR_VIEW}:${viewId}`, CacheGetType.TYPE_OBJECT, )); - if (!view) { + if (view) { + const calendarRange = await CalendarRange.read(viewId, ncMeta); + if (calendarRange) { + view.calendar_range = calendarRange.ranges; + } else { + view.calendar_range = []; + } + } else { view = await ncMeta.metaGet2(null, null, MetaTable.CALENDAR_VIEW, { fk_view_id: viewId, }); + const calendarRange = await CalendarRange.read(viewId); + if (calendarRange) { + view.calendar_range = calendarRange.ranges; + } await NocoCache.set(`${CacheScope.CALENDAR_VIEW}:${viewId}`, view); } @@ -83,18 +95,18 @@ export default class CalendarView implements CalendarType { 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, + if (body.calendar_range) { + await NocoCache.del(`${CacheScope.CALENDAR_VIEW_RANGE}:${calendarId}`); + await ncMeta.metaDelete(null, null, MetaTable.CALENDAR_VIEW_RANGE, {}, { + fk_view_id: calendarId, }); - }*/ - + await CalendarRange.bulkInsert(body.calendar_range.map((range) => { + return { + fk_view_id: calendarId, + ...range + } + })); + } // update meta return await ncMeta.metaUpdate(null, null, MetaTable.CALENDAR_VIEW, updateObj, { fk_view_id: calendarId, diff --git a/packages/nocodb/src/models/View.ts b/packages/nocodb/src/models/View.ts index c523030d11..cd7464d801 100644 --- a/packages/nocodb/src/models/View.ts +++ b/packages/nocodb/src/models/View.ts @@ -63,7 +63,6 @@ export default class View implements ViewType { | MapViewColumn | CalendarViewColumn >; - calendar_range?: Array; sorts: Sort[]; filter: Filter; @@ -135,7 +134,6 @@ export default class View implements ViewType { break; case ViewTypes.CALENDAR: this.view = await CalendarView.get(this.id, ncMeta); - this.calendar_range = (await CalendarRange.read(this.id, ncMeta)).ranges; break; } return this.view; diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index c60e89419c..14123abbbe 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -20332,6 +20332,13 @@ "$ref": "#/components/schemas/CalendarColumn" } }, + "calendar_range": { + "type": "array", + "description": "Calendar Date Range", + "items": { + "$ref": "#/components/schemas/CalendarRange" + } + }, "meta": { "$ref": "#/components/schemas/Meta", "description": "Meta Info for Kanban" @@ -20519,7 +20526,7 @@ "type": "array", "description": "Calendar Columns", "items": { - "$ref": "#/components/schemas/CalendarDateRange" + "$ref": "#/components/schemas/CalendarRange" } }, "meta": {