Browse Source

enhancement: add download to View

pull/2552/head
Wing-Kam Wong 2 years ago
parent
commit
b89f79a02d
  1. 108
      packages/nocodb/src/lib/models/View.ts

108
packages/nocodb/src/lib/models/View.ts

@ -3,7 +3,7 @@ import {
CacheDelDirection, CacheDelDirection,
CacheGetType, CacheGetType,
CacheScope, CacheScope,
MetaTable MetaTable,
} from '../utils/globals'; } from '../utils/globals';
import Model from './Model'; import Model from './Model';
import FormView from './FormView'; import FormView from './FormView';
@ -42,6 +42,7 @@ export default class View implements ViewType {
project_id?: string; project_id?: string;
base_id?: string; base_id?: string;
show_system_fields?: boolean; show_system_fields?: boolean;
download?: boolean;
constructor(data: View) { constructor(data: View) {
Object.assign(this, data); Object.assign(this, data);
@ -135,15 +136,15 @@ export default class View implements ViewType {
_or: [ _or: [
{ {
id: { id: {
eq: titleOrId eq: titleOrId,
} },
}, },
{ {
title: { title: {
eq: titleOrId eq: titleOrId,
} },
} },
] ],
} }
); );
// todo: cache - titleOrId can be viewId so we need a different scope here // todo: cache - titleOrId can be viewId so we need a different scope here
@ -174,7 +175,7 @@ export default class View implements ViewType {
MetaTable.VIEWS, MetaTable.VIEWS,
{ {
fk_model_id, fk_model_id,
is_default: 1 is_default: 1,
}, },
null null
); );
@ -188,11 +189,11 @@ export default class View implements ViewType {
if (!viewsList.length) { if (!viewsList.length) {
viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
condition: { condition: {
fk_model_id: modelId fk_model_id: modelId,
}, },
orderBy: { orderBy: {
order: 'asc' order: 'asc',
} },
}); });
await NocoCache.setList(CacheScope.VIEW, [modelId], viewsList); await NocoCache.setList(CacheScope.VIEW, [modelId], viewsList);
} }
@ -201,13 +202,13 @@ export default class View implements ViewType {
(a.order != null ? a.order : Infinity) - (a.order != null ? a.order : Infinity) -
(b.order != null ? b.order : Infinity) (b.order != null ? b.order : Infinity)
); );
return viewsList?.map(v => new View(v)); return viewsList?.map((v) => new View(v));
} }
public async getFilters(ncMeta = Noco.ncMeta) { public async getFilters(ncMeta = Noco.ncMeta) {
return (this.filter = (await Filter.getFilterObject( return (this.filter = (await Filter.getFilterObject(
{ {
viewId: this.id viewId: this.id,
}, },
ncMeta ncMeta
)) as any); )) as any);
@ -228,7 +229,7 @@ export default class View implements ViewType {
) { ) {
// get order value // get order value
const order = await ncMeta.metaGetNextOrder(MetaTable.VIEWS, { const order = await ncMeta.metaGetNextOrder(MetaTable.VIEWS, {
fk_model_id: view.fk_model_id fk_model_id: view.fk_model_id,
}); });
const insertObj = { const insertObj = {
@ -242,7 +243,7 @@ export default class View implements ViewType {
project_id: view.project_id, project_id: view.project_id,
base_id: view.base_id, base_id: view.base_id,
created_at: view.created_at, created_at: view.created_at,
updated_at: view.updated_at updated_at: view.updated_at,
}; };
// get project and base id if missing // get project and base id if missing
@ -275,7 +276,7 @@ export default class View implements ViewType {
await GridView.insert( await GridView.insert(
{ {
...(view as GridView), ...(view as GridView),
fk_view_id: view_id fk_view_id: view_id,
}, },
ncMeta ncMeta
); );
@ -285,7 +286,7 @@ export default class View implements ViewType {
{ {
...(copyFromView?.view || {}), ...(copyFromView?.view || {}),
...view, ...view,
fk_view_id: view_id fk_view_id: view_id,
}, },
ncMeta ncMeta
); );
@ -296,7 +297,7 @@ export default class View implements ViewType {
heading: view.title, heading: view.title,
...(copyFromView?.view || {}), ...(copyFromView?.view || {}),
...view, ...view,
fk_view_id: view_id fk_view_id: view_id,
}, },
ncMeta ncMeta
); );
@ -317,7 +318,7 @@ export default class View implements ViewType {
{ {
...sort, ...sort,
fk_view_id: view_id, fk_view_id: view_id,
id: null id: null,
}, },
ncMeta ncMeta
); );
@ -328,7 +329,7 @@ export default class View implements ViewType {
{ {
...filter, ...filter,
fk_view_id: view_id, fk_view_id: view_id,
id: null id: null,
}, },
ncMeta ncMeta
); );
@ -353,7 +354,7 @@ export default class View implements ViewType {
view_id, view_id,
fk_column_id: vCol.fk_column_id || vCol.id, fk_column_id: vCol.fk_column_id || vCol.id,
show, show,
id: null id: null,
}, },
ncMeta ncMeta
); );
@ -376,7 +377,7 @@ export default class View implements ViewType {
fk_column_id: param.fk_column_id, fk_column_id: param.fk_column_id,
fk_model_id: param.fk_model_id, fk_model_id: param.fk_model_id,
order: param.order, order: param.order,
show: param.show show: param.show,
}; };
const views = await this.list(param.fk_model_id, ncMeta); const views = await this.list(param.fk_model_id, ncMeta);
@ -386,7 +387,7 @@ export default class View implements ViewType {
await GridViewColumn.insert( await GridViewColumn.insert(
{ {
...insertObj, ...insertObj,
fk_view_id: view.id fk_view_id: view.id,
}, },
ncMeta ncMeta
); );
@ -395,7 +396,7 @@ export default class View implements ViewType {
await GalleryViewColumn.insert( await GalleryViewColumn.insert(
{ {
...insertObj, ...insertObj,
fk_view_id: view.id fk_view_id: view.id,
}, },
ncMeta ncMeta
); );
@ -423,7 +424,7 @@ export default class View implements ViewType {
col = await GridViewColumn.insert( col = await GridViewColumn.insert(
{ {
...param, ...param,
fk_view_id: view.id fk_view_id: view.id,
}, },
ncMeta ncMeta
); );
@ -434,7 +435,7 @@ export default class View implements ViewType {
col = await GalleryViewColumn.insert( col = await GalleryViewColumn.insert(
{ {
...param, ...param,
fk_view_id: view.id fk_view_id: view.id,
}, },
ncMeta ncMeta
); );
@ -445,7 +446,7 @@ export default class View implements ViewType {
col = await FormViewColumn.insert( col = await FormViewColumn.insert(
{ {
...param, ...param,
fk_view_id: view.id fk_view_id: view.id,
}, },
ncMeta ncMeta
); );
@ -525,7 +526,7 @@ export default class View implements ViewType {
} }
const updateObj = { const updateObj = {
order: colData.order, order: colData.order,
show: colData.show show: colData.show,
}; };
// get existing cache // get existing cache
const key = `${cacheScope}:${colId}`; const key = `${cacheScope}:${colId}`;
@ -556,7 +557,7 @@ export default class View implements ViewType {
const existingCol = await ncMeta.metaGet2(null, null, table, { const existingCol = await ncMeta.metaGet2(null, null, table, {
fk_view_id: viewId, fk_view_id: viewId,
fk_column_id: fkColId fk_column_id: fkColId,
}); });
if (existingCol) { if (existingCol) {
@ -566,7 +567,7 @@ export default class View implements ViewType {
table, table,
{ {
order: colData.order, order: colData.order,
show: colData.show show: colData.show,
}, },
existingCol.id existingCol.id
); );
@ -576,14 +577,14 @@ export default class View implements ViewType {
fk_view_id: viewId, fk_view_id: viewId,
fk_column_id: fkColId, fk_column_id: fkColId,
order: colData.order, order: colData.order,
show: colData.show show: colData.show,
}); });
} }
} }
static async getByUUID(uuid: string, ncMeta = Noco.ncMeta) { static async getByUUID(uuid: string, ncMeta = Noco.ncMeta) {
const view = await ncMeta.metaGet2(null, null, MetaTable.VIEWS, { const view = await ncMeta.metaGet2(null, null, MetaTable.VIEWS, {
uuid uuid,
}); });
return view && new View(view); return view && new View(view);
@ -609,7 +610,7 @@ export default class View implements ViewType {
null, null,
MetaTable.VIEWS, MetaTable.VIEWS,
{ {
uuid: view.uuid uuid: view.uuid,
}, },
viewId viewId
); );
@ -638,7 +639,7 @@ export default class View implements ViewType {
null, null,
MetaTable.VIEWS, MetaTable.VIEWS,
{ {
password password,
}, },
viewId viewId
); );
@ -660,7 +661,7 @@ export default class View implements ViewType {
null, null,
MetaTable.VIEWS, MetaTable.VIEWS,
{ {
uuid: null uuid: null,
}, },
viewId viewId
); );
@ -684,7 +685,8 @@ export default class View implements ViewType {
'show_system_fields', 'show_system_fields',
'lock_type', 'lock_type',
'password', 'password',
'uuid' 'download',
'uuid',
]); ]);
// get existing cache // get existing cache
const key = `${CacheScope.VIEW}:${viewId}`; const key = `${CacheScope.VIEW}:${viewId}`;
@ -713,7 +715,7 @@ export default class View implements ViewType {
const columnTable = this.extractViewColumnsTableName(view); const columnTable = this.extractViewColumnsTableName(view);
const columnTableScope = this.extractViewColumnsTableNameScope(view); const columnTableScope = this.extractViewColumnsTableNameScope(view);
await ncMeta.metaDelete(null, null, columnTable, { await ncMeta.metaDelete(null, null, columnTable, {
fk_view_id: viewId fk_view_id: viewId,
}); });
await NocoCache.deepDel( await NocoCache.deepDel(
tableScope, tableScope,
@ -721,7 +723,7 @@ export default class View implements ViewType {
CacheDelDirection.CHILD_TO_PARENT CacheDelDirection.CHILD_TO_PARENT
); );
await ncMeta.metaDelete(null, null, table, { await ncMeta.metaDelete(null, null, table, {
fk_view_id: viewId fk_view_id: viewId,
}); });
await NocoCache.deepDel( await NocoCache.deepDel(
columnTableScope, columnTableScope,
@ -840,15 +842,15 @@ export default class View implements ViewType {
table, table,
{ show: true }, { show: true },
{ {
fk_view_id: viewId fk_view_id: viewId,
}, },
ignoreColdIds?.length ignoreColdIds?.length
? { ? {
_not: { _not: {
fk_column_id: { fk_column_id: {
in: ignoreColdIds in: ignoreColdIds,
} },
} },
} }
: null : null
); );
@ -881,15 +883,15 @@ export default class View implements ViewType {
table, table,
{ show: false }, { show: false },
{ {
fk_view_id: viewId fk_view_id: viewId,
}, },
ignoreColdIds?.length ignoreColdIds?.length
? { ? {
_not: { _not: {
fk_column_id: { fk_column_id: {
in: ignoreColdIds in: ignoreColdIds,
} },
} },
} }
: null : null
); );
@ -905,18 +907,18 @@ export default class View implements ViewType {
sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, {
xcCondition: { xcCondition: {
fk_model_id: { fk_model_id: {
eq: tableId eq: tableId,
}, },
_not: { _not: {
uuid: { uuid: {
eq: null eq: null,
} },
} },
} },
}); });
await NocoCache.setList(CacheScope.VIEW, [tableId], sharedViews); await NocoCache.setList(CacheScope.VIEW, [tableId], sharedViews);
} }
sharedViews = sharedViews.filter(v => v.uuid !== null); sharedViews = sharedViews.filter((v) => v.uuid !== null);
return sharedViews?.map(v => new View(v)); return sharedViews?.map((v) => new View(v));
} }
} }

Loading…
Cancel
Save