mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
chore: support update field attribute in collection (#5643)
This commit is contained in:
parent
6198c99706
commit
9fe1775ca3
@ -76,6 +76,15 @@ export class Collection implements ICollection {
|
||||
return this.fields.get(name);
|
||||
}
|
||||
|
||||
getFieldByField(field: string): IField {
|
||||
for (const item of this.fields.values()) {
|
||||
if (item.options.field === field) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getFields() {
|
||||
return [...this.fields.values()];
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ export interface ICollection {
|
||||
|
||||
getField(name: string): IField;
|
||||
|
||||
getFieldByField(field: string): IField;
|
||||
|
||||
[key: string]: any;
|
||||
|
||||
unavailableActions?: () => string[];
|
||||
|
@ -369,6 +369,10 @@ export class Collection<
|
||||
return this.fields.get(name);
|
||||
}
|
||||
|
||||
getFieldByField(field: string): Field {
|
||||
return this.findField((f) => f.options.field === field);
|
||||
}
|
||||
|
||||
getFields() {
|
||||
return [...this.fields.values()];
|
||||
}
|
||||
|
@ -20,13 +20,27 @@ export class DataSourcesFieldModel extends MagicAttributeModel {
|
||||
const { app } = loadOptions;
|
||||
|
||||
const options = this.get();
|
||||
const { collectionName, name, dataSourceKey } = options;
|
||||
const { collectionName, name, dataSourceKey, field } = options;
|
||||
const dataSource = app.dataSourceManager.dataSources.get(dataSourceKey);
|
||||
const collection = dataSource.collectionManager.getCollection(collectionName);
|
||||
const oldField = collection.getField(name);
|
||||
|
||||
const oldFieldByName = collection.getField(name);
|
||||
const oldFieldByField = field ? collection.getFieldByField(field) : null;
|
||||
|
||||
const oldField = oldFieldByField || oldFieldByName;
|
||||
const newOptions = mergeOptions(oldField ? oldField.options : {}, options);
|
||||
|
||||
collection.setField(name, newOptions);
|
||||
|
||||
if (oldFieldByField && !oldFieldByName) {
|
||||
const filedShouldRemove = collection
|
||||
.getFields()
|
||||
.filter((f) => f.options.field === field && f.options.name !== name);
|
||||
|
||||
for (const f of filedShouldRemove) {
|
||||
collection.removeField(f.options.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unload(loadOptions: LoadOptions) {
|
||||
|
@ -67,20 +67,22 @@ export default {
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await mainDb.getRepository('dataSourcesFields').update({
|
||||
filter: {
|
||||
name,
|
||||
collectionName,
|
||||
dataSourceKey,
|
||||
},
|
||||
values,
|
||||
});
|
||||
fieldRecord = (
|
||||
await mainDb.getRepository('dataSourcesFields').update({
|
||||
filter: {
|
||||
name,
|
||||
collectionName,
|
||||
dataSourceKey,
|
||||
},
|
||||
values,
|
||||
})
|
||||
)[0];
|
||||
}
|
||||
|
||||
const field = ctx.app.dataSourceManager.dataSources
|
||||
.get(dataSourceKey)
|
||||
.collectionManager.getCollection(collectionName)
|
||||
.getField(name);
|
||||
.getField(fieldRecord.get('name'));
|
||||
|
||||
ctx.body = field.options;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user