@simitgroup/simpleapp-generator 2.0.3-k-alpha → 2.0.3-m-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 CHANGED
@@ -1,3 +1,9 @@
1
+ [2.0.3m-alpha]
2
+ 1. Extract BridgeResourceAccessorBase for extensibility
3
+
4
+ [2.0.3l-alpha]
5
+ 1. Remove docnoformat form and page templates
6
+
1
7
  [2.0.3k-alpha]
2
8
  1. Update sharelibs imports to @simtrain/shared package
3
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simitgroup/simpleapp-generator",
3
- "version": "2.0.3k-alpha",
3
+ "version": "2.0.3m-alpha",
4
4
  "description": "frontend nuxtjs and backend nests code generator using jsonschema.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -34,11 +34,11 @@ import { MiniAppBridgeService } from "./bridge.service";
34
34
  const { pascalName, kebabName, hasMiniAppWhitelistedApi } = getMiniAppInfo(it.modules[i]);
35
35
  %>
36
36
  <% if(hasMiniAppWhitelistedApi) { %>
37
- import { MiniApp<%= pascalName %>BridgeService } from "../services/resources/<%= kebabName %>-bridge.service";
37
+ import { MiniApp<%= pascalName %>BridgeService } from "./resources/<%= kebabName %>-bridge.service";
38
38
  <% } %>
39
39
  <% } %>
40
40
 
41
- export class MiniAppBridgeResourceAccessor {
41
+ export class MiniAppBridgeResourceAccessorBase {
42
42
  protected bridge: MiniAppBridgeService;
43
43
  protected instances: Partial<MiniAppResourceMap> = {};
44
44
 
@@ -0,0 +1,10 @@
1
+ import { MiniAppBridgeResourceAccessorBase } from "./bridge-resource-accessor-base.service";
2
+
3
+ export class MiniAppBridgeResourceAccessor extends MiniAppBridgeResourceAccessorBase {
4
+ protected customInstances: Partial<{
5
+ }> = {};
6
+
7
+ constructor() {
8
+ super();
9
+ }
10
+ }
@@ -36,7 +36,7 @@ import { MiniAppResourceMap } from "../types/resource-mapper.type";
36
36
  <% } %>
37
37
  <% } %>
38
38
 
39
- export class MiniAppBridgeResourceAccessor {
39
+ export class MiniAppBridgeResourceAccessorBase {
40
40
  protected instances: Partial<MiniAppResourceMap> = {};
41
41
 
42
42
  protected miniAppCode: string = "";
@@ -0,0 +1,6 @@
1
+ import { MiniAppBridgeResourceAccessorBase } from "./bridge-resource-accessor-base.service";
2
+
3
+ export class MiniAppBridgeResourceAccessor extends MiniAppBridgeResourceAccessorBase {
4
+ protected customInstances: Partial<{
5
+ }> = {};
6
+ }
@@ -5,29 +5,25 @@
5
5
  * Author: --
6
6
  */
7
7
 
8
+ import { AxiosError } from "axios";
8
9
  import { SimpleAppDocumentType } from "~/types";
10
+ import { MINI_APP_BRIDGE_MESSAGES } from "../constants/common.constant";
11
+ import { MINI_APP_API_CUSTOM_RESOURCES } from "../constants/custom-resource.constant";
12
+ import { MINI_APP_API_RESOURCES } from "../constants/resource.constant";
9
13
  import {
10
14
  MiniAppBridgeMessageApi,
11
15
  MiniAppBridgeMessageNavigate,
12
16
  MiniAppBridgeMessageNavigateCurrentMiniApp,
13
17
  MiniAppBridgeMessageOpenOnScreenResourceForm,
14
18
  } from "../types/bridge.type";
15
- import { AxiosError } from "axios";
16
- import { MINI_APP_BRIDGE_MESSAGES } from "../constants/common.constant";
17
19
  import { MiniAppResourceMap } from "../types/resource-mapper.type";
18
20
  import { MiniAppBridgeResourceAccessor } from "./bridge-resource-accessor.service";
19
- import { MINI_APP_API_RESOURCES } from "../constants/resource.constant";
20
21
 
21
22
  export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
22
23
  /**************************************** Bridge Handler ***************************************/
23
24
 
24
25
  handleBridgeNavigate(message: MiniAppBridgeMessageNavigate) {
25
- goTo(
26
- message.params.target,
27
- message.params.id,
28
- message.params.query,
29
- message.params.options,
30
- );
26
+ goTo(message.params.target, message.params.id, message.params.query, message.params.options);
31
27
  }
32
28
 
33
29
  handleBridgeNavigateCurrentMiniApp(
@@ -48,9 +44,7 @@ export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
48
44
  goTo(targetUrl, undefined, message.params.query, message.params.options);
49
45
  }
50
46
 
51
- handleBridgeOpenOnScreenResourceForm(
52
- message: MiniAppBridgeMessageOpenOnScreenResourceForm,
53
- ) {
47
+ handleBridgeOpenOnScreenResourceForm(message: MiniAppBridgeMessageOpenOnScreenResourceForm) {
54
48
  if (message.params.resource.id) {
55
49
  onScreenEditDocument(
56
50
  message.params.resource.name as SimpleAppDocumentType,
@@ -108,10 +102,8 @@ export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
108
102
  data: (err.response.data as any)?.data ?? "",
109
103
  error: (err.response.data as any)?.error ?? "",
110
104
  message: (err.response.data as any)?.message ?? "",
111
- statusCode:
112
- (err.response.data as any)?.statusCode ?? "",
113
- statusMessage:
114
- (err.response.data as any)?.statusMessage ?? "",
105
+ statusCode: (err.response.data as any)?.statusCode ?? "",
106
+ statusMessage: (err.response.data as any)?.statusMessage ?? "",
115
107
  }
116
108
  : {},
117
109
  status: err.response.status,
@@ -129,11 +121,11 @@ export class MiniAppBridgeService extends MiniAppBridgeResourceAccessor {
129
121
 
130
122
  private async handleBridgeCallApi(message: MiniAppBridgeMessageApi<any>) {
131
123
  const resourceName = message.params.resource.name;
132
-
133
124
  if (!MINI_APP_API_RESOURCES.includes(resourceName)) {
134
- throw new Error(`Unknown resource name: ${resourceName}`);
125
+ if (!MINI_APP_API_CUSTOM_RESOURCES.includes(resourceName)) {
126
+ throw new Error(`Unknown resource name: ${resourceName}`);
127
+ }
135
128
  }
136
-
137
129
  const bridge = this[resourceName as keyof MiniAppResourceMap];
138
130
  return await bridge.handleApi(message);
139
131
  }
@@ -1,240 +0,0 @@
1
- <template>
2
- <div>
3
- <title v-if="id">{{ data.docNoFormatName ?? data.docNoFormatNo }}</title>
4
-
5
- <SimpleAppForm #default="o" :document="doc">
6
- <SimpleAppFormToolBar
7
- :document="doc"
8
- @on="actionListener"
9
- ></SimpleAppFormToolBar>
10
- <div class="grid grid-cols-1 lg:grid-cols-2 gap-4 p-2">
11
- <SimpleAppInput
12
- :input-type="SimpleAppInputType.autocomplete"
13
- :setting="o.getField('#/properties/branch')"
14
- v-model="data.branch"
15
- />
16
- <SimpleAppInput
17
- :readonly="!doc.isNew()"
18
- :input-type="SimpleAppInputType.select"
19
- :setting="o.getField('#/properties/docNoType')"
20
- :options="
21
- getAllDocFormats().map((item) => ({
22
- label: docNoTypeMapping[item.docType] || item.docType,
23
- value: item.docType,
24
- }))
25
- "
26
- v-model="data.docNoType"
27
- />
28
-
29
- <SimpleAppInput
30
- :input-type="SimpleAppInputType.text"
31
- :setting="o.getField('#/properties/docNoFormatNo')"
32
- v-model="data.docNoFormatNo"
33
- />
34
-
35
- <SimpleAppInput
36
- :input-type="SimpleAppInputType.text"
37
- :setting="o.getField('#/properties/docNoFormatName')"
38
- v-model="data.docNoFormatName"
39
- />
40
-
41
- <SimpleAppInput
42
- :input-type="SimpleAppInputType.checkbox"
43
- :setting="o.getField('#/properties/active')"
44
- v-model="data.active"
45
- />
46
- <SimpleAppInput
47
- :input-type="SimpleAppInputType.checkbox"
48
- :setting="o.getField('#/properties/default')"
49
- v-model="data.default"
50
- />
51
-
52
- <SimpleAppInput
53
- :input-type="SimpleAppInputType.text"
54
- :setting="o.getField('#/properties/docNoPattern')"
55
- v-model="data.docNoPattern"
56
- @keyup="updateSample"
57
- :description="sample"
58
- v-tooltip="'Examples: PO-[00000], SI{YY}/[000], SI{YYMM}/[000]'"
59
- />
60
-
61
- <SimpleAppInput
62
- :input-type="SimpleAppInputType.number"
63
- :setting="o.getField('#/properties/nextNumber')"
64
- v-model="data.nextNumber"
65
- />
66
- </div>
67
- </SimpleAppForm>
68
- <DebugDocumentData v-model="data" :label="doc.getDocName()" />
69
- <DataTable
70
- :value="formatParams"
71
- class="p-datatable-sm mt-6"
72
- stripedRows
73
- responsiveLayout="scroll"
74
- >
75
- <template #header>
76
- <div class="text-sm font-semibold">Format Parameters</div>
77
- </template>
78
- <Column
79
- field="placeholder"
80
- header="Placeholder"
81
- style="width: 30%"
82
- class="text-xs"
83
- />
84
- <Column field="description" header="Description" class="text-xs" />
85
- </DataTable>
86
- </div>
87
- </template>
88
-
89
- <script setup lang="ts">
90
- /**
91
- * This file was automatically generated by simpleapp generator.
92
- * last change 2024-02-16
93
- * Author: Ks Tan
94
- */
95
- import { SimpleAppInputType, FormCrudEvent } from "~/types";
96
- import { DocumentNoFormat } from "~/simpleapp/generate/openapi";
97
- import { DocumentnoformatDoc } from "~/simpleapp/docs/DocumentnoformatDoc";
98
-
99
- const props = defineProps<{
100
- _id?: string;
101
- doc?: DocumentnoformatDoc;
102
- paras?: Partial<DocumentNoFormat>;
103
- }>();
104
-
105
- const doc = props.doc ?? useNuxtApp().$DocumentnoformatDoc()
106
- const data = doc.getReactiveData();
107
- const sample = ref("");
108
- const emits = defineEmits(["after"]);
109
- const id = computed(() => props._id ?? "");
110
-
111
- /************ start default methods ****************/
112
-
113
- const newData = () => {
114
- doc.setNew();
115
- delete data.value.branch;
116
- };
117
-
118
- const formatParams = [
119
- {
120
- placeholder: "[0000]",
121
- description: "0001 displays the transaction numbering.",
122
- },
123
- {
124
- placeholder: "{YYYY}",
125
- description: "Displays 4-digit current year (e.g., 2025-9999).",
126
- },
127
- {
128
- placeholder: "{YY}",
129
- description: "Displays 2-digit current year (e.g., 25).",
130
- },
131
- {
132
- placeholder: "{MM}",
133
- description: "Displays 2-digit current month (e.g., 01-12).",
134
- },
135
- { placeholder: "{ddd}", description: "Displays current day (e.g., Tue)." },
136
- {
137
- placeholder: "{DD}",
138
- description: "Displays 2-digit day of the month (e.g., 01-31).",
139
- },
140
- {
141
- placeholder: "{YYMM}",
142
- description: "Displays 2-digit year and 2-digit month (e.g., 2504).",
143
- },
144
- {
145
- placeholder: "{YYYYMM}",
146
- description: "Displays 4-digit year and 2-digit month (e.g., 202504).",
147
- },
148
- ];
149
-
150
- const getRecord = async () => {
151
- if (id.value && id.value != "new") {
152
- await doc.getById(id.value);
153
- } else {
154
- newData();
155
- }
156
- };
157
-
158
- const docNoTypeMapping: Record<string, string> = {
159
- CN: "Credit Note",
160
- ANNOUNCEMENT: "Announcement",
161
- ENROLL: "Enrolment",
162
- INV: "Invoice",
163
- PAY: "Payment",
164
- REFUND: "Refund",
165
- STU: "Student",
166
- TEACHER: "Teacher",
167
- TUITION: "Tuition Class",
168
- };
169
-
170
- getRecord();
171
- watch(id, async () => await getRecord());
172
- /************ end default methods ****************/
173
-
174
- const actionListener = async (actionName: string) => {
175
- emits("after", actionName, data.value);
176
- };
177
-
178
- onMounted(async () => {
179
- await actionListener(FormCrudEvent.mount);
180
- setTimeout(() => {
181
- updateSample();
182
- }, 300);
183
- });
184
- /************ start api methods ****************/
185
-
186
- // const runListDocFormats = async () => {
187
- // const data = {
188
- // id: id.value,
189
- // };
190
- // const result = await doc.runListDocFormats(
191
- // doctype,
192
-
193
- // data,
194
- // );
195
- // };
196
- /************ end api methods ****************/
197
- const updateSample = () => {
198
- sample.value = "Format Sample: " + previewDocNo();
199
- };
200
-
201
- const previewDocNo = (): string => {
202
- const pattern = data.value.docNoPattern;
203
- if (pattern) {
204
- const numberReg: RegExp = /\[(.*?)\]/g;
205
- const dateReg: RegExp = /\{(.*?)\}/g;
206
- let newvalue = pattern;
207
- const numberpattern = pattern.match(numberReg);
208
- const datepattern = pattern.match(dateReg);
209
-
210
- if (numberpattern && numberpattern.length > 0) {
211
- const numberlength = numberpattern[0]
212
- .replace("[", "")
213
- .replace("]", "").length;
214
-
215
- let nextnumber = (data.value.nextNumber ?? 0).toString();
216
-
217
- const numberdiff = numberlength - nextnumber.length;
218
-
219
- for (let n = 0; n < numberdiff; n++) {
220
- nextnumber = "0" + nextnumber;
221
- }
222
- newvalue = newvalue.replace(numberpattern[0], nextnumber);
223
- }
224
-
225
- if (datepattern && datepattern.length > 0) {
226
- for (let d = 0; d < datepattern.length; d++) {
227
- const dpattern = datepattern[d];
228
- const date = new Date();
229
- const formatteddate = getDayJs()().format(
230
- dpattern.replace("{", "").replace("}", ""),
231
- );
232
- newvalue = newvalue.replace(dpattern, formatteddate);
233
- }
234
- }
235
- return newvalue;
236
- } else {
237
- return "";
238
- }
239
- };
240
- </script>
@@ -1,37 +0,0 @@
1
- <template>
2
- <LazyFormDocnoformat :_id="_id" @after="after" />
3
- </template>
4
-
5
- <script setup lang="ts">
6
- /**
7
- * This file was automatically generated by simpleapp generator.
8
- * last change 2023-09-09
9
- * author: Ks Tan
10
- */
11
-
12
- import { Docnoformat } from "~/simpleapp/generate/types";
13
- const doc = useNuxtApp().$DocnoformatDoc();
14
-
15
- const props = defineProps<{ _id: string }>();
16
- const after = (actionName: string, data: Docnoformat) => {
17
- switch (actionName) {
18
- case "new":
19
- goTo(doc.getDocName(), "new");
20
- break;
21
- case "create":
22
- goTo(doc.getDocName(), data._id);
23
- refreshDocumentList(doc.getDocName());
24
- useNuxtApp().$event("CloseDialog", doc.getDocName().toLowerCase());
25
- break;
26
- case "update":
27
- refreshDocumentList(doc.getDocName());
28
- useNuxtApp().$event("CloseDialog", doc.getDocName().toLowerCase());
29
- break;
30
- case "delete":
31
- goTo(doc.getDocName(), "new");
32
- refreshDocumentList(doc.getDocName());
33
- useNuxtApp().$event("CloseDialog", doc.getDocName().toLowerCase());
34
- break;
35
- }
36
- };
37
- </script>