mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-07 14:39:25 +08:00
* fix: add license code * fix: bug * fix: bug * fix: upgrade * fix: improve * chore: add copyright information to the file header * fix: d.ts bug * fix: bug * fix: e2e bug * fix: merge main --------- Co-authored-by: chenos <chenlinxh@gmail.com>
190 lines
4.8 KiB
TypeScript
190 lines
4.8 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 { Plugin } from '../application/Plugin';
|
|
|
|
import { InheritanceCollectionMixin } from './mixins/InheritanceCollectionMixin';
|
|
import {
|
|
CheckboxFieldInterface,
|
|
CheckboxGroupFieldInterface,
|
|
ChinaRegionFieldInterface,
|
|
CollectionSelectFieldInterface,
|
|
ColorFieldInterface,
|
|
CreatedAtFieldInterface,
|
|
CreatedByFieldInterface,
|
|
DatetimeFieldInterface,
|
|
EmailFieldInterface,
|
|
IconFieldInterface,
|
|
IdFieldInterface,
|
|
InputFieldInterface,
|
|
IntegerFieldInterface,
|
|
JsonFieldInterface,
|
|
LinkToFieldInterface,
|
|
M2MFieldInterface,
|
|
M2OFieldInterface,
|
|
MarkdownFieldInterface,
|
|
MultipleSelectFieldInterface,
|
|
NumberFieldInterface,
|
|
O2MFieldInterface,
|
|
O2OFieldInterface,
|
|
OHOFieldInterface,
|
|
OBOFieldInterface,
|
|
PasswordFieldInterface,
|
|
PercentFieldInterface,
|
|
PhoneFieldInterface,
|
|
RadioGroupFieldInterface,
|
|
RichTextFieldInterface,
|
|
SelectFieldInterface,
|
|
SubTableFieldInterface,
|
|
TableoidFieldInterface,
|
|
TextareaFieldInterface,
|
|
TimeFieldInterface,
|
|
UpdatedAtFieldInterface,
|
|
UpdatedByFieldInterface,
|
|
UrlFieldInterface,
|
|
SortFieldInterface,
|
|
UUIDFieldInterface,
|
|
NanoidFieldInterface,
|
|
UnixTimestampFieldInterface,
|
|
} from './interfaces';
|
|
import {
|
|
GeneralCollectionTemplate,
|
|
ExpressionCollectionTemplate,
|
|
SqlCollectionTemplate,
|
|
TreeCollectionTemplate,
|
|
ViewCollectionTemplate,
|
|
} from './templates';
|
|
import { DEFAULT_DATA_SOURCE_KEY, DEFAULT_DATA_SOURCE_TITLE } from '../data-source/data-source/DataSourceManager';
|
|
import { DataSource } from '../data-source/data-source/DataSource';
|
|
|
|
class MainDataSource extends DataSource {
|
|
async getDataSource() {
|
|
const service = await this.app.apiClient.request({
|
|
resource: 'collections',
|
|
action: 'list',
|
|
params: {
|
|
paginate: false,
|
|
appends: ['fields', 'category'],
|
|
filter: {
|
|
// inherit: false,
|
|
},
|
|
sort: ['sort'],
|
|
},
|
|
});
|
|
const collections = service?.data?.data || [];
|
|
return {
|
|
collections,
|
|
};
|
|
}
|
|
}
|
|
|
|
export class CollectionPlugin extends Plugin {
|
|
async load() {
|
|
this.dataSourceManager.addCollectionMixins([InheritanceCollectionMixin]);
|
|
this.addFieldInterfaces();
|
|
this.addCollectionTemplates();
|
|
this.addFieldInterfaces();
|
|
this.addFieldInterfaceGroups();
|
|
this.addMainDataSource();
|
|
}
|
|
|
|
addMainDataSource() {
|
|
if (this.options?.config?.enableRemoteDataSource === false) return;
|
|
this.dataSourceManager.addDataSource(MainDataSource, {
|
|
key: DEFAULT_DATA_SOURCE_KEY,
|
|
displayName: DEFAULT_DATA_SOURCE_TITLE,
|
|
});
|
|
}
|
|
|
|
addFieldInterfaceGroups() {
|
|
this.dataSourceManager.addFieldInterfaceGroups({
|
|
basic: {
|
|
label: '{{t("Basic")}}',
|
|
},
|
|
choices: {
|
|
label: '{{t("Choices")}}',
|
|
},
|
|
media: {
|
|
label: '{{t("Media")}}',
|
|
},
|
|
datetime: {
|
|
label: '{{t("Date & Time")}}',
|
|
},
|
|
relation: {
|
|
label: '{{t("Relation")}}',
|
|
},
|
|
advanced: {
|
|
label: '{{t("Advanced type")}}',
|
|
},
|
|
systemInfo: {
|
|
label: '{{t("System info")}}',
|
|
},
|
|
others: {
|
|
label: '{{t("Others")}}',
|
|
},
|
|
});
|
|
}
|
|
|
|
addFieldInterfaces() {
|
|
this.dataSourceManager.addFieldInterfaces([
|
|
CheckboxFieldInterface,
|
|
CheckboxGroupFieldInterface,
|
|
ChinaRegionFieldInterface,
|
|
CollectionSelectFieldInterface,
|
|
ColorFieldInterface,
|
|
CreatedAtFieldInterface,
|
|
CreatedByFieldInterface,
|
|
DatetimeFieldInterface,
|
|
EmailFieldInterface,
|
|
IconFieldInterface,
|
|
IdFieldInterface,
|
|
InputFieldInterface,
|
|
IntegerFieldInterface,
|
|
JsonFieldInterface,
|
|
LinkToFieldInterface,
|
|
M2MFieldInterface,
|
|
M2OFieldInterface,
|
|
MarkdownFieldInterface,
|
|
MultipleSelectFieldInterface,
|
|
NumberFieldInterface,
|
|
O2MFieldInterface,
|
|
O2OFieldInterface,
|
|
OHOFieldInterface,
|
|
OBOFieldInterface,
|
|
PasswordFieldInterface,
|
|
PercentFieldInterface,
|
|
PhoneFieldInterface,
|
|
RadioGroupFieldInterface,
|
|
RichTextFieldInterface,
|
|
SelectFieldInterface,
|
|
SubTableFieldInterface,
|
|
TableoidFieldInterface,
|
|
TextareaFieldInterface,
|
|
TimeFieldInterface,
|
|
UpdatedAtFieldInterface,
|
|
UpdatedByFieldInterface,
|
|
UrlFieldInterface,
|
|
SortFieldInterface,
|
|
UUIDFieldInterface,
|
|
NanoidFieldInterface,
|
|
UnixTimestampFieldInterface,
|
|
]);
|
|
}
|
|
|
|
addCollectionTemplates() {
|
|
this.dataSourceManager.addCollectionTemplates([
|
|
GeneralCollectionTemplate,
|
|
ExpressionCollectionTemplate,
|
|
SqlCollectionTemplate,
|
|
TreeCollectionTemplate,
|
|
ViewCollectionTemplate,
|
|
]);
|
|
}
|
|
}
|