@simitgroup/simpleapp-generator 1.6.6-y-alpha → 1.6.7-a-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 +37 -9
- package/dist/framework.js +1 -1
- package/dist/framework.js.map +1 -1
- package/dist/generate.js +4 -4
- package/dist/generate.js.map +1 -1
- package/package.json +1 -1
- package/publish.sh +1 -0
- package/src/framework.ts +2 -2
- package/src/generate.ts +4 -4
- package/templates/basic/nuxt/resource-bridge.service.ts.eta +11 -2
- package/templates/basic/nuxt/simpleapp.generate.client.ts.eta +3 -3
- package/templates/nest/src/simpleapp/services/webhook.service.ts._eta +1 -1
- package/templates/nuxt/plugins/19.simpleapp-mini-app-store.ts.eta +379 -0
- package/templates/nuxt/plugins/20.simpleapp-userstore.ts.eta +3 -3
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldFormField.vue.eta +100 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldFormFieldInput.vue.eta +121 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldFormSection.vue.eta +40 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldMenuItem.vue.eta +37 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldMenuItemBadge.vue.eta +25 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldViewFormField.vue.eta +96 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldViewFormFieldInput.vue.eta +150 -0
- package/templates/nuxt/simpleapp/generate/features/customField/components/CustomFieldViewFormSection.vue.eta +38 -0
- package/templates/nuxt/simpleapp/generate/features/customField/composables/useCustomFieldDocList.ts.eta +48 -0
- package/templates/nuxt/simpleapp/generate/features/customField/enums/common.ts.eta +4 -0
- package/templates/nuxt/simpleapp/generate/features/customField/services/CustomFieldService.ts.eta +231 -0
- package/templates/nuxt/simpleapp/generate/features/customField/types/common.ts.eta +16 -0
- package/templates/nuxt/simpleapp/generate/features/customField/types/page.ts.eta +5 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppMenuButton.vue.eta +104 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppPageIcon.vue.eta +20 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppPageIframe.vue.eta +79 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppPermissionWrapper.vue.eta +17 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppRestrictedWarning.vue.eta +25 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppSettingLayout.vue.eta +29 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppSettingPage.vue.eta +69 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/MiniAppWrapper.vue.eta +39 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/integration/MiniAppIntegrationItem.vue.eta +48 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/integration/MiniAppIntegrationItemBadge.vue.eta +31 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/integration/MiniAppIntegrationItemGroup.vue.eta +34 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/components/integration/MiniAppIntegrationPage.vue.eta +156 -0
- package/templates/nuxt/simpleapp/generate/features/miniApp/app/types/miniApp.ts.eta +25 -0
- package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/services/bridge-resource-accessor.service.ts.eta +3 -1
- package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/services/bridge.service.ts.eta +7 -4
- package/dist/buildinschemas/message.d.ts +0 -3
- package/dist/buildinschemas/message.d.ts.map +0 -1
- package/dist/buildinschemas/message.js +0 -34
- package/dist/buildinschemas/message.js.map +0 -1
- package/dist/buildinschemas/webhookhistory.d.ts +0 -3
- package/dist/buildinschemas/webhookhistory.d.ts.map +0 -1
- package/dist/buildinschemas/webhookhistory.js +0 -44
- package/dist/buildinschemas/webhookhistory.js.map +0 -1
- package/dist/createproject.js +0 -138
- package/dist/createproject.js.map +0 -1
- package/dist/generate-allow-changebackend.js +0 -305
- package/dist/generate-allow-changebackend.js.map +0 -1
- package/dist/index2.js +0 -118
- package/dist/index2.js.map +0 -1
- package/dist/installdependency.js +0 -20
- package/dist/installdependency.js.map +0 -1
- package/dist/installnest.js +0 -2
- package/dist/installnest.js.map +0 -1
- package/dist/installnuxt.js +0 -2
- package/dist/installnuxt.js.map +0 -1
- package/dist/processors/groupsbuilder.js +0 -2
- package/dist/processors/groupsbuilder.js.map +0 -1
- package/dist/schematype/baseschema.js +0 -25
- package/dist/schematype/baseschema.js.map +0 -1
- package/dist/schematype/default.js +0 -2
- package/dist/schematype/default.js.map +0 -1
- package/dist/schematype/index.js +0 -12
- package/dist/schematype/index.js.map +0 -1
- package/dist/schematype/primarymasterdata.js +0 -38
- package/dist/schematype/primarymasterdata.js.map +0 -1
- package/dist/schematype/simple.js +0 -24
- package/dist/schematype/simple.js.map +0 -1
- package/dist/schematype/simplemasterdata.js +0 -31
- package/dist/schematype/simplemasterdata.js.map +0 -1
- package/dist/schematype/transaction.js +0 -74
- package/dist/schematype/transaction.js.map +0 -1
- package/templates/nest/src/simpleapp/types/customfield.ts.eta +0 -14
- package/templates/nuxt/plugins/19.app-plugins.ts.eta +0 -422
- /package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/constants/common.constant.ts.eta +0 -0
- /package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/constants/resource.constant.ts.eta +0 -0
- /package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/types/bridge.type.ts.eta +0 -0
- /package/templates/nuxt/simpleapp/generate/{miniApp → features/miniApp}/bridge/types/resource-mapper.type.ts.eta +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<span
|
|
3
|
+
class="flex items-center gap-2 w-fit px-2 py-0.5 rounded-lg text-[0.65rem] font-semibold text-surface-700"
|
|
4
|
+
:class="{
|
|
5
|
+
'bg-slate-100': !isActive,
|
|
6
|
+
'bg-gradient-to-r from-[#00b2d8] to-[#5ecbc5] !text-white': isActive,
|
|
7
|
+
}"
|
|
8
|
+
>
|
|
9
|
+
<i
|
|
10
|
+
class="pi"
|
|
11
|
+
:class="{
|
|
12
|
+
'pi-minus-circle': !isActive,
|
|
13
|
+
'pi-check-circle': isActive,
|
|
14
|
+
}"
|
|
15
|
+
/>
|
|
16
|
+
<span>{{ title }}</span>
|
|
17
|
+
</span>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
defineProps<{
|
|
22
|
+
isActive: boolean;
|
|
23
|
+
title: string;
|
|
24
|
+
}>();
|
|
25
|
+
</script>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<template v-if="validJsonSchema">
|
|
3
|
+
<template v-if="_.isArray(validJsonSchema)"> </template>
|
|
4
|
+
<template v-else>
|
|
5
|
+
<template v-if="validJsonSchema.type === 'object'">
|
|
6
|
+
<template v-if="validJsonSchema['x-foreignkey']">
|
|
7
|
+
<CustomFieldViewFormFieldInput
|
|
8
|
+
:jsonSchema="validJsonSchema"
|
|
9
|
+
:hierarchy="hierarchy"
|
|
10
|
+
:schemaSource="schemaSource"
|
|
11
|
+
v-model="data[schemaName]"
|
|
12
|
+
/>
|
|
13
|
+
</template>
|
|
14
|
+
<template v-else>
|
|
15
|
+
<Fieldset class="col-span-2 rounded-xl">
|
|
16
|
+
<template #legend>
|
|
17
|
+
<span
|
|
18
|
+
:class="{
|
|
19
|
+
'mx-2': legendTitle && legendTitle !== '',
|
|
20
|
+
}"
|
|
21
|
+
>
|
|
22
|
+
{{ legendTitle }}
|
|
23
|
+
</span>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<div
|
|
27
|
+
class="grid grid-cols-2 gap-4 p-2"
|
|
28
|
+
:class="{
|
|
29
|
+
'pt-4': legendTitle === undefined || legendTitle === '',
|
|
30
|
+
}"
|
|
31
|
+
>
|
|
32
|
+
<template
|
|
33
|
+
v-if="validJsonSchema.properties"
|
|
34
|
+
v-for="(subSchema, subSchemaName) in validJsonSchema.properties"
|
|
35
|
+
:key="subSchemaName"
|
|
36
|
+
>
|
|
37
|
+
<CustomFieldViewFormField
|
|
38
|
+
:jsonSchema="subSchema"
|
|
39
|
+
:data="data[schemaName]"
|
|
40
|
+
:schemaSource="schemaSource"
|
|
41
|
+
:schemaName="subSchemaName as string"
|
|
42
|
+
:hierarchy="
|
|
43
|
+
hierarchy === '' || hierarchy === undefined
|
|
44
|
+
? (subSchemaName as string)
|
|
45
|
+
: `${hierarchy}.${subSchemaName}`
|
|
46
|
+
"
|
|
47
|
+
/>
|
|
48
|
+
</template>
|
|
49
|
+
</div>
|
|
50
|
+
</Fieldset>
|
|
51
|
+
</template>
|
|
52
|
+
</template>
|
|
53
|
+
<template v-else>
|
|
54
|
+
<CustomFieldViewFormFieldInput
|
|
55
|
+
:jsonSchema="validJsonSchema"
|
|
56
|
+
:hierarchy="hierarchy"
|
|
57
|
+
:schemaSource="schemaSource"
|
|
58
|
+
v-model="data[schemaName]"
|
|
59
|
+
/>
|
|
60
|
+
</template>
|
|
61
|
+
</template>
|
|
62
|
+
</template>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script setup lang="ts">
|
|
66
|
+
import _ from "lodash";
|
|
67
|
+
import { SimpleAppJSONSchema7Definition } from "~/types";
|
|
68
|
+
import { SchemaSource } from "~/types/customField.type";
|
|
69
|
+
import CustomFieldViewFormFieldInput from "./CustomFieldViewFormFieldInput.vue";
|
|
70
|
+
|
|
71
|
+
const props = defineProps<{
|
|
72
|
+
jsonSchema?: SimpleAppJSONSchema7Definition | undefined;
|
|
73
|
+
data: any;
|
|
74
|
+
hierarchy: string;
|
|
75
|
+
schemaName: string;
|
|
76
|
+
schemaSource: SchemaSource;
|
|
77
|
+
isHideFieldsetLegend?: boolean;
|
|
78
|
+
}>();
|
|
79
|
+
|
|
80
|
+
const legendTitle = computed(() => {
|
|
81
|
+
if (props.isHideFieldsetLegend) return "";
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
(props.jsonSchema &&
|
|
85
|
+
typeof props.jsonSchema !== "boolean" &&
|
|
86
|
+
props.jsonSchema?.title) ??
|
|
87
|
+
props.schemaName
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
const validJsonSchema = computed(() => {
|
|
91
|
+
if (props.jsonSchema !== undefined && typeof props.jsonSchema === "object") {
|
|
92
|
+
return props.jsonSchema;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
});
|
|
96
|
+
</script>
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<template v-if="jsonSchema.type !== 'array'">
|
|
3
|
+
<div>
|
|
4
|
+
<label v-if="!isParentIsArray" class="text-gray-400 text-sm truncate">
|
|
5
|
+
{{ label }}
|
|
6
|
+
</label>
|
|
7
|
+
<div>
|
|
8
|
+
<PageDocListColumnItem
|
|
9
|
+
:col="columnName"
|
|
10
|
+
:data="{
|
|
11
|
+
[columnName]: model,
|
|
12
|
+
}"
|
|
13
|
+
:schemacols="schemaCols"
|
|
14
|
+
:uniqueKey="''"
|
|
15
|
+
:documentTitle="''"
|
|
16
|
+
:resourcename="''"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
21
|
+
<template
|
|
22
|
+
v-else-if="
|
|
23
|
+
jsonSchema.type === 'array' &&
|
|
24
|
+
jsonSchema.items &&
|
|
25
|
+
_.isObject(jsonSchema.items) &&
|
|
26
|
+
!Array.isArray(jsonSchema.items)
|
|
27
|
+
"
|
|
28
|
+
>
|
|
29
|
+
<template v-if="jsonSchema.items.type === 'object'">
|
|
30
|
+
<div class="col-span-2">
|
|
31
|
+
<SimpleAppInputTable
|
|
32
|
+
:getField="() => {}"
|
|
33
|
+
class="col-span-4"
|
|
34
|
+
:setting="{
|
|
35
|
+
readonly: true,
|
|
36
|
+
}"
|
|
37
|
+
v-model="model"
|
|
38
|
+
>
|
|
39
|
+
<Column
|
|
40
|
+
v-if="
|
|
41
|
+
jsonSchema.items &&
|
|
42
|
+
typeof jsonSchema.items === 'object' &&
|
|
43
|
+
'properties' in jsonSchema.items
|
|
44
|
+
"
|
|
45
|
+
v-for="(subSchema, subSchemaName) in jsonSchema.items.properties"
|
|
46
|
+
:key="subSchemaName"
|
|
47
|
+
:field="subSchemaName.toString()"
|
|
48
|
+
#body="{ index }"
|
|
49
|
+
:header="camelCaseToWords(subSchemaName.toString())"
|
|
50
|
+
>
|
|
51
|
+
<CustomFieldViewFormFieldInput
|
|
52
|
+
v-if="typeof subSchema === 'object' && subSchema !== null"
|
|
53
|
+
:jsonSchema="subSchema"
|
|
54
|
+
:hierarchy="
|
|
55
|
+
hierarchy === '' || hierarchy === undefined
|
|
56
|
+
? (subSchemaName as string)
|
|
57
|
+
: `${hierarchy}.*.${subSchemaName}`
|
|
58
|
+
"
|
|
59
|
+
:schemaSource="schemaSource"
|
|
60
|
+
v-model="model[index][subSchemaName]"
|
|
61
|
+
/>
|
|
62
|
+
</Column>
|
|
63
|
+
</SimpleAppInputTable>
|
|
64
|
+
</div>
|
|
65
|
+
</template>
|
|
66
|
+
<template v-else-if="jsonSchema.items.type === 'string'">
|
|
67
|
+
<div>
|
|
68
|
+
<label v-if="!isParentIsArray" class="text-gray-400 text-sm truncate">
|
|
69
|
+
{{ label }}
|
|
70
|
+
</label>
|
|
71
|
+
<div>
|
|
72
|
+
<PageDocListColumnItem
|
|
73
|
+
:col="columnName"
|
|
74
|
+
:data="{
|
|
75
|
+
[columnName]: model,
|
|
76
|
+
}"
|
|
77
|
+
:schemacols="schemaCols"
|
|
78
|
+
:uniqueKey="''"
|
|
79
|
+
:documentTitle="''"
|
|
80
|
+
:resourcename="''"
|
|
81
|
+
/>
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
</template>
|
|
85
|
+
</template>
|
|
86
|
+
</template>
|
|
87
|
+
|
|
88
|
+
<script setup lang="ts">
|
|
89
|
+
import _ from "lodash";
|
|
90
|
+
import PageDocListColumnItem from "~/components/page/PageDocListColumnItem.vue";
|
|
91
|
+
import {
|
|
92
|
+
SchemaFields,
|
|
93
|
+
SimpleAppInputType,
|
|
94
|
+
SimpleAppJSONSchema7,
|
|
95
|
+
} from "~/types";
|
|
96
|
+
import { SchemaSource } from "~/types/customField.type";
|
|
97
|
+
|
|
98
|
+
const props = defineProps<{
|
|
99
|
+
jsonSchema: SimpleAppJSONSchema7;
|
|
100
|
+
hierarchy: string;
|
|
101
|
+
schemaSource: SchemaSource;
|
|
102
|
+
}>();
|
|
103
|
+
|
|
104
|
+
const model = defineModel<any>();
|
|
105
|
+
|
|
106
|
+
const columnName = computed(() => {
|
|
107
|
+
return props.hierarchy.split(".").pop() ?? "";
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const schemaCols = computed(() => {
|
|
111
|
+
return {
|
|
112
|
+
[columnName.value]: props.jsonSchema,
|
|
113
|
+
} as SchemaFields;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const label = computed(() => {
|
|
117
|
+
return props.jsonSchema.title ?? props.hierarchy.split(".").pop();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const fieldPath = computed(() => {
|
|
121
|
+
const hierarchies = props.hierarchy.split(".");
|
|
122
|
+
|
|
123
|
+
const path = (getFieldPathPrefix() + hierarchies.join("/properties/"))
|
|
124
|
+
.replace("properties/*", "items")
|
|
125
|
+
.replace("*", "items");
|
|
126
|
+
|
|
127
|
+
// if (props.schemaSource === "miniAppSetting") {
|
|
128
|
+
// return path.replace("/properties/setting", "");
|
|
129
|
+
// }
|
|
130
|
+
|
|
131
|
+
return path;
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const inputType = computed(() => {
|
|
135
|
+
return getInputType(props.jsonSchema);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const isParentIsArray = computed(() => {
|
|
139
|
+
const hierarchies = props.hierarchy.split(".");
|
|
140
|
+
return hierarchies[hierarchies.length - 2] == "*";
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
function getFieldPathPrefix() {
|
|
144
|
+
if (props.schemaSource === "customField") {
|
|
145
|
+
return "#/properties/more/properties/";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return "#/properties/";
|
|
149
|
+
}
|
|
150
|
+
</script>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<section v-if="validProperties" class="space-y-4">
|
|
3
|
+
<template
|
|
4
|
+
v-for="(groupJsonSchema, groupName) in validProperties"
|
|
5
|
+
:key="groupName"
|
|
6
|
+
>
|
|
7
|
+
<CustomFieldViewFormField
|
|
8
|
+
v-if="isValidSchema(groupJsonSchema)"
|
|
9
|
+
:jsonSchema="groupJsonSchema"
|
|
10
|
+
:data="data"
|
|
11
|
+
:schemaName="groupName.toString()"
|
|
12
|
+
:hierarchy="groupName.toString()"
|
|
13
|
+
schemaSource="customField"
|
|
14
|
+
/>
|
|
15
|
+
</template>
|
|
16
|
+
</section>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import _ from 'lodash';
|
|
21
|
+
import { CustomFieldMoreSchema } from '~/simpleapp/generate/features/customField/types/common';
|
|
22
|
+
import CustomFieldViewFormField from './CustomFieldViewFormField.vue';
|
|
23
|
+
|
|
24
|
+
const props = defineProps<{
|
|
25
|
+
customFieldJsonSchema: CustomFieldMoreSchema;
|
|
26
|
+
data: any;
|
|
27
|
+
}>();
|
|
28
|
+
|
|
29
|
+
const validProperties = computed(() => {
|
|
30
|
+
if (
|
|
31
|
+
props.customFieldJsonSchema.properties !== undefined &&
|
|
32
|
+
typeof props.customFieldJsonSchema.properties === 'object'
|
|
33
|
+
) {
|
|
34
|
+
return props.customFieldJsonSchema.properties;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const useCustomFieldDocList = () => {
|
|
2
|
+
function isCustomField(jsonSchema: any, col: string): boolean {
|
|
3
|
+
return (
|
|
4
|
+
col.startsWith("more.default.") &&
|
|
5
|
+
!!getCustomFieldSchemaItem(jsonSchema, col)
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getCustomFieldSchemaItem(jsonSchema: any, col: string): any {
|
|
10
|
+
const key = col.replace("more.default.", "");
|
|
11
|
+
return jsonSchema?.more?.properties?.default?.properties?.[key];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getCustomFieldSchema(jsonSchema: any, col: string): any {
|
|
15
|
+
return jsonSchema?.more?.properties?.default?.properties ?? {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getCustomFieldSchemaKey(jsonSchema: any, col: string): any {
|
|
19
|
+
const key = col.replace("more.default.", "");
|
|
20
|
+
return key;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getCustomFieldData(data: any): any {
|
|
24
|
+
return data?.more?.default;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getCustomFieldTitle(jsonSchema: any, col: string): string {
|
|
28
|
+
return (
|
|
29
|
+
getCustomFieldSchemaItem(jsonSchema, col)?.title ??
|
|
30
|
+
col.split(".").pop() ??
|
|
31
|
+
col
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getCustomFieldField(jsonSchema: any, col: string): string {
|
|
36
|
+
const schema = getCustomFieldSchemaItem(jsonSchema, col);
|
|
37
|
+
return schema?.["x-foreignkey"] ? `${col}.label` : col;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
isCustomField,
|
|
42
|
+
getCustomFieldSchema,
|
|
43
|
+
getCustomFieldSchemaKey,
|
|
44
|
+
getCustomFieldData,
|
|
45
|
+
getCustomFieldTitle,
|
|
46
|
+
getCustomFieldField,
|
|
47
|
+
};
|
|
48
|
+
};
|
package/templates/nuxt/simpleapp/generate/features/customField/services/CustomFieldService.ts.eta
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import {
|
|
3
|
+
CustomFieldDataMode,
|
|
4
|
+
CustomFieldMoreSchema,
|
|
5
|
+
CustomFieldMoreSchemaGroup
|
|
6
|
+
} from '../types/common';
|
|
7
|
+
import { CustomFieldDataModeEnum } from '../enums/common';
|
|
8
|
+
import { DynamicObject, SimpleAppJSONSchema7Definition } from '~/types';
|
|
9
|
+
|
|
10
|
+
export class CustomFieldService {
|
|
11
|
+
// =============================== Prepare Schema Function ===============================
|
|
12
|
+
prepareCustomFieldJsonSchema(collectionName: string) {
|
|
13
|
+
const customFieldFromDB = this.findCustomFieldSchemaFromDB(collectionName);
|
|
14
|
+
const customFieldFromMiniApp =
|
|
15
|
+
this.findCustomFieldSchemaFromMiniApp(collectionName);
|
|
16
|
+
|
|
17
|
+
if (customFieldFromDB && !_.isEmpty(customFieldFromDB)) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const schema: CustomFieldMoreSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
...customFieldFromDB,
|
|
24
|
+
...customFieldFromMiniApp
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return schema;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private findCustomFieldSchemaFromDB(collectionName: string) {
|
|
32
|
+
const { $customFieldStore } = useNuxtApp();
|
|
33
|
+
if (!$customFieldStore.data || _.isEmpty($customFieldStore.data)) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const customField = $customFieldStore.findByCollectionName(collectionName);
|
|
38
|
+
if (!customField) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (
|
|
43
|
+
!customField?.form?.jsonSchema ||
|
|
44
|
+
_.isEmpty(customField?.form?.jsonSchema)
|
|
45
|
+
) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const schema: CustomFieldMoreSchemaGroup = {
|
|
50
|
+
default: {
|
|
51
|
+
title: 'Custom Field',
|
|
52
|
+
...customField.form.jsonSchema
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return schema;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private findCustomFieldSchemaFromMiniApp(collectionName: string) {
|
|
60
|
+
const schema: CustomFieldMoreSchemaGroup = {};
|
|
61
|
+
|
|
62
|
+
const { $miniAppStore } = useNuxtApp();
|
|
63
|
+
|
|
64
|
+
const miniAppForms = $miniAppStore.getForm(collectionName);
|
|
65
|
+
if (!miniAppForms || miniAppForms.length <= 0) {
|
|
66
|
+
return schema;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
for (let i = 0; i < miniAppForms.length; i++) {
|
|
70
|
+
const miniAppItem = miniAppForms[i];
|
|
71
|
+
const { miniAppCode, jsonSchema } = miniAppItem;
|
|
72
|
+
|
|
73
|
+
schema[miniAppCode] = jsonSchema as SimpleAppJSONSchema7Definition;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return schema;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ================================ Prepare Data Function ================================
|
|
80
|
+
prepareCustomFieldData<T extends DynamicObject>(
|
|
81
|
+
collectionName: string,
|
|
82
|
+
mode: CustomFieldDataMode,
|
|
83
|
+
customSchema: CustomFieldMoreSchema | undefined,
|
|
84
|
+
resourceData: T | undefined
|
|
85
|
+
): T | undefined {
|
|
86
|
+
if (
|
|
87
|
+
!customSchema ||
|
|
88
|
+
!customSchema?.properties ||
|
|
89
|
+
_.isEmpty(customSchema.properties)
|
|
90
|
+
) {
|
|
91
|
+
return resourceData;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
switch (mode) {
|
|
95
|
+
case CustomFieldDataModeEnum.DEFAULT:
|
|
96
|
+
return this.prepareCustomFieldWithDefaultData<T>(customSchema);
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
case CustomFieldDataModeEnum.EXISTING:
|
|
100
|
+
if (!resourceData) {
|
|
101
|
+
return this.prepareCustomFieldWithDefaultData<T>(customSchema);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return this.prepareCustomFieldWithExistingData(
|
|
105
|
+
customSchema,
|
|
106
|
+
resourceData
|
|
107
|
+
);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private prepareCustomFieldWithDefaultData<T extends DynamicObject>(
|
|
113
|
+
customSchema: CustomFieldMoreSchema
|
|
114
|
+
) {
|
|
115
|
+
const data: DynamicObject = {};
|
|
116
|
+
for (const [groupName, groupItem] of Object.entries(
|
|
117
|
+
customSchema.properties
|
|
118
|
+
)) {
|
|
119
|
+
const defaultData = this.generateDefaultData(groupItem);
|
|
120
|
+
|
|
121
|
+
data[groupName] = defaultData;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return data as T;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private prepareCustomFieldWithExistingData<T extends DynamicObject>(
|
|
128
|
+
customSchema: CustomFieldMoreSchema,
|
|
129
|
+
resourceData: T
|
|
130
|
+
) {
|
|
131
|
+
const data: DynamicObject = {};
|
|
132
|
+
for (const [groupName, groupItem] of Object.entries(
|
|
133
|
+
customSchema.properties
|
|
134
|
+
)) {
|
|
135
|
+
const defaultData = this.generateDefaultData(groupItem);
|
|
136
|
+
const mergedData = this.mergeWithDefault(
|
|
137
|
+
defaultData,
|
|
138
|
+
resourceData?.[groupName]
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
data[groupName] = mergedData;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return data as T;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
private generateDefaultData(schema: SimpleAppJSONSchema7Definition): any {
|
|
148
|
+
if (!_.isObject(schema)) {
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (schema.type === 'object') {
|
|
153
|
+
const result: any = {};
|
|
154
|
+
|
|
155
|
+
if (schema?.['x-foreignkey']) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const properties = schema.properties || {};
|
|
160
|
+
for (const key of Object.keys(properties)) {
|
|
161
|
+
result[key] = this.generateDefaultData(properties[key]);
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (schema.type === 'array') {
|
|
167
|
+
const itemSchema = schema.items;
|
|
168
|
+
const minItems = schema.minItems || 0;
|
|
169
|
+
const arr = [];
|
|
170
|
+
const itemsCount = minItems > 0 ? 1 : 0;
|
|
171
|
+
for (let i = 0; i < itemsCount; i++) {
|
|
172
|
+
arr.push(
|
|
173
|
+
this.generateDefaultData(itemSchema as SimpleAppJSONSchema7Definition)
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
return arr;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (typeof schema.default !== 'undefined') {
|
|
180
|
+
return schema.default;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// handle primitive types fallback
|
|
184
|
+
switch (schema.type) {
|
|
185
|
+
case 'string':
|
|
186
|
+
return '';
|
|
187
|
+
case 'number':
|
|
188
|
+
case 'integer':
|
|
189
|
+
return 0;
|
|
190
|
+
case 'boolean':
|
|
191
|
+
return false;
|
|
192
|
+
default:
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private mergeWithDefault<T extends DynamicObject>(
|
|
198
|
+
defaultData: T,
|
|
199
|
+
collectionData: T | undefined
|
|
200
|
+
) {
|
|
201
|
+
if (Array.isArray(defaultData)) {
|
|
202
|
+
if (Array.isArray(collectionData)) {
|
|
203
|
+
if (_.isEmpty(collectionData)) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
// Merge each item
|
|
207
|
+
const mergedArray = collectionData.map((collectionItem, index) => {
|
|
208
|
+
const defaultItem = defaultData[index] ?? defaultData[0]; // use first default if index out of bound
|
|
209
|
+
return this.mergeWithDefault<T>(defaultItem, collectionItem);
|
|
210
|
+
}) as any;
|
|
211
|
+
return mergedArray;
|
|
212
|
+
} else {
|
|
213
|
+
// return defaultData;
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
} else if (typeof defaultData === 'object' && defaultData !== null) {
|
|
217
|
+
const result: any = {};
|
|
218
|
+
for (const key of Object.keys(defaultData)) {
|
|
219
|
+
result[key] = this.mergeWithDefault(
|
|
220
|
+
defaultData[key],
|
|
221
|
+
collectionData?.[key]
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
} else {
|
|
226
|
+
return typeof collectionData !== 'undefined'
|
|
227
|
+
? collectionData
|
|
228
|
+
: defaultData;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SimpleAppJSONSchema7, SimpleAppJSONSchema7Definition } from '~/types';
|
|
2
|
+
import { CustomFieldDataModeEnum } from '../enums/common';
|
|
3
|
+
|
|
4
|
+
export type CustomFieldDataMode = CustomFieldDataModeEnum;
|
|
5
|
+
|
|
6
|
+
export type CustomFieldMore = {
|
|
7
|
+
more?: CustomFieldMoreSchema;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type CustomFieldMoreSchema = SimpleAppJSONSchema7 & {
|
|
11
|
+
properties: CustomFieldMoreSchemaGroup;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CustomFieldMoreSchemaGroup = {
|
|
15
|
+
[key: string]: SimpleAppJSONSchema7Definition;
|
|
16
|
+
};
|