@simitgroup/simpleapp-generator 1.6.6-p-alpha → 1.6.6-r-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReleaseNote.md +3 -0
- package/dist/buildinschemas/autoincreament.d.ts.map +1 -1
- package/dist/buildinschemas/autoincreament.js +17 -14
- package/dist/buildinschemas/autoincreament.js.map +1 -1
- package/dist/buildinschemas/branch.d.ts.map +1 -1
- package/dist/buildinschemas/branch.js +25 -24
- package/dist/buildinschemas/branch.js.map +1 -1
- package/dist/buildinschemas/changehistories.d.ts.map +1 -1
- package/dist/buildinschemas/changehistories.js +10 -9
- package/dist/buildinschemas/changehistories.js.map +1 -1
- package/dist/buildinschemas/customfield.d.ts.map +1 -1
- package/dist/buildinschemas/customfield.js +14 -24
- package/dist/buildinschemas/customfield.js.map +1 -1
- package/dist/buildinschemas/docnoformat.d.ts.map +1 -1
- package/dist/buildinschemas/docnoformat.js +34 -23
- package/dist/buildinschemas/docnoformat.js.map +1 -1
- package/dist/buildinschemas/documentevent.d.ts.map +1 -1
- package/dist/buildinschemas/documentevent.js +36 -26
- package/dist/buildinschemas/documentevent.js.map +1 -1
- package/dist/buildinschemas/index.d.ts +1 -0
- package/dist/buildinschemas/index.d.ts.map +1 -1
- package/dist/buildinschemas/index.js +3 -1
- package/dist/buildinschemas/index.js.map +1 -1
- package/dist/buildinschemas/keyvaluepair.d.ts.map +1 -1
- package/dist/buildinschemas/keyvaluepair.js +7 -6
- package/dist/buildinschemas/keyvaluepair.js.map +1 -1
- package/dist/buildinschemas/message.d.ts +3 -0
- package/dist/buildinschemas/message.d.ts.map +1 -0
- package/dist/buildinschemas/message.js +34 -0
- package/dist/buildinschemas/message.js.map +1 -0
- package/dist/buildinschemas/organization.d.ts.map +1 -1
- package/dist/buildinschemas/organization.js +34 -30
- package/dist/buildinschemas/organization.js.map +1 -1
- package/dist/buildinschemas/permission.d.ts.map +1 -1
- package/dist/buildinschemas/permission.js +16 -7
- package/dist/buildinschemas/permission.js.map +1 -1
- package/dist/buildinschemas/systemmessage.d.ts.map +1 -1
- package/dist/buildinschemas/systemmessage.js +35 -32
- package/dist/buildinschemas/systemmessage.js.map +1 -1
- package/dist/buildinschemas/tenant.d.ts.map +1 -1
- package/dist/buildinschemas/tenant.js +17 -16
- package/dist/buildinschemas/tenant.js.map +1 -1
- package/dist/buildinschemas/user.d.ts.map +1 -1
- package/dist/buildinschemas/user.js +34 -31
- package/dist/buildinschemas/user.js.map +1 -1
- package/dist/buildinschemas/webhook.d.ts.map +1 -1
- package/dist/buildinschemas/webhook.js +123 -51
- package/dist/buildinschemas/webhook.js.map +1 -1
- package/dist/buildinschemas/webhookhistory.d.ts +3 -0
- package/dist/buildinschemas/webhookhistory.d.ts.map +1 -0
- package/dist/buildinschemas/webhookhistory.js +44 -0
- package/dist/buildinschemas/webhookhistory.js.map +1 -0
- package/dist/buildinschemas/webhooklog.d.ts +3 -0
- package/dist/buildinschemas/webhooklog.d.ts.map +1 -0
- package/dist/buildinschemas/webhooklog.js +77 -0
- package/dist/buildinschemas/webhooklog.js.map +1 -0
- package/dist/createproject.js +138 -0
- package/dist/createproject.js.map +1 -0
- package/dist/framework.d.ts.map +1 -1
- package/dist/framework.js +5 -7
- package/dist/framework.js.map +1 -1
- package/dist/generate-allow-changebackend.js +305 -0
- package/dist/generate-allow-changebackend.js.map +1 -0
- package/dist/generate.js +19 -4
- package/dist/generate.js.map +1 -1
- package/dist/index2.js +118 -0
- package/dist/index2.js.map +1 -0
- package/dist/installdependency.js +20 -0
- package/dist/installdependency.js.map +1 -0
- package/dist/installnest.js +2 -0
- package/dist/installnest.js.map +1 -0
- package/dist/installnuxt.js +2 -0
- package/dist/installnuxt.js.map +1 -0
- package/dist/processors/groupsbuilder.js +2 -0
- package/dist/processors/groupsbuilder.js.map +1 -0
- package/dist/processors/jsonschemabuilder.js +14 -12
- package/dist/processors/jsonschemabuilder.js.map +1 -1
- package/dist/schematype/baseschema.js +25 -0
- package/dist/schematype/baseschema.js.map +1 -0
- package/dist/schematype/default.js +2 -0
- package/dist/schematype/default.js.map +1 -0
- package/dist/schematype/index.js +12 -0
- package/dist/schematype/index.js.map +1 -0
- package/dist/schematype/primarymasterdata.js +38 -0
- package/dist/schematype/primarymasterdata.js.map +1 -0
- package/dist/schematype/simple.js +24 -0
- package/dist/schematype/simple.js.map +1 -0
- package/dist/schematype/simplemasterdata.js +31 -0
- package/dist/schematype/simplemasterdata.js.map +1 -0
- package/dist/schematype/transaction.js +74 -0
- package/dist/schematype/transaction.js.map +1 -0
- package/dist/type.d.ts +39 -5
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
- package/src/buildinschemas/autoincreament.ts +35 -33
- package/src/buildinschemas/branch.ts +47 -47
- package/src/buildinschemas/changehistories.ts +31 -30
- package/src/buildinschemas/customfield.ts +14 -24
- package/src/buildinschemas/docnoformat.ts +54 -43
- package/src/buildinschemas/documentevent.ts +42 -33
- package/src/buildinschemas/index.ts +1 -0
- package/src/buildinschemas/keyvaluepair.ts +25 -25
- package/src/buildinschemas/organization.ts +54 -50
- package/src/buildinschemas/permission.ts +34 -25
- package/src/buildinschemas/systemmessage.ts +39 -38
- package/src/buildinschemas/tenant.ts +46 -45
- package/src/buildinschemas/user.ts +64 -60
- package/src/buildinschemas/webhook.ts +131 -59
- package/src/buildinschemas/webhooklog.ts +75 -0
- package/src/framework.ts +6 -8
- package/src/generate.ts +19 -3
- package/src/processors/jsonschemabuilder.ts +6 -4
- package/src/type.ts +271 -215
- package/templates/basic/miniAppJsSdk/resource-bridge.service.ts.eta +9 -7
- package/templates/basic/miniAppStreamlitSdk/resource-bridge.service.ts.eta +22 -7
- package/templates/basic/nuxt/jsonschema.ts.eta +7 -0
- package/templates/basic/nuxt/resource-bridge.editable.service.ts.eta +40 -0
- package/templates/basic/nuxt/resource-bridge.service.ts.eta +24 -21
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +27 -9
- package/templates/miniAppJsSdk/src/services/bridge-resource-accessor.service.ts.eta +2 -2
- package/templates/miniAppStreamlitSdk/simtrain_eco_mini_app_streamlit_sdk/sdk.py.eta +5 -2
- package/templates/nest/src/simpleapp/generate/commons/middlewares/tenant.middleware.ts.eta +4 -2
- package/templates/nest/src/simpleapp/generate/commons/runwebhook.service.ts.eta +143 -168
- package/templates/nest/src/simpleapp/generate/commons/user.context.ts.eta +22 -13
- package/templates/nest/src/simpleapp/generate/processors/simpleapp.processor.ts.eta +22 -16
- package/templates/nest/src/simpleapp/webhooks/branch.ts._eta +37 -0
- package/templates/nest/src/simpleapp/webhooks/index.ts._eta +21 -0
- package/templates/nuxt/components/simpleApp/SimpleAppForm.vue.eta +4 -3
- package/templates/nuxt/components/simpleApp/SimpleAppInputTable.vue.eta +0 -1
- package/templates/nuxt/plugins/18.simpleapp-custom-field-store.ts.eta +9 -3
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppClient.ts.eta +32 -22
- package/templates/nuxt/simpleapp/generate/jsonSchemas/index.ts.eta +11 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/common.constant.ts.eta +1 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/constants/resource.constant.ts.eta +2 -2
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge-resource-accessor.service.ts.eta +4 -4
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/services/bridge.service.ts.eta +20 -1
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/bridge.type.ts.eta +9 -0
- package/templates/nuxt/simpleapp/generate/miniApp/bridge/types/resource-mapper.type.ts.eta +2 -2
- package/templates/project/build.sh.eta +0 -5
- package/templates/nest/src/simpleapp/apischemas/customfield.ts.eta +0 -21
- package/templates/nuxt/simpleapp/generate/clients/SimpleAppCustomFieldClient.ts.eta +0 -188
- /package/templates/nest/src/simpleapp/generate/processors/{webhook.processor.ts.eta → webhook.processor.ts.etaxxxx} +0 -0
|
@@ -13,10 +13,13 @@ import {
|
|
|
13
13
|
NotificationStatus,
|
|
14
14
|
SchemaType,
|
|
15
15
|
FormActions,
|
|
16
|
+
DynamicObject,
|
|
16
17
|
} from "~/types";
|
|
17
18
|
import { getValidateService } from "~/simpleapp/generate/sharelibs/validate";
|
|
18
|
-
import { SimpleAppCustomFieldClient } from "./SimpleAppCustomFieldClient";
|
|
19
19
|
import { WatchHandle } from "vue";
|
|
20
|
+
import { CustomFieldService } from "../features/customField/services/CustomFieldService";
|
|
21
|
+
import { CustomFieldDataMode } from "../features/customField/types/common";
|
|
22
|
+
import { CustomFieldDataModeEnum } from "../features/customField/enums/common";
|
|
20
23
|
|
|
21
24
|
// import { useToast, } from 'primevue/usetoast';
|
|
22
25
|
// import type { ToastMessageOptions } from 'primevue/toast';
|
|
@@ -50,8 +53,10 @@ export class SimpleAppClient<
|
|
|
50
53
|
protected errorlist = ref({});
|
|
51
54
|
protected completeformula = true;
|
|
52
55
|
protected axios;
|
|
53
|
-
|
|
56
|
+
|
|
57
|
+
// FLAG::CUSTOM_FIELD
|
|
54
58
|
protected _customFieldWatch: WatchHandle | null = null;
|
|
59
|
+
private _customFieldService = new CustomFieldService();
|
|
55
60
|
|
|
56
61
|
constructor(apiobj: TApi, doctype: string, docname: string) {
|
|
57
62
|
this.docapi = apiobj;
|
|
@@ -76,25 +81,29 @@ export class SimpleAppClient<
|
|
|
76
81
|
return false;
|
|
77
82
|
} //if there is readonly attribute in data, will override it at processor and client
|
|
78
83
|
setData = (data: any) => {
|
|
79
|
-
// this.data.value = data;
|
|
80
|
-
|
|
81
|
-
// TODO: Will Cause Docno Format Broken
|
|
82
|
-
// data.more = this._customFieldClient.formCustomFieldData(
|
|
83
|
-
// this.doctype,
|
|
84
|
-
// this.schema.properties?.more,
|
|
85
|
-
// data.createdBy == "",
|
|
86
|
-
// data.more,
|
|
87
|
-
// );
|
|
88
|
-
|
|
89
84
|
Object.assign(this.data.value, data);
|
|
90
85
|
};
|
|
91
86
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
87
|
+
prepareCustomFieldJsonSchema() {
|
|
88
|
+
const resp = this._customFieldService.prepareCustomFieldJsonSchema(
|
|
89
|
+
this.docname,
|
|
90
|
+
);
|
|
91
|
+
this.schema.properties.more = resp;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
prepareCustomFieldData<T extends DynamicObject>(
|
|
95
|
+
mode: CustomFieldDataMode,
|
|
96
|
+
data: T,
|
|
97
|
+
) {
|
|
98
|
+
const customFieldData = this._customFieldService.prepareCustomFieldData(
|
|
99
|
+
this.docname,
|
|
100
|
+
mode,
|
|
101
|
+
this.schema.properties?.more,
|
|
102
|
+
data.more,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
(data as any).more = customFieldData;
|
|
106
|
+
return data;
|
|
98
107
|
}
|
|
99
108
|
|
|
100
109
|
async getById(id?: string) {
|
|
@@ -103,10 +112,11 @@ export class SimpleAppClient<
|
|
|
103
112
|
return await this.docapi
|
|
104
113
|
.runFindOne(id, this.axios)
|
|
105
114
|
.then((res: AxiosResponse) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
const dataWithCustomField = this.prepareCustomFieldData(
|
|
116
|
+
CustomFieldDataModeEnum.EXISTING,
|
|
117
|
+
res.data,
|
|
118
|
+
);
|
|
119
|
+
this.setData(dataWithCustomField);
|
|
110
120
|
this.setWatchChange();
|
|
111
121
|
setTimeout(() => {
|
|
112
122
|
this.ready = true;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
+
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
+
* last change 2024-02-23
|
|
5
|
+
* Author: Ks Tan
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
<%for(let i=0; i<it.modules.length;i++){ %>
|
|
9
|
+
<% const d = it.modules[i] %>
|
|
10
|
+
export * from './<%= d['doctype']%>.jsonschema'
|
|
11
|
+
<%}%>
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
const pascalName = upperFirstCase(resourceName);
|
|
22
22
|
const kebabName = camelToKebab(resourceName);
|
|
23
23
|
|
|
24
|
-
const miniAppWhitelistApis = config?.miniApp?.whitelist ||
|
|
25
|
-
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
24
|
+
const miniAppWhitelistApis = config?.miniApp?.whitelist || {};
|
|
25
|
+
const hasMiniAppWhitelistedApi = Object.keys(miniAppWhitelistApis).length > 0;
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
resourceName,
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
const pascalName = upperFirstCase(resourceName);
|
|
22
22
|
const kebabName = camelToKebab(resourceName);
|
|
23
23
|
|
|
24
|
-
const miniAppWhitelistApis = config?.miniApp?.whitelist ||
|
|
25
|
-
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
24
|
+
const miniAppWhitelistApis = config?.miniApp?.whitelist || {};
|
|
25
|
+
const hasMiniAppWhitelistedApi = Object.keys(miniAppWhitelistApis).length > 0;
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
resourceName,
|
|
@@ -40,7 +40,7 @@ import { MiniAppResourceMap } from "../types/resource-mapper.type";
|
|
|
40
40
|
const { pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
|
|
41
41
|
%>
|
|
42
42
|
<% if(hasMiniAppWhitelistedApi) { %>
|
|
43
|
-
import { MiniApp<%= pascalName %>
|
|
43
|
+
import { MiniApp<%= pascalName %>BridgeEditableService } from "./editable/resources/<%= kebabName %>-bridge.editable.service";
|
|
44
44
|
<% } %>
|
|
45
45
|
<% } %>
|
|
46
46
|
|
|
@@ -54,7 +54,7 @@ export class MiniAppBridgeResourceAccessor {
|
|
|
54
54
|
<% if(hasMiniAppWhitelistedApi) { %>
|
|
55
55
|
get <%= resourceName %>() {
|
|
56
56
|
if (!this.instances.<%= resourceName %>) {
|
|
57
|
-
this.instances.<%= resourceName %> = new MiniApp<%= pascalName %>
|
|
57
|
+
this.instances.<%= resourceName %> = new MiniApp<%= pascalName %>BridgeEditableService();
|
|
58
58
|
}
|
|
59
59
|
return this.instances.<%= resourceName %>;
|
|
60
60
|
}
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* last change 2025-06-18
|
|
5
5
|
* Author: --
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { SimpleAppDocumentType } from "~/types";
|
|
9
9
|
import {
|
|
10
10
|
MiniAppBridgeMessageApi,
|
|
11
11
|
MiniAppBridgeMessageNavigate,
|
|
12
|
+
MiniAppBridgeMessageNavigateCurrentMiniApp,
|
|
12
13
|
MiniAppBridgeMessageOpenOnScreenResourceForm,
|
|
13
14
|
} from "../types/bridge.type";
|
|
14
15
|
import { AxiosError } from "axios";
|
|
@@ -24,6 +25,24 @@ export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
|
|
|
24
25
|
goTo(message.params.target, message.params.id, message.params.query);
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
handleBridgeNavigateCurrentMiniApp(
|
|
29
|
+
message: MiniAppBridgeMessageNavigateCurrentMiniApp,
|
|
30
|
+
pluginCode: string,
|
|
31
|
+
) {
|
|
32
|
+
const target = message.params.target;
|
|
33
|
+
const { $appPluginsStore } = useNuxtApp();
|
|
34
|
+
let targetUrl = "";
|
|
35
|
+
if (target === "setting") {
|
|
36
|
+
targetUrl = $appPluginsStore.getPluginSettingPath(pluginCode);
|
|
37
|
+
} else {
|
|
38
|
+
targetUrl = $appPluginsStore.getPluginPageUrlPath(pluginCode, "");
|
|
39
|
+
targetUrl = targetUrl.replace(/^\/|\/$/g, "");
|
|
40
|
+
targetUrl = `${targetUrl}/${message.params.target}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
goTo(targetUrl, undefined, message.params.query);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
handleBridgeOpenOnScreenResourceForm(
|
|
28
47
|
message: MiniAppBridgeMessageOpenOnScreenResourceForm,
|
|
29
48
|
) {
|
|
@@ -16,6 +16,7 @@ export type MiniAppResource = {
|
|
|
16
16
|
|
|
17
17
|
export type MiniAppBridgeMessage<TAction> =
|
|
18
18
|
| MiniAppBridgeMessageNavigate
|
|
19
|
+
| MiniAppBridgeMessageNavigateCurrentMiniApp
|
|
19
20
|
| MiniAppBridgeMessageOpenOnScreenResourceForm
|
|
20
21
|
| MiniAppBridgeMessageApi<TAction>
|
|
21
22
|
| MiniAppBridgeMessageInitResponse;
|
|
@@ -29,6 +30,14 @@ export type MiniAppBridgeMessageNavigate = {
|
|
|
29
30
|
};
|
|
30
31
|
};
|
|
31
32
|
|
|
33
|
+
export type MiniAppBridgeMessageNavigateCurrentMiniApp = {
|
|
34
|
+
type: typeof MINI_APP_BRIDGE_MESSAGES.NAVIGATE_CURRENT_MINI_APP;
|
|
35
|
+
params: {
|
|
36
|
+
target: string;
|
|
37
|
+
query?: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
32
41
|
export type MiniAppBridgeMessageOpenOnScreenResourceForm = {
|
|
33
42
|
type: typeof MINI_APP_BRIDGE_MESSAGES.OPEN_ON_SCREEN_RESOURCE_FORM;
|
|
34
43
|
params: {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
const pascalName = upperFirstCase(resourceName);
|
|
22
22
|
const kebabName = camelToKebab(resourceName);
|
|
23
23
|
|
|
24
|
-
const miniAppWhitelistApis = config?.miniApp?.whitelist ||
|
|
25
|
-
const hasMiniAppWhitelistedApi = miniAppWhitelistApis.length > 0;
|
|
24
|
+
const miniAppWhitelistApis = config?.miniApp?.whitelist || {};
|
|
25
|
+
const hasMiniAppWhitelistedApi = Object.keys(miniAppWhitelistApis).length > 0;
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
28
|
resourceName,
|
|
@@ -19,11 +19,6 @@ elif [ $type == 'updatebackend' ]; then
|
|
|
19
19
|
cp -a ./sharelibs backend/src/simpleapp/generate
|
|
20
20
|
elif [ $type == 'updateMiniAppJsSdk' ]; then
|
|
21
21
|
simpleapp-generator -c config.json -g updateMiniAppJsSdk
|
|
22
|
-
mkdir -p ./miniAppSdk/js/src/constants
|
|
23
|
-
mkdir -p ./miniAppSdk/js/src/types
|
|
24
|
-
cp -a ./frontend/simpleapp/generate/miniApp/bridge/constants/* ./miniAppSdk/js/src/constants
|
|
25
|
-
cp -a ./frontend/simpleapp/generate/miniApp/bridge/types/* ./miniAppSdk/js/src/types
|
|
26
|
-
cp -a miniAppSdk/js/src/* ../sdk/simtrain-eco-js-sdk/src
|
|
27
22
|
elif [ $type == 'updateMiniAppStreamlitSdk' ]; then
|
|
28
23
|
simpleapp-generator -c config.json -g updateMiniAppStreamlitSdk
|
|
29
24
|
fi
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
-
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change 2024-02-23
|
|
5
|
-
* Author: Ks Tan
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Field, ObjectType } from '@nestjs/graphql';
|
|
9
|
-
import { ApiProperty } from '@nestjs/swagger';
|
|
10
|
-
import { Customfield } from '../generate/apischemas';
|
|
11
|
-
|
|
12
|
-
@ObjectType()
|
|
13
|
-
export class CompleteCustomFieldResource {
|
|
14
|
-
@Field()
|
|
15
|
-
@ApiProperty({ type: 'string', required: true })
|
|
16
|
-
resourceName: string;
|
|
17
|
-
|
|
18
|
-
@Field(() => Customfield)
|
|
19
|
-
@ApiProperty({ type: () => Customfield, required: false })
|
|
20
|
-
data: Customfield;
|
|
21
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file was automatically generated by simpleapp generator. Every
|
|
3
|
-
* MODIFICATION OVERRIDE BY GENERATEOR
|
|
4
|
-
* last change 2025-06-09
|
|
5
|
-
*/
|
|
6
|
-
import _ from "lodash";
|
|
7
|
-
import {
|
|
8
|
-
CustomFieldJsonSchemaMoreSchema,
|
|
9
|
-
CustomFieldJsonSchemaMoreSchemaGroup,
|
|
10
|
-
DynamicObject,
|
|
11
|
-
SimpleAppJSONSchema7Definition,
|
|
12
|
-
} from "~/types";
|
|
13
|
-
|
|
14
|
-
export class SimpleAppCustomFieldClient {
|
|
15
|
-
constructor() {}
|
|
16
|
-
|
|
17
|
-
formCustomFieldJsonSchema(collectionName: string) {
|
|
18
|
-
const customFieldFromDB = this._findCustomFieldSchemaFromDB(collectionName);
|
|
19
|
-
const customFieldFromPlugin =
|
|
20
|
-
this._findCustomFieldSchemaFromPlugin(collectionName);
|
|
21
|
-
|
|
22
|
-
if (customFieldFromDB && !_.isEmpty(customFieldFromDB)) {
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const schema: CustomFieldJsonSchemaMoreSchema = {
|
|
26
|
-
type: "object",
|
|
27
|
-
properties: {
|
|
28
|
-
...customFieldFromDB,
|
|
29
|
-
...customFieldFromPlugin,
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
return schema;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private _findCustomFieldSchemaFromDB(collectionName: string) {
|
|
37
|
-
const { $customFieldStore } = useNuxtApp();
|
|
38
|
-
if (!$customFieldStore.data || _.isEmpty($customFieldStore.data)) {
|
|
39
|
-
return {};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const customField = $customFieldStore.findByCollectionName(collectionName);
|
|
43
|
-
if (!customField) {
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const schema: CustomFieldJsonSchemaMoreSchemaGroup = {
|
|
48
|
-
default: {
|
|
49
|
-
title: "Custom Field",
|
|
50
|
-
...customField.form.schema,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
return schema;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private _findCustomFieldSchemaFromPlugin(collectionName: string) {
|
|
58
|
-
const schema: CustomFieldJsonSchemaMoreSchemaGroup = {};
|
|
59
|
-
|
|
60
|
-
const { $appPluginsStore } = useNuxtApp();
|
|
61
|
-
|
|
62
|
-
const pluginForms = $appPluginsStore.getForm(collectionName);
|
|
63
|
-
if (!pluginForms || pluginForms.length <= 0) {
|
|
64
|
-
return schema;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < pluginForms.length; i++) {
|
|
68
|
-
const pluginItem = pluginForms[i];
|
|
69
|
-
const { pluginCode, jsonSchema } = pluginItem;
|
|
70
|
-
|
|
71
|
-
schema[pluginCode] = jsonSchema as SimpleAppJSONSchema7Definition;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return schema;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
formCustomFieldData(
|
|
78
|
-
collectionName: string,
|
|
79
|
-
moreSchema: CustomFieldJsonSchemaMoreSchema | undefined,
|
|
80
|
-
isNew: boolean,
|
|
81
|
-
resourceData: any | undefined,
|
|
82
|
-
) {
|
|
83
|
-
if (!moreSchema || !moreSchema?.properties) {
|
|
84
|
-
return resourceData;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (collectionName !== "religion") {
|
|
88
|
-
return resourceData;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const data: DynamicObject = {};
|
|
92
|
-
|
|
93
|
-
if (!isNew) {
|
|
94
|
-
for (const [groupName, groupItem] of Object.entries(
|
|
95
|
-
moreSchema.properties,
|
|
96
|
-
)) {
|
|
97
|
-
const defaultData = this.generateDefaultData(groupItem);
|
|
98
|
-
const mergedData = this.mergeWithDefault(
|
|
99
|
-
defaultData,
|
|
100
|
-
resourceData?.[groupName],
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
data[groupName] = mergedData;
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
for (const [groupName, groupItem] of Object.entries(
|
|
107
|
-
moreSchema.properties,
|
|
108
|
-
)) {
|
|
109
|
-
const defaultData = this.generateDefaultData(groupItem);
|
|
110
|
-
|
|
111
|
-
data[groupName] = defaultData;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return data;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
generateDefaultData(schema: any): any {
|
|
119
|
-
if (schema.type === "object") {
|
|
120
|
-
const result: any = {};
|
|
121
|
-
if (schema?.["x-foreignkey"]) {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const properties = schema.properties || {};
|
|
126
|
-
for (const key of Object.keys(properties)) {
|
|
127
|
-
result[key] = this.generateDefaultData(properties[key]);
|
|
128
|
-
}
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (schema.type === "array") {
|
|
133
|
-
const itemSchema = schema.items;
|
|
134
|
-
const minItems = schema.minItems || 0;
|
|
135
|
-
const arr = [];
|
|
136
|
-
const itemsCount = minItems > 0 ? 1 : 0;
|
|
137
|
-
for (let i = 0; i < itemsCount; i++) {
|
|
138
|
-
arr.push(this.generateDefaultData(itemSchema));
|
|
139
|
-
}
|
|
140
|
-
return arr;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
if (typeof schema.default !== "undefined") {
|
|
144
|
-
return schema.default;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// handle primitive types fallback
|
|
148
|
-
switch (schema.type) {
|
|
149
|
-
case "string":
|
|
150
|
-
return "";
|
|
151
|
-
case "number":
|
|
152
|
-
case "integer":
|
|
153
|
-
return 0;
|
|
154
|
-
case "boolean":
|
|
155
|
-
return false;
|
|
156
|
-
default:
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
mergeWithDefault(defaultData: any, dbData: any): any {
|
|
162
|
-
if (Array.isArray(defaultData)) {
|
|
163
|
-
if (Array.isArray(dbData)) {
|
|
164
|
-
if (_.isEmpty(dbData)) {
|
|
165
|
-
return [];
|
|
166
|
-
}
|
|
167
|
-
// Merge each item
|
|
168
|
-
const mergedArray = dbData.map((dbItem, index) => {
|
|
169
|
-
const defaultItem = defaultData[index] ?? defaultData[0]; // use first default if index out of bound
|
|
170
|
-
return this.mergeWithDefault(defaultItem, dbItem);
|
|
171
|
-
});
|
|
172
|
-
return mergedArray;
|
|
173
|
-
} else {
|
|
174
|
-
// return defaultData;
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
} else if (typeof defaultData === "object" && defaultData !== null) {
|
|
178
|
-
const result: any = {};
|
|
179
|
-
for (const key of Object.keys(defaultData)) {
|
|
180
|
-
result[key] = this.mergeWithDefault(defaultData[key], dbData?.[key]);
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
} else {
|
|
184
|
-
// primitive value
|
|
185
|
-
return typeof dbData !== "undefined" ? dbData : defaultData;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
File without changes
|