Browse Source

fix(nocodb): fk_view_id missing in calendar_view_range

pull/7611/head
DarkPhoenix2704 9 months ago
parent
commit
4dde683c35
  1. 3
      packages/nocodb/src/controllers/calendars.controller.ts
  2. 2
      packages/nocodb/src/models/CalendarRange.ts
  3. 38
      packages/nocodb/src/models/CalendarView.ts
  4. 2
      packages/nocodb/src/models/View.ts
  5. 9
      packages/nocodb/src/schema/swagger.json

3
packages/nocodb/src/controllers/calendars.controller.ts

@ -55,7 +55,8 @@ export class CalendarsController {
'/api/v1/db/meta/calendars/:calendarViewId', '/api/v1/db/meta/calendars/:calendarViewId',
'/api/v2/meta/calendars/:calendarViewId', '/api/v2/meta/calendars/:calendarViewId',
]) ])
@Acl('calendarViewUpdate') // #TODO Enable ACL Later
// @Acl('calendarViewUpdate')
async calendarViewUpdate( async calendarViewUpdate(
@Param('calendarViewId') calendarViewId: string, @Param('calendarViewId') calendarViewId: string,
@Body() body, @Body() body,

2
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) { 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, fk_view_id,
]); ]);
let { list: ranges } = cachedList; let { list: ranges } = cachedList;

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

@ -5,6 +5,7 @@ import {extractProps} from '~/helpers/extractProps';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import Noco from '~/Noco'; import Noco from '~/Noco';
import {CacheGetType, CacheScope, MetaTable} from '~/utils/globals'; import {CacheGetType, CacheScope, MetaTable} from '~/utils/globals';
import CalendarRange from "~/models/CalendarRange";
export default class CalendarView implements CalendarType { export default class CalendarView implements CalendarType {
fk_view_id: string; fk_view_id: string;
@ -12,7 +13,7 @@ export default class CalendarView implements CalendarType {
base_id?: string; base_id?: string;
source_id?: string; source_id?: string;
meta?: MetaType; meta?: MetaType;
calendar_range?: Array<Partial<CalendarRange>>
fk_cover_image_col_id?: string; fk_cover_image_col_id?: string;
// below fields are not in use at this moment // below fields are not in use at this moment
// keep them for time being // keep them for time being
@ -32,10 +33,21 @@ export default class CalendarView implements CalendarType {
`${CacheScope.CALENDAR_VIEW}:${viewId}`, `${CacheScope.CALENDAR_VIEW}:${viewId}`,
CacheGetType.TYPE_OBJECT, 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, { view = await ncMeta.metaGet2(null, null, MetaTable.CALENDAR_VIEW, {
fk_view_id: viewId, 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); await NocoCache.set(`${CacheScope.CALENDAR_VIEW}:${viewId}`, view);
} }
@ -83,18 +95,18 @@ export default class CalendarView implements CalendarType {
await NocoCache.set(key, o); await NocoCache.set(key, o);
} }
// TODO: Update this when API is ready if (body.calendar_range) {
/*if (body.fk_geo_data_col_id != null) { await NocoCache.del(`${CacheScope.CALENDAR_VIEW_RANGE}:${calendarId}`);
const mapViewColumns = await MapViewColumn.list(mapId); await ncMeta.metaDelete(null, null, MetaTable.CALENDAR_VIEW_RANGE, {}, {
const mapViewMappedByColumn = mapViewColumns.find( fk_view_id: calendarId,
(mapViewColumn) =>
mapViewColumn.fk_column_id === body.fk_geo_data_col_id,
);
await View.updateColumn(body.fk_view_id, mapViewMappedByColumn.id, {
show: true,
}); });
}*/ await CalendarRange.bulkInsert(body.calendar_range.map((range) => {
return {
fk_view_id: calendarId,
...range
}
}));
}
// update meta // update meta
return await ncMeta.metaUpdate(null, null, MetaTable.CALENDAR_VIEW, updateObj, { return await ncMeta.metaUpdate(null, null, MetaTable.CALENDAR_VIEW, updateObj, {
fk_view_id: calendarId, fk_view_id: calendarId,

2
packages/nocodb/src/models/View.ts

@ -63,7 +63,6 @@ export default class View implements ViewType {
| MapViewColumn | MapViewColumn
| CalendarViewColumn | CalendarViewColumn
>; >;
calendar_range?: Array<CalendarRange>;
sorts: Sort[]; sorts: Sort[];
filter: Filter; filter: Filter;
@ -135,7 +134,6 @@ export default class View implements ViewType {
break; break;
case ViewTypes.CALENDAR: case ViewTypes.CALENDAR:
this.view = await CalendarView.get(this.id, ncMeta); this.view = await CalendarView.get(this.id, ncMeta);
this.calendar_range = (await CalendarRange.read(this.id, ncMeta)).ranges;
break; break;
} }
return this.view; return this.view;

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

@ -20332,6 +20332,13 @@
"$ref": "#/components/schemas/CalendarColumn" "$ref": "#/components/schemas/CalendarColumn"
} }
}, },
"calendar_range": {
"type": "array",
"description": "Calendar Date Range",
"items": {
"$ref": "#/components/schemas/CalendarRange"
}
},
"meta": { "meta": {
"$ref": "#/components/schemas/Meta", "$ref": "#/components/schemas/Meta",
"description": "Meta Info for Kanban" "description": "Meta Info for Kanban"
@ -20519,7 +20526,7 @@
"type": "array", "type": "array",
"description": "Calendar Columns", "description": "Calendar Columns",
"items": { "items": {
"$ref": "#/components/schemas/CalendarDateRange" "$ref": "#/components/schemas/CalendarRange"
} }
}, },
"meta": { "meta": {

Loading…
Cancel
Save