|
|
@ -208,11 +208,10 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
|
|
|
|
|
|
|
|
public async onTableDelete( |
|
|
|
public async onTableDelete( |
|
|
|
tn: string, |
|
|
|
tn: string, |
|
|
|
extras?: { ignoreRelations?: boolean } |
|
|
|
extras?: { ignoreVirtualRelations?: boolean; ignoreViews?: boolean } |
|
|
|
): Promise<void> { |
|
|
|
): Promise<void> { |
|
|
|
this.baseLog(`onTableDelete : '%s'`, tn); |
|
|
|
this.baseLog(`onTableDelete : '%s'`, tn); |
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); |
|
|
|
XcCache.del([this.projectId, this.dbAlias, 'table', tn].join('::')); |
|
|
|
if (!extras?.ignoreRelations) |
|
|
|
|
|
|
|
await this.xcMeta.metaDelete( |
|
|
|
await this.xcMeta.metaDelete( |
|
|
|
this.projectId, |
|
|
|
this.projectId, |
|
|
|
this.dbAlias, |
|
|
|
this.dbAlias, |
|
|
@ -230,9 +229,11 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
eq: tn |
|
|
|
eq: tn |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
], |
|
|
|
|
|
|
|
...(extras?.ignoreVirtualRelations ? { type: { eq: 'virtual' } } : {}) |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.deleteTableNameInACL(tn); |
|
|
|
await this.deleteTableNameInACL(tn); |
|
|
|
|
|
|
|
|
|
|
|
await this.xcMeta.metaDelete( |
|
|
|
await this.xcMeta.metaDelete( |
|
|
@ -355,7 +356,7 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
/* update fieldsOrder */ |
|
|
|
/* update fieldsOrder */ |
|
|
|
const index = fieldsOrder.indexOf(alias); |
|
|
|
const index = fieldsOrder.indexOf(alias); |
|
|
|
if (index > -1) { |
|
|
|
if (index > -1) { |
|
|
|
fieldsOrder.splice(index, 0); |
|
|
|
fieldsOrder.splice(index, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* update formView params */ |
|
|
|
/* update formView params */ |
|
|
@ -1030,7 +1031,7 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
/* update fieldsOrder */ |
|
|
|
/* update fieldsOrder */ |
|
|
|
const index = fieldsOrder.indexOf(column.cno); |
|
|
|
const index = fieldsOrder.indexOf(column.cno); |
|
|
|
if (index > -1) { |
|
|
|
if (index > -1) { |
|
|
|
fieldsOrder.splice(index, 0); |
|
|
|
fieldsOrder.splice(index, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* update formView params */ |
|
|
|
/* update formView params */ |
|
|
@ -1531,7 +1532,7 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
/* update fieldsOrder */ |
|
|
|
/* update fieldsOrder */ |
|
|
|
const index = fieldsOrder.indexOf(alias); |
|
|
|
const index = fieldsOrder.indexOf(alias); |
|
|
|
if (index > -1) { |
|
|
|
if (index > -1) { |
|
|
|
fieldsOrder.splice(index, 0); |
|
|
|
fieldsOrder.splice(index, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* update formView params */ |
|
|
|
/* update formView params */ |
|
|
@ -2957,7 +2958,7 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async onTableMetaRecreate(tableName: string): Promise<void> { |
|
|
|
public async onTableMetaRecreate(tableName: string): Promise<void> { |
|
|
|
const meta = this.getMeta(tableName); |
|
|
|
const oldMeta = this.getMeta(tableName); |
|
|
|
|
|
|
|
|
|
|
|
const virtualRelations = await this.xcMeta.metaList( |
|
|
|
const virtualRelations = await this.xcMeta.metaList( |
|
|
|
this.projectId, |
|
|
|
this.projectId, |
|
|
@ -2966,7 +2967,7 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
xcCondition: { |
|
|
|
xcCondition: { |
|
|
|
virtual: true, |
|
|
|
type: 'virtual', |
|
|
|
_or: [ |
|
|
|
_or: [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
tn: { |
|
|
|
tn: { |
|
|
@ -3003,16 +3004,95 @@ export default abstract class BaseApiBuilder<T extends Noco> |
|
|
|
rel.id |
|
|
|
rel.id |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// todo : handle query params
|
|
|
|
|
|
|
|
const oldModelRow = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
this.projectId, |
|
|
|
|
|
|
|
this.dbAlias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ title: tableName } |
|
|
|
|
|
|
|
); |
|
|
|
await this.onTableDelete(tableName, { |
|
|
|
await this.onTableDelete(tableName, { |
|
|
|
ignoreRelations: true, |
|
|
|
ignoreVirtualRelations: true, |
|
|
|
ignoreViews: true |
|
|
|
ignoreViews: true |
|
|
|
} as any); |
|
|
|
} as any); |
|
|
|
|
|
|
|
|
|
|
|
// todo : handle query params
|
|
|
|
let queryParams: any; |
|
|
|
// todo : handle query para
|
|
|
|
try { |
|
|
|
|
|
|
|
queryParams = JSON.parse(oldModelRow.query_params); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
queryParams = {}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
virtualViews, |
|
|
|
|
|
|
|
virtualViewsParamsArr |
|
|
|
|
|
|
|
} = await this.extractSharedAndVirtualViewsParams(tableName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.onTableCreate(tableName, { oldMeta: oldMeta }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const meta = this.getMeta(tableName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (const oldColumn of oldMeta.columns) { |
|
|
|
|
|
|
|
if (meta.columns.find(c => c.c === oldColumn.cn)) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// virtual views param update
|
|
|
|
|
|
|
|
for (const qp of [queryParams, ...virtualViewsParamsArr]) { |
|
|
|
|
|
|
|
if (!qp) continue; |
|
|
|
|
|
|
|
|
|
|
|
await this.onTableCreate(tableName, { oldMeta: meta }); |
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
const { |
|
|
|
|
|
|
|
filters = {}, |
|
|
|
|
|
|
|
sortList = [], |
|
|
|
|
|
|
|
showFields = {}, |
|
|
|
|
|
|
|
fieldsOrder = [], |
|
|
|
|
|
|
|
extraViewParams = {} |
|
|
|
|
|
|
|
} = qp; |
|
|
|
|
|
|
|
/* update sort field */ |
|
|
|
|
|
|
|
const sIndex = (sortList || []).findIndex( |
|
|
|
|
|
|
|
v => v.field === oldColumn.cno |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (sIndex > -1) { |
|
|
|
|
|
|
|
sortList.splice(sIndex, 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* update show field */ |
|
|
|
|
|
|
|
if (oldColumn.cno in showFields) { |
|
|
|
|
|
|
|
delete showFields[oldColumn.cno]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/* update filters */ |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
filters && |
|
|
|
|
|
|
|
JSON.stringify(filters)?.includes(`"${oldColumn.cno}"`) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
filters.splice(0, filters.length); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* update fieldsOrder */ |
|
|
|
|
|
|
|
const index = fieldsOrder.indexOf(oldColumn.cno); |
|
|
|
|
|
|
|
if (index > -1) { |
|
|
|
|
|
|
|
fieldsOrder.splice(index, 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* update formView params */ |
|
|
|
|
|
|
|
// extraViewParams.formParams.fields
|
|
|
|
|
|
|
|
if (extraViewParams?.formParams?.fields?.[oldColumn.cno]) { |
|
|
|
|
|
|
|
delete extraViewParams.formParams.fields[oldColumn.cno]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.updateSharedAndVirtualViewsParams( |
|
|
|
|
|
|
|
virtualViewsParamsArr, |
|
|
|
|
|
|
|
virtualViews |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await this.xcMeta.metaUpdate( |
|
|
|
|
|
|
|
this.projectId, |
|
|
|
|
|
|
|
this.dbAlias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
query_params: JSON.stringify(queryParams) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ title: tableName, type: 'table' } |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async getOrderVal(): Promise<number> { |
|
|
|
protected async getOrderVal(): Promise<number> { |
|
|
|