forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource.ts
More file actions
109 lines (84 loc) · 3.1 KB
/
resource.ts
File metadata and controls
109 lines (84 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { IPublicTypeEditorView, IPublicResourceData, IPublicResourceTypeConfig, IBaseModelResource, IPublicEnumPluginRegisterLevel } from '@alilc/lowcode-types';
import { Logger } from '@alilc/lowcode-utils';
import { BasicContext, IBasicContext } from './context/base-context';
import { IResourceType } from './resource-type';
import { IWorkspace } from './workspace';
const logger = new Logger({ level: 'warn', bizName: 'workspace:resource' });
export interface IResource extends Resource {}
export class Resource implements IBaseModelResource<IResource> {
private context: IBasicContext;
resourceTypeInstance: IPublicResourceTypeConfig;
editorViewMap: Map<string, IPublicTypeEditorView> = new Map<string, IPublicTypeEditorView>();
get name() {
return this.resourceType.name;
}
get viewName() {
return this.resourceData.viewName || (this.resourceData as any).viewType || this.defaultViewName;
}
get description() {
return this.resourceTypeInstance?.description;
}
get icon() {
return this.resourceData.icon || this.resourceTypeInstance?.icon;
}
get type() {
return this.resourceType.type;
}
get title(): string | undefined {
return this.resourceData.title || this.resourceTypeInstance.defaultTitle;
}
get id(): string | undefined {
return this.resourceData.id;
}
get options() {
return this.resourceData.options;
}
get category() {
return this.resourceData?.category;
}
get skeleton() {
return this.context.innerSkeleton;
}
children: IResource[];
get config() {
return this.resourceData.config;
}
constructor(readonly resourceData: IPublicResourceData, readonly resourceType: IResourceType, readonly workspace: IWorkspace) {
this.context = new BasicContext(workspace, `resource-${resourceData.resourceName || resourceType.name}`, IPublicEnumPluginRegisterLevel.Resource);
this.resourceTypeInstance = resourceType.resourceTypeModel(this.context.innerPlugins._getLowCodePluginContext({
pluginName: '',
}), this.options);
this.init();
if (this.resourceTypeInstance.editorViews) {
this.resourceTypeInstance.editorViews.forEach((d: any) => {
this.editorViewMap.set(d.viewName, d);
});
}
if (!resourceType) {
logger.error(`resourceType[${resourceType}] is unValid.`);
}
this.children = this.resourceData?.children?.map(d => new Resource(d, this.workspace.getResourceType(d.resourceName || this.resourceType.name), this.workspace)) || [];
}
async init() {
await this.resourceTypeInstance.init?.();
await this.context.innerPlugins.init();
}
async import(schema: any) {
return await this.resourceTypeInstance.import?.(schema);
}
async url() {
return await this.resourceTypeInstance.url?.();
}
async save(value: any) {
return await this.resourceTypeInstance.save?.(value);
}
get editorViews() {
return this.resourceTypeInstance.editorViews;
}
get defaultViewName() {
return this.resourceTypeInstance.defaultViewName || this.resourceTypeInstance.defaultViewType;
}
getEditorView(name: string) {
return this.editorViewMap.get(name);
}
}