From b89f79a02d311ea9a63cc0102704d6370565a288 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 4 Jul 2022 20:01:33 +0800 Subject: [PATCH] enhancement: add download to View --- packages/nocodb/src/lib/models/View.ts | 108 +++++++++++++------------ 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/packages/nocodb/src/lib/models/View.ts b/packages/nocodb/src/lib/models/View.ts index 02d29ff654..3ceceb8ba6 100644 --- a/packages/nocodb/src/lib/models/View.ts +++ b/packages/nocodb/src/lib/models/View.ts @@ -3,7 +3,7 @@ import { CacheDelDirection, CacheGetType, CacheScope, - MetaTable + MetaTable, } from '../utils/globals'; import Model from './Model'; import FormView from './FormView'; @@ -42,6 +42,7 @@ export default class View implements ViewType { project_id?: string; base_id?: string; show_system_fields?: boolean; + download?: boolean; constructor(data: View) { Object.assign(this, data); @@ -135,15 +136,15 @@ export default class View implements ViewType { _or: [ { id: { - eq: titleOrId - } + eq: titleOrId, + }, }, { title: { - eq: titleOrId - } - } - ] + eq: titleOrId, + }, + }, + ], } ); // 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, { fk_model_id, - is_default: 1 + is_default: 1, }, null ); @@ -188,11 +189,11 @@ export default class View implements ViewType { if (!viewsList.length) { viewsList = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { condition: { - fk_model_id: modelId + fk_model_id: modelId, }, orderBy: { - order: 'asc' - } + order: 'asc', + }, }); await NocoCache.setList(CacheScope.VIEW, [modelId], viewsList); } @@ -201,13 +202,13 @@ export default class View implements ViewType { (a.order != null ? a.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) { return (this.filter = (await Filter.getFilterObject( { - viewId: this.id + viewId: this.id, }, ncMeta )) as any); @@ -228,7 +229,7 @@ export default class View implements ViewType { ) { // get order value const order = await ncMeta.metaGetNextOrder(MetaTable.VIEWS, { - fk_model_id: view.fk_model_id + fk_model_id: view.fk_model_id, }); const insertObj = { @@ -242,7 +243,7 @@ export default class View implements ViewType { project_id: view.project_id, base_id: view.base_id, created_at: view.created_at, - updated_at: view.updated_at + updated_at: view.updated_at, }; // get project and base id if missing @@ -275,7 +276,7 @@ export default class View implements ViewType { await GridView.insert( { ...(view as GridView), - fk_view_id: view_id + fk_view_id: view_id, }, ncMeta ); @@ -285,7 +286,7 @@ export default class View implements ViewType { { ...(copyFromView?.view || {}), ...view, - fk_view_id: view_id + fk_view_id: view_id, }, ncMeta ); @@ -296,7 +297,7 @@ export default class View implements ViewType { heading: view.title, ...(copyFromView?.view || {}), ...view, - fk_view_id: view_id + fk_view_id: view_id, }, ncMeta ); @@ -317,7 +318,7 @@ export default class View implements ViewType { { ...sort, fk_view_id: view_id, - id: null + id: null, }, ncMeta ); @@ -328,7 +329,7 @@ export default class View implements ViewType { { ...filter, fk_view_id: view_id, - id: null + id: null, }, ncMeta ); @@ -353,7 +354,7 @@ export default class View implements ViewType { view_id, fk_column_id: vCol.fk_column_id || vCol.id, show, - id: null + id: null, }, ncMeta ); @@ -376,7 +377,7 @@ export default class View implements ViewType { fk_column_id: param.fk_column_id, fk_model_id: param.fk_model_id, order: param.order, - show: param.show + show: param.show, }; const views = await this.list(param.fk_model_id, ncMeta); @@ -386,7 +387,7 @@ export default class View implements ViewType { await GridViewColumn.insert( { ...insertObj, - fk_view_id: view.id + fk_view_id: view.id, }, ncMeta ); @@ -395,7 +396,7 @@ export default class View implements ViewType { await GalleryViewColumn.insert( { ...insertObj, - fk_view_id: view.id + fk_view_id: view.id, }, ncMeta ); @@ -423,7 +424,7 @@ export default class View implements ViewType { col = await GridViewColumn.insert( { ...param, - fk_view_id: view.id + fk_view_id: view.id, }, ncMeta ); @@ -434,7 +435,7 @@ export default class View implements ViewType { col = await GalleryViewColumn.insert( { ...param, - fk_view_id: view.id + fk_view_id: view.id, }, ncMeta ); @@ -445,7 +446,7 @@ export default class View implements ViewType { col = await FormViewColumn.insert( { ...param, - fk_view_id: view.id + fk_view_id: view.id, }, ncMeta ); @@ -525,7 +526,7 @@ export default class View implements ViewType { } const updateObj = { order: colData.order, - show: colData.show + show: colData.show, }; // get existing cache const key = `${cacheScope}:${colId}`; @@ -556,7 +557,7 @@ export default class View implements ViewType { const existingCol = await ncMeta.metaGet2(null, null, table, { fk_view_id: viewId, - fk_column_id: fkColId + fk_column_id: fkColId, }); if (existingCol) { @@ -566,7 +567,7 @@ export default class View implements ViewType { table, { order: colData.order, - show: colData.show + show: colData.show, }, existingCol.id ); @@ -576,14 +577,14 @@ export default class View implements ViewType { fk_view_id: viewId, fk_column_id: fkColId, order: colData.order, - show: colData.show + show: colData.show, }); } } static async getByUUID(uuid: string, ncMeta = Noco.ncMeta) { const view = await ncMeta.metaGet2(null, null, MetaTable.VIEWS, { - uuid + uuid, }); return view && new View(view); @@ -609,7 +610,7 @@ export default class View implements ViewType { null, MetaTable.VIEWS, { - uuid: view.uuid + uuid: view.uuid, }, viewId ); @@ -638,7 +639,7 @@ export default class View implements ViewType { null, MetaTable.VIEWS, { - password + password, }, viewId ); @@ -660,7 +661,7 @@ export default class View implements ViewType { null, MetaTable.VIEWS, { - uuid: null + uuid: null, }, viewId ); @@ -684,7 +685,8 @@ export default class View implements ViewType { 'show_system_fields', 'lock_type', 'password', - 'uuid' + 'download', + 'uuid', ]); // get existing cache const key = `${CacheScope.VIEW}:${viewId}`; @@ -713,7 +715,7 @@ export default class View implements ViewType { const columnTable = this.extractViewColumnsTableName(view); const columnTableScope = this.extractViewColumnsTableNameScope(view); await ncMeta.metaDelete(null, null, columnTable, { - fk_view_id: viewId + fk_view_id: viewId, }); await NocoCache.deepDel( tableScope, @@ -721,7 +723,7 @@ export default class View implements ViewType { CacheDelDirection.CHILD_TO_PARENT ); await ncMeta.metaDelete(null, null, table, { - fk_view_id: viewId + fk_view_id: viewId, }); await NocoCache.deepDel( columnTableScope, @@ -840,15 +842,15 @@ export default class View implements ViewType { table, { show: true }, { - fk_view_id: viewId + fk_view_id: viewId, }, ignoreColdIds?.length ? { _not: { fk_column_id: { - in: ignoreColdIds - } - } + in: ignoreColdIds, + }, + }, } : null ); @@ -881,15 +883,15 @@ export default class View implements ViewType { table, { show: false }, { - fk_view_id: viewId + fk_view_id: viewId, }, ignoreColdIds?.length ? { _not: { fk_column_id: { - in: ignoreColdIds - } - } + in: ignoreColdIds, + }, + }, } : null ); @@ -905,18 +907,18 @@ export default class View implements ViewType { sharedViews = await ncMeta.metaList2(null, null, MetaTable.VIEWS, { xcCondition: { fk_model_id: { - eq: tableId + eq: tableId, }, _not: { uuid: { - eq: null - } - } - } + eq: null, + }, + }, + }, }); await NocoCache.setList(CacheScope.VIEW, [tableId], sharedViews); } - sharedViews = sharedViews.filter(v => v.uuid !== null); - return sharedViews?.map(v => new View(v)); + sharedViews = sharedViews.filter((v) => v.uuid !== null); + return sharedViews?.map((v) => new View(v)); } }