mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-04 21:19:27 +08:00
* feat: environments plugin * feat: improve code * fix: improve code * feat: improve code * refactor: package description * feat: bulk import * fix: remove * refactor: file manager support environment variables * refactor: file manager support environment variables * refactor: map manager support environment variables * refactor: support environment variables * refactor: support environment variables * refactor: support delete environment variables * fix: bug * refactor: workflow support environment variables * refactor: email environment variables * refactor: support bulk import * refactor: support bulk import * refactor: support bulk import * refactor: support bulk import * refactor: code improve * feat: env * chore: update * feat: environment * fix: bug * fix: acl snippet * fix: acl snippets * chore: map manager * refactor: support line break * refactor: support password * chore: environment variables * fix: bug * fix: bug * chore: enviroment variables * chore: system settings * fix: improve code * feat: verification * feat: map * feat: file-manager * feat: notification * fix: bug * feat: workflow * fix: improve code * fix: bug * feat: data-source * feat: auth * fix: error * fix: bug * refactor: description * refactor: locale * refactor: locale * refactor: locale * refactor: code improve * refactor: locale * refactor: locale * style: style improve * fix: error * fix: bug * fix: bug * refactor: environment * fix: ellipsis * refactor: password * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug * chore: test * fix: cache * fix: mysql dialect options * refactor: email config form * fix: bug * fix: bug * fix: authenticator.dataValues parse * fix: include undefined * fix: json * fix: json parse * chore: enviromentProvider * fix: acl * fix: rowKey * fix: update ProviderOptions.tsx * feat: get app instance * fix: bug * fix: text * fix: build error * fix: error * chore: migration rules options * chore: migration rules * refactor: code improve * feat: env v2 * chore: environment varibales * chore: environment serve * fix: getVariables * feat: improve code * fix: bug * chore: collection options for migration * chore: tree collection options * chore: migration rules * chore: migration rules * chore: env api * chore: env api * fix: optionsKeysNotAllowedInEnv * fix: required true * fix: improve code * fix: app refresh * fix: remove db.import * fix: type error * fix: map * refactor: locale improve * refactor: tx-cos * fix: undefined * refactor: code improve * chore: use bookworm * fix: npm add user * fix: npm login * fix: npm adduser * fix: npm adduser * fix: expect * fix: expect * fix: environmentVariables * refactor: support bulk delete & filter * refactor: locale improve * feat: filter * refactor: useGlobalVariable * fix: scope * fix: bug * fix: optionsKeysNotAllowedInEnv * fix: test error * fix: test * fix: test * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com> Co-authored-by: Chareice <chareice@live.com>
97 lines
2.2 KiB
TypeScript
97 lines
2.2 KiB
TypeScript
/**
|
|
* This file is part of the NocoBase (R) project.
|
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
* Authors: NocoBase Team.
|
|
*
|
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
*/
|
|
|
|
import { default as lodash } from 'lodash';
|
|
import { CollectionField } from './collection-field';
|
|
import { CollectionOptions, ICollection, ICollectionManager, IField, IRepository } from './types';
|
|
|
|
export class Collection implements ICollection {
|
|
repository: IRepository;
|
|
fields: Map<string, IField> = new Map<string, IField>();
|
|
|
|
constructor(
|
|
protected options: CollectionOptions,
|
|
public collectionManager: ICollectionManager,
|
|
) {
|
|
this.setRepository(options.repository);
|
|
|
|
if (options.fields) {
|
|
this.setFields(options.fields);
|
|
}
|
|
}
|
|
|
|
get name() {
|
|
return this.options.name;
|
|
}
|
|
|
|
get filterTargetKey() {
|
|
return this.options.filterTargetKey;
|
|
}
|
|
|
|
updateOptions(options: CollectionOptions, mergeOptions?: any) {
|
|
const newOptions = {
|
|
...this.options,
|
|
...lodash.cloneDeep(options),
|
|
};
|
|
|
|
this.options = newOptions;
|
|
|
|
this.setFields(newOptions.fields || []);
|
|
|
|
if (options.repository) {
|
|
this.setRepository(options.repository);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
setFields(fields: any[]) {
|
|
const fieldNames = this.fields.keys();
|
|
for (const fieldName of fieldNames) {
|
|
this.removeField(fieldName);
|
|
}
|
|
|
|
for (const field of fields) {
|
|
this.setField(field.name, field);
|
|
}
|
|
}
|
|
|
|
setField(name: string, options: any) {
|
|
const field = new CollectionField(options);
|
|
this.fields.set(name, field);
|
|
return field;
|
|
}
|
|
|
|
removeField(name: string) {
|
|
this.fields.delete(name);
|
|
}
|
|
|
|
getField(name: string) {
|
|
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()];
|
|
}
|
|
|
|
protected setRepository(repository: any) {
|
|
const RepositoryClass = this.collectionManager.getRegisteredRepository(repository || 'Repository');
|
|
this.repository = new RepositoryClass(this);
|
|
}
|
|
}
|