@simitgroup/simpleapp-generator 2.0.3-e-alpha → 2.0.3-g-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 +7 -0
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +5 -10
- package/dist/generate.js.map +1 -1
- package/package.json +1 -1
- package/src/generate.ts +5 -11
- package/templates/nest/src/app.service.ts.eta +1 -5
- package/templates/nest/src/simple-app/_core/features/mini-app/mini-app-manager/mini-app-manager-policy.service.ts.eta +2 -2
- package/templates/nest/src/simple-app/_core/features/policy/policy.service.ts.eta +3 -4
- package/templates/nest/src/simple-app/_core/features/user-context/user.context.ts.eta +0 -7
- package/templates/nest/src/simple-app/_core/framework/base/simple-app.service.ts.eta +0 -4
- package/templates/nest/src/simple-app/_core/framework/schemas/simple-app.schema.ts.eta +0 -1
- package/templates/nuxt/composables/date.generate.ts.eta +18 -17
- package/templates/nuxt/composables/getOpenApi.generate.ts.eta +11 -26
- package/templates/nuxt/types/index.ts._eta +0 -1
- package/templates/nuxt/types/schema.ts.eta +12 -11
- package/README copy.md +0 -1283
- package/src/processors/bpmnbuilder.ts +0 -167
- package/templates/nest/src/simple-app/config/license-types/index.ts._eta +0 -1
- package/templates/nuxt/components/header/button/task/HeaderButtonTaskItem.vue.eta +0 -28
- package/templates/nuxt/components/header/button/task/HeaderButtonTaskList.vue._eta +0 -114
- package/templates/nuxt/components/workflow/forms/dynamicfield.vue._eta +0 -92
- package/templates/nuxt/components/workflow/forms/index.ts._eta +0 -17
- package/templates/nuxt/components/workflow/forms/simpleapprove.vue._eta +0 -49
- package/templates/nuxt/composables/workflow.generate.ts.eta +0 -27
- package/templates/nuxt/simpleapp/workflows/bpmn/readme.md._eta +0 -1
- package/templates/nuxt/simpleapp/workflows/forms/index.ts._eta +0 -8
- package/templates/nuxt/simpleapp/workflows/forms/readme.md._eta +0 -1
- package/templates/nuxt/simpleapp/workflows/forms/simpleapprove.jsonschema.ts._eta +0 -14
- package/templates/nuxt/types/workflow.ts.eta +0 -25
- package/templates/project/workflows/bpmn/sayhello.bpmn._eta +0 -42
- package/templates/project/workflows/forms/index.ts._eta +0 -2
- package/templates/project/workflows/forms/simpleapprove.jsonschema.ts._eta +0 -8
- package/templates/workflow/next/listener.ts.eta +0 -79
package/README copy.md
DELETED
|
@@ -1,1283 +0,0 @@
|
|
|
1
|
-
# Quick start
|
|
2
|
-
1. git clone from simpleapp-generator
|
|
3
|
-
```sh
|
|
4
|
-
git clone https://github.com/SIMITGROUP/simpleapp-generator-template myapp
|
|
5
|
-
cd ~/myapp
|
|
6
|
-
simpleapp-generator -c config.json
|
|
7
|
-
```
|
|
8
|
-
2. start backend
|
|
9
|
-
```sh
|
|
10
|
-
cd ~/myapp/backend
|
|
11
|
-
pnpm start:dev
|
|
12
|
-
```
|
|
13
|
-
3. start frontend
|
|
14
|
-
```sh
|
|
15
|
-
cd ~/myapp/frontend
|
|
16
|
-
pnpm dev
|
|
17
|
-
```
|
|
18
|
-
4. try ui:
|
|
19
|
-
* frontend: (http://localhost:8080)[http://localhost:8080]
|
|
20
|
-
* backend: (http://localhost:8000/api)[http://localhost:8000/api]
|
|
21
|
-
5. Match the json schema and the generated forms
|
|
22
|
-
```sh
|
|
23
|
-
code ~/mydoc
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
# Concept of Development
|
|
27
|
-
Development using simpleapp-generator involve below steps:
|
|
28
|
-
[Simple]
|
|
29
|
-
1. create appropriate jsonschema
|
|
30
|
-
2. generate frontend and backend architectures
|
|
31
|
-
3. start backend service, obtain and save api definations into openapi.yaml
|
|
32
|
-
4. regenerate codes so frontend can obtain openapi clients
|
|
33
|
-
5. align frontend UI, add necessary component such as css and ui components
|
|
34
|
-
|
|
35
|
-
[Advance]
|
|
36
|
-
1. complete simple task
|
|
37
|
-
2. add more api/process at backend `controller`,`service`,`schema`. Such as:
|
|
38
|
-
a. special search
|
|
39
|
-
b. special workflows
|
|
40
|
-
c. connect external api
|
|
41
|
-
d. additional data processing and validation which is not supported by jsonschema (AJV)
|
|
42
|
-
3. security like sso/jwt, plugins
|
|
43
|
-
a. keycloak integration at frontends
|
|
44
|
-
b. backend manage jwt
|
|
45
|
-
4. allow additional field formats, validations by modifying ajv
|
|
46
|
-
a. allow custom jsonschema field property, and do something at backend
|
|
47
|
-
b. allow custom field format, and do something at backend
|
|
48
|
-
5. repeat same typscript formula at frontend and backend
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
after generate
|
|
52
|
-
1. `./backend/tsconfig.ts` add bolow into compile options
|
|
53
|
-
```typescript
|
|
54
|
-
"resolveJsonModule": true,
|
|
55
|
-
"esModuleInterop": true,
|
|
56
|
-
```
|
|
57
|
-
2.`./backend/.env` change mongodb setting as below example:
|
|
58
|
-
```bash
|
|
59
|
-
MONGODB_URL='mongodb://mongoadmin:secret@localhost:27017/admin?authMechanism=DEFAULT'
|
|
60
|
-
```
|
|
61
|
-
3. download http://localhost:8080/api into `./openapi.yaml`
|
|
62
|
-
4. regenerate code (for frontend can function completely)
|
|
63
|
-
5.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
1. install openapi-generator, pnpm, nest, rename openapi for new setup
|
|
67
|
-
2. load backend tsconfig and add more property: **
|
|
68
|
-
3. add prettier formating option for frontend
|
|
69
|
-
4. error messages
|
|
70
|
-
5. fix single and multi select bugs
|
|
71
|
-
6. function of remain menulist
|
|
72
|
-
7. security of string input, block xss
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
errors formating
|
|
76
|
-
18.keep audit trail into db
|
|
77
|
-
10.add backend find options
|
|
78
|
-
10.add frontend find options
|
|
79
|
-
11.retain modifications of controller, service, apiclients
|
|
80
|
-
14.add permission control
|
|
81
|
-
16.access right
|
|
82
|
-
17.setting of tenants
|
|
83
|
-
|
|
84
|
-
authentication in nuxt
|
|
85
|
-
jwt in backend
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
9. beautify default tailwind ui
|
|
89
|
-
1. front page
|
|
90
|
-
2. top bar
|
|
91
|
-
3. menu bars
|
|
92
|
-
4. default with of each component is it nicely fit
|
|
93
|
-
5. table layout
|
|
94
|
-
7. error formating
|
|
95
|
-
9. write proper user guide
|
|
96
|
-
13.add workflow functions
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
hold
|
|
101
|
-
|
|
102
|
-
10.plugin for ajv
|
|
103
|
-
long string format for description
|
|
104
|
-
|
|
105
|
-
# Todo
|
|
106
|
-
x21.control csrf
|
|
107
|
-
x8. simpleapp generate currentfolder error **
|
|
108
|
-
x1. override app.vue *
|
|
109
|
-
x2. create layout
|
|
110
|
-
simpleapp (first time only)
|
|
111
|
-
/default *
|
|
112
|
-
x3. components/ (first time only)
|
|
113
|
-
x /MonitorEvent.vue *
|
|
114
|
-
x /CrudBasic.vue **
|
|
115
|
-
x /Menubar *
|
|
116
|
-
4. create page/docs (everytime)
|
|
117
|
-
/index.ts
|
|
118
|
-
//create page if docs/documentname not exists ***
|
|
119
|
-
//override if docs/documentname/delete-me-for-avoid-override exists *
|
|
120
|
-
5. login/logout sessions
|
|
121
|
-
x6. auto create *
|
|
122
|
-
x server/api to backend *
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
1. define foreign key relationship in json schema2
|
|
129
|
-
2. auto index and block deletion
|
|
130
|
-
3. when delete identify foreign connected documents
|
|
131
|
-
4. how to unique key
|
|
132
|
-
5. how to multi-tenancy
|
|
133
|
-
6. login/logout in nuxt
|
|
134
|
-
7. jwt in nestjs
|
|
135
|
-
8. format errors at server side link back client side
|
|
136
|
-
9. how to auto toast
|
|
137
|
-
10.server side custom validation link back client side
|
|
138
|
-
11.permission controls
|
|
139
|
-
12.find records
|
|
140
|
-
13.audit trail
|
|
141
|
-
14.data isolation by org, branch and tenant
|
|
142
|
-
15.statistics, aggregations
|
|
143
|
-
16.auto generate frontend page
|
|
144
|
-
17.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
# simpleapp-generator
|
|
151
|
-
## this project still in alpha stage!
|
|
152
|
-
|
|
153
|
-
SimpleApp is an frontend and backend code generator, the ideal of this project is to allow developer build reliable and scalable application with low code methods.
|
|
154
|
-
|
|
155
|
-
It suitable for complex schema +complex calculation such as:
|
|
156
|
-
1. sales invoice: having parent and childs as 1 document, it need to calculate tax, discount, exchange rate
|
|
157
|
-
2. delivery order: need to calculate total quantity, unit of measurement conversion
|
|
158
|
-
|
|
159
|
-
Key Ideal:
|
|
160
|
-
1. Every data store as json format, name as `document`
|
|
161
|
-
2. Every document defined by jsonschema, and store in folder `definations`
|
|
162
|
-
3. We store jsonschema as `<uniquedocumentname>.<uniquedocumentshortname>.jsonschema.json`. Example: `purchaseorder.po.jsonschema.json`, `student.std.jsonschema.json`
|
|
163
|
-
4. `JsonSchema` used to generate:
|
|
164
|
-
- multiple pattern of data types for database, dto, frontend, backend. The data type match to `jsonschema`
|
|
165
|
-
- api controller (openapi)
|
|
166
|
-
- simpleapp frontend and backend objects
|
|
167
|
-
5. Generated code will control data validation in both frontend and backend using `ajv`
|
|
168
|
-
6. There is few important keyword need to know:
|
|
169
|
-
- `jsondata`: actual data like `{"document_no":"PO001",amount:300}`
|
|
170
|
-
- `jsonschema`: it is schema of `jsondata`, we use it to generate CRUD codes
|
|
171
|
-
- `frontend`: user interface framework using nuxt (vue+typescript), it doesn't store any data
|
|
172
|
-
- `backend`: api server using nest(typescript), it provide openapi, and store data into mongodb
|
|
173
|
-
- `doc service`: a typescript class use for process specific document in server. example" `po.service.ts`
|
|
174
|
-
- `doc controller`: it is api router for route http traffic to document service. example: `po.controller.ts`
|
|
175
|
-
- `doc client`: frontend client, it provide reactive data and data processing mechanism for frontend
|
|
176
|
-
|
|
177
|
-
6. To make our app useful, we perform development at
|
|
178
|
-
- backend: modify `api controller` and `backend document service`
|
|
179
|
-
- frontend: layout user interface, bind input fields to `doc client` , and modify `doc client` required
|
|
180
|
-
7. We may frequently change `jsonschema`, `doc service`, `doc controller`, `doc client`:
|
|
181
|
-
- the previous modified code remain when you regenerate code (with specific rules)
|
|
182
|
-
8. After regenerate codes, some data processing codes in `doc service` will sync into `doc client`, to reduce repeat coding at both end
|
|
183
|
-
|
|
184
|
-
## Benefit
|
|
185
|
-
- Use `jsonschema` generate most of the frontend and backend code
|
|
186
|
-
- Generated frontend and backend code in typescript+OOP.
|
|
187
|
-
- it control as tight as possible the frontend and backend data consistency
|
|
188
|
-
- support complex data schema, included parent and childs, nested objects
|
|
189
|
-
- enforce frontend and backend use same data type
|
|
190
|
-
- data store in mongodb, exactly same with schema, no join no headache
|
|
191
|
-
- flexible frontend, you can code react or vue, no problem. `simpleapp generator` only focus data, not ui
|
|
192
|
-
- allow developer enforce specific data processing in frontend and backend
|
|
193
|
-
- you can regenerate source code multiple time without worry your customization gone (there is a way!)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
Init Nuxt script
|
|
197
|
-
1. npm i -D @sidebase/nuxt-auth
|
|
198
|
-
2. pnpm i --save next-auth@4.21.1
|
|
199
|
-
npm i -D @sidebase/nuxt-session
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
## You shall know
|
|
204
|
-
This project assume you familiar with below:
|
|
205
|
-
1. typescript (no typescript, not reliable frontend)
|
|
206
|
-
2. mongodb
|
|
207
|
-
3. vue/react kind of ecosystem
|
|
208
|
-
|
|
209
|
-
# Special Format:
|
|
210
|
-
There is special format value:
|
|
211
|
-
1. `field-autcomplete-code`:field for document code, like `student_code,document_no`
|
|
212
|
-
2. `field-autocomplete-label`: field for document name, like `student_name, product_name`
|
|
213
|
-
|
|
214
|
-
# Special properties:
|
|
215
|
-
## object:
|
|
216
|
-
* autocomplete-src=category => autocomplete list from server-url/category/autocomplete
|
|
217
|
-
|
|
218
|
-
You need to install mongodb and openapi generator:
|
|
219
|
-
1. https://www.mongodb.com/docs/manual/installation/
|
|
220
|
-
2. https://openapi-generator.tech/docs/installation/
|
|
221
|
-
|
|
222
|
-
# Quick Start
|
|
223
|
-
This quick start create a example project developed by simpleapp-generator
|
|
224
|
-
1. Install `simpleapp-generator`
|
|
225
|
-
```sh
|
|
226
|
-
npm install -g simpleapp-generator
|
|
227
|
-
```
|
|
228
|
-
2. mkdir project folder for store frontend and backend codes
|
|
229
|
-
```sh
|
|
230
|
-
mkdir ~/myapp
|
|
231
|
-
cd myapp
|
|
232
|
-
```
|
|
233
|
-
3. generate sample project
|
|
234
|
-
```sh
|
|
235
|
-
simpleapp-generator -e person # -e mean use example schema "person". Currently only 1 example
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
4. run backend apiserver
|
|
239
|
-
```sh
|
|
240
|
-
cd backend
|
|
241
|
-
pnpm start:dev
|
|
242
|
-
```
|
|
243
|
-
5. browse to `http://localhost:8000/api` for swagger ui, `http://localhost:8000/api-yaml` for openapi documents
|
|
244
|
-
6. You may use vscode to see the example code in `backend/src/docs/pes`:
|
|
245
|
-
- pes.controller.ts //document api controller
|
|
246
|
-
- pes.service.ts //document service controller
|
|
247
|
-
- pes.type.ts, pes.apischema.ts, pes.model.ts //multiple datatype or schema
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
```
|
|
257
|
-
mkdir definations #we put json schema here
|
|
258
|
-
|
|
259
|
-
```
|
|
260
|
-
3. create configuration file `config.json`
|
|
261
|
-
```sh
|
|
262
|
-
echo '{"definationsFolder":"./definations","backendFolder":"./backend", "frontendFolder":"./frontend","openapi3Yaml":""}' > config.json
|
|
263
|
-
```
|
|
264
|
-
4. create below content and save as `~/myapp/definations/person.pes.jsonschema.json`
|
|
265
|
-
```json
|
|
266
|
-
{
|
|
267
|
-
"type": "object",
|
|
268
|
-
"properties": {
|
|
269
|
-
"name": {
|
|
270
|
-
"type": "object",
|
|
271
|
-
"properties": {
|
|
272
|
-
"firstName": {
|
|
273
|
-
"type": "string",
|
|
274
|
-
"example": [
|
|
275
|
-
"John"
|
|
276
|
-
]
|
|
277
|
-
},
|
|
278
|
-
"lastName": {
|
|
279
|
-
"type": "string",
|
|
280
|
-
"example": [
|
|
281
|
-
"Fox"
|
|
282
|
-
]
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
"age": {
|
|
287
|
-
"type": "integer",
|
|
288
|
-
"example": [
|
|
289
|
-
20
|
|
290
|
-
]
|
|
291
|
-
},
|
|
292
|
-
"email": {
|
|
293
|
-
"type": "string",
|
|
294
|
-
"example": [
|
|
295
|
-
"john@example.com"
|
|
296
|
-
],
|
|
297
|
-
"format": "email"
|
|
298
|
-
},
|
|
299
|
-
"dob": {
|
|
300
|
-
"type": "string",
|
|
301
|
-
"example": [
|
|
302
|
-
"2000-01-01"
|
|
303
|
-
],
|
|
304
|
-
"format": "date"
|
|
305
|
-
},
|
|
306
|
-
"hobbies": {
|
|
307
|
-
"type": "array",
|
|
308
|
-
"items": {
|
|
309
|
-
"type": "string",
|
|
310
|
-
"example": [
|
|
311
|
-
"badminton",
|
|
312
|
-
"dota",
|
|
313
|
-
"reading"
|
|
314
|
-
]
|
|
315
|
-
}
|
|
316
|
-
},
|
|
317
|
-
"addresses": {
|
|
318
|
-
"type": "array",
|
|
319
|
-
"items": {
|
|
320
|
-
"type": "object",
|
|
321
|
-
"required": [
|
|
322
|
-
"street1",
|
|
323
|
-
"street2",
|
|
324
|
-
"postcode"
|
|
325
|
-
],
|
|
326
|
-
"properties": {
|
|
327
|
-
"street1": {
|
|
328
|
-
"type": "string",
|
|
329
|
-
"example": [
|
|
330
|
-
"11, Fox Road"
|
|
331
|
-
]
|
|
332
|
-
},
|
|
333
|
-
"street2": {
|
|
334
|
-
"type": "string",
|
|
335
|
-
"example": [
|
|
336
|
-
"My Home Town"
|
|
337
|
-
]
|
|
338
|
-
},
|
|
339
|
-
"postcode": {
|
|
340
|
-
"type": "integer",
|
|
341
|
-
"example": [
|
|
342
|
-
12345
|
|
343
|
-
]
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
```
|
|
351
|
-
5. generate backend and frontend codes, and define backend/.env `mongodb connection` string:
|
|
352
|
-
```sh
|
|
353
|
-
simpleapp-generator -c ./config.json
|
|
354
|
-
code backend # use vscode open backend project, edit .env
|
|
355
|
-
```
|
|
356
|
-
6. You can start backend server and try the generated api at `http://localhost:8000/api`
|
|
357
|
-
```sh
|
|
358
|
-
cd ~/myapp/backend
|
|
359
|
-
pnpm start:dev
|
|
360
|
-
```
|
|
361
|
-
7. Next we need more frontend work, put content of `http://localhost:8000/api-yaml` into `~/myapp/openapi.yaml`, and edit config.json as:
|
|
362
|
-
```json
|
|
363
|
-
{
|
|
364
|
-
"definationsFolder":"./definations",
|
|
365
|
-
"backendFolder":"./backend",
|
|
366
|
-
"frontendFolder":"./frontend",
|
|
367
|
-
"openapi3Yaml":"./openapi.yaml"
|
|
368
|
-
}
|
|
369
|
-
```
|
|
370
|
-
8. regenerate source code, and use vscode open both backend and frontend project:
|
|
371
|
-
```sh
|
|
372
|
-
simpleapp-generator -c ./config.json
|
|
373
|
-
code ./frontend ;
|
|
374
|
-
code ./backend ;
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
# The complete development process:
|
|
379
|
-
1. Prepare documents
|
|
380
|
-
a. Prepare sample json data
|
|
381
|
-
b. Convert `json` data to `jsonschema`
|
|
382
|
-
c. touch up jsonschema, like define require fields, format, minLength and etc
|
|
383
|
-
d. place json schema into `definations` folder
|
|
384
|
-
2. Generate source codes
|
|
385
|
-
a. generate source code into backend project
|
|
386
|
-
b. start backend service, obtain yaml content and save into project folder
|
|
387
|
-
c. re-generate source code, it create required codes for frontend
|
|
388
|
-
3. Begin Frontend development:
|
|
389
|
-
a. use vscode open frontend project
|
|
390
|
-
b. create user interface with several input fields, bind to generated simpleapp object
|
|
391
|
-
|
|
392
|
-
## 1. Prepare documents
|
|
393
|
-
1. [click here](https://www.convertsimple.com/convert-javascript-to-json/) allow you create json data with lesser effort. Lets use this example:
|
|
394
|
-
```json
|
|
395
|
-
{
|
|
396
|
-
"docNo": "SI001",
|
|
397
|
-
"customer": "My Customer Pte Ltd",
|
|
398
|
-
"amount": 200,
|
|
399
|
-
"products": [
|
|
400
|
-
"apple",
|
|
401
|
-
"orange"
|
|
402
|
-
],
|
|
403
|
-
"details": [
|
|
404
|
-
{
|
|
405
|
-
"item": "apple",
|
|
406
|
-
"qty": 100,
|
|
407
|
-
"unitprice": 1,
|
|
408
|
-
"subtotal": 100
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
"item": "orange",
|
|
412
|
-
"qty": 100,
|
|
413
|
-
"unitprice": 1,
|
|
414
|
-
"subtotal": 100
|
|
415
|
-
}
|
|
416
|
-
],
|
|
417
|
-
"remarks": "need fast delivery"
|
|
418
|
-
}
|
|
419
|
-
```
|
|
420
|
-
b. Copy generated json data to [here](https://redocly.com/tools/json-to-json-schema) using below setting, you may define data type/format/required parameters according [jsonschema standard](https://json-schema.org/understanding-json-schema/reference/index.html)
|
|
421
|
-
```
|
|
422
|
-
output format: json
|
|
423
|
-
add example to schema: true
|
|
424
|
-
infer require property for array items: true
|
|
425
|
-
disable additionalProperty: true
|
|
426
|
-
```
|
|
427
|
-
Here is the result:
|
|
428
|
-
```json
|
|
429
|
-
{
|
|
430
|
-
"type": "object",
|
|
431
|
-
"properties": {
|
|
432
|
-
"docNo": {
|
|
433
|
-
"type": "string",
|
|
434
|
-
"example": [
|
|
435
|
-
"SI001"
|
|
436
|
-
]
|
|
437
|
-
},
|
|
438
|
-
"customer": {
|
|
439
|
-
"type": "string",
|
|
440
|
-
"example": [
|
|
441
|
-
"My Customer Pte Ltd"
|
|
442
|
-
]
|
|
443
|
-
},
|
|
444
|
-
"amount": {
|
|
445
|
-
"type": "integer",
|
|
446
|
-
"example": [
|
|
447
|
-
200
|
|
448
|
-
]
|
|
449
|
-
},
|
|
450
|
-
"products": {
|
|
451
|
-
"type": "array",
|
|
452
|
-
"items": {
|
|
453
|
-
"type": "string",
|
|
454
|
-
"example": [
|
|
455
|
-
"apple",
|
|
456
|
-
"orange"
|
|
457
|
-
]
|
|
458
|
-
}
|
|
459
|
-
},
|
|
460
|
-
"details": {
|
|
461
|
-
"type": "array",
|
|
462
|
-
"items": {
|
|
463
|
-
"type": "object",
|
|
464
|
-
"required": [
|
|
465
|
-
"item",
|
|
466
|
-
"qty",
|
|
467
|
-
"unitprice",
|
|
468
|
-
"subtotal"
|
|
469
|
-
],
|
|
470
|
-
"properties": {
|
|
471
|
-
"item": {
|
|
472
|
-
"type": "string",
|
|
473
|
-
"example": [
|
|
474
|
-
"apple",
|
|
475
|
-
"orange"
|
|
476
|
-
]
|
|
477
|
-
},
|
|
478
|
-
"qty": {
|
|
479
|
-
"type": "integer",
|
|
480
|
-
"example": [
|
|
481
|
-
100,
|
|
482
|
-
100
|
|
483
|
-
]
|
|
484
|
-
},
|
|
485
|
-
"unitprice": {
|
|
486
|
-
"type": "integer",
|
|
487
|
-
"example": [
|
|
488
|
-
1,
|
|
489
|
-
1
|
|
490
|
-
]
|
|
491
|
-
},
|
|
492
|
-
"subtotal": {
|
|
493
|
-
"type": "integer",
|
|
494
|
-
"example": [
|
|
495
|
-
100,
|
|
496
|
-
100
|
|
497
|
-
]
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
},
|
|
502
|
-
"remarks": {
|
|
503
|
-
"type": "string",
|
|
504
|
-
"example": [
|
|
505
|
-
"need fast delivery"
|
|
506
|
-
]
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
```
|
|
511
|
-
c. save the json data into `definations` folder
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
## Backend NestJS project preparation
|
|
518
|
-
1. install backend nest application: `npm i -g pnpm @nestjs/cli` (cli tools for pnpm and nestjs)
|
|
519
|
-
2. create a folder `~/myapp`
|
|
520
|
-
3. cd `~/myapp`
|
|
521
|
-
4. create blank nest project `nest new backend`, pick `pnpm`
|
|
522
|
-
5. enter backend folder: `cd backend`
|
|
523
|
-
6. install dependency: `pnpm install --save @nestjs/swagger @nestjs/mongoose mongoose ajv ajv-formats @nestjs/config` (ignore ✕ missing peer webpack)
|
|
524
|
-
7. create .env file with following settings:
|
|
525
|
-
```sh
|
|
526
|
-
MONGODB_URL='mongodb://<user>:<pass>@<host>:<port>/<db>?authMechanism=DEFAULT'
|
|
527
|
-
HTTP_PORT=8000
|
|
528
|
-
PROJECT_NAME='SimpleApp Demo1'
|
|
529
|
-
PROJECT_DESCRIPTION='Try CRUD'
|
|
530
|
-
PROJECT_VERSION='1.0.0'
|
|
531
|
-
```
|
|
532
|
-
7. change `src/main.ts`, allow openapi document:
|
|
533
|
-
```ts
|
|
534
|
-
import { NestFactory } from '@nestjs/core';
|
|
535
|
-
import { AppModule } from './app.module';
|
|
536
|
-
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
537
|
-
|
|
538
|
-
async function bootstrap() {
|
|
539
|
-
const app = await NestFactory.create(AppModule);
|
|
540
|
-
app.enableCors();
|
|
541
|
-
const config = new DocumentBuilder()
|
|
542
|
-
.setTitle(process.env.PROJECT_NAME)
|
|
543
|
-
.setDescription(process.env.PROJECT_DESCRIPTION)
|
|
544
|
-
.setVersion(process.env.PROJECT_VERSION)
|
|
545
|
-
.build();
|
|
546
|
-
const document = SwaggerModule.createDocument(app, config);
|
|
547
|
-
SwaggerModule.setup('api', app, document, {
|
|
548
|
-
swaggerOptions: { showExtensions: true },
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
await app.listen(process.env.HTTP_PORT); //listen which port
|
|
552
|
-
}
|
|
553
|
-
bootstrap();
|
|
554
|
-
```
|
|
555
|
-
9. start backend server `pnpm start:dev`, monitor [http://localhost:3000/api](http://localhost:3000/api)
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
## Frontend NuxtJS project preparation (or, any others framework if you have know how)
|
|
559
|
-
1. `cd ~/myapp`
|
|
560
|
-
2. create new frontend nuxt project `npx nuxi@latest init frontend`
|
|
561
|
-
3. `cd frontend`
|
|
562
|
-
4. install required package: `pnpm install ajv ajv-formats axios json-schema`
|
|
563
|
-
5. create .env file with below content
|
|
564
|
-
```sh
|
|
565
|
-
SIMPLEAPP_BACKEND_URL=http://localhost:8000
|
|
566
|
-
PORT=8800
|
|
567
|
-
```
|
|
568
|
-
6. run frontend: `pnpm dev -o`
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
## setup Mongodb
|
|
572
|
-
1. you can use mongodb, either docker or install binary
|
|
573
|
-
https://www.mongodb.com/docs/manual/installation/
|
|
574
|
-
** remember create database, and define suitable credentials (user/password)
|
|
575
|
-
|
|
576
|
-
## Setup openapi-generator
|
|
577
|
-
Refer below:
|
|
578
|
-
https://openapi-generator.tech/docs/installation/
|
|
579
|
-
|
|
580
|
-
I'm using mac, so i use `brew install openapi-generator`
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
# Job Begin!
|
|
584
|
-
3 steps:
|
|
585
|
-
1. Prepare json schema
|
|
586
|
-
2. use json schema generate frontend and backend codes
|
|
587
|
-
3. persom simple development
|
|
588
|
-
|
|
589
|
-
## 1. Prepare sample data schema
|
|
590
|
-
1. lets assume we have a sample data:
|
|
591
|
-
```json
|
|
592
|
-
{
|
|
593
|
-
"name":{"firstName":"John","lastName":"Fox"},
|
|
594
|
-
"age":20,
|
|
595
|
-
"email":"john@example.com",
|
|
596
|
-
"dob":"2000-01-01",
|
|
597
|
-
"hobbies":["badminton","dota","reading"],
|
|
598
|
-
"addresses": [{"street1":"11, Fox Road","street2":"My Home Town","postcode":12345}]
|
|
599
|
-
}
|
|
600
|
-
```
|
|
601
|
-
2. Generate it become `jsonschema` [here](https://redocly.com/tools/json-to-json-schema), format as json. Follow below settings:
|
|
602
|
-
```
|
|
603
|
-
add example to schema: true
|
|
604
|
-
infer require property for array items: true
|
|
605
|
-
disable additionalProperty: true
|
|
606
|
-
```
|
|
607
|
-
|
|
608
|
-
Below is the sample of jsonschema:
|
|
609
|
-
```json
|
|
610
|
-
{
|
|
611
|
-
"type": "object",
|
|
612
|
-
"properties": {
|
|
613
|
-
"name": {
|
|
614
|
-
"type": "object",
|
|
615
|
-
"properties": {
|
|
616
|
-
"firstName": {
|
|
617
|
-
"type": "string",
|
|
618
|
-
"example": [
|
|
619
|
-
"John"
|
|
620
|
-
]
|
|
621
|
-
},
|
|
622
|
-
"lastName": {
|
|
623
|
-
"type": "string",
|
|
624
|
-
"example": [
|
|
625
|
-
"Fox"
|
|
626
|
-
]
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
},
|
|
630
|
-
"age": {
|
|
631
|
-
"type": "integer",
|
|
632
|
-
"example": [
|
|
633
|
-
20
|
|
634
|
-
]
|
|
635
|
-
},
|
|
636
|
-
"email": {
|
|
637
|
-
"type": "string",
|
|
638
|
-
"example": [
|
|
639
|
-
"john@example.com"
|
|
640
|
-
],
|
|
641
|
-
"format": "email"
|
|
642
|
-
},
|
|
643
|
-
"dob": {
|
|
644
|
-
"type": "string",
|
|
645
|
-
"example": [
|
|
646
|
-
"2000-01-01"
|
|
647
|
-
],
|
|
648
|
-
"format": "date"
|
|
649
|
-
},
|
|
650
|
-
"hobbies": {
|
|
651
|
-
"type": "array",
|
|
652
|
-
"items": {
|
|
653
|
-
"type": "string",
|
|
654
|
-
"example": [
|
|
655
|
-
"badminton",
|
|
656
|
-
"dota",
|
|
657
|
-
"reading"
|
|
658
|
-
]
|
|
659
|
-
}
|
|
660
|
-
},
|
|
661
|
-
"addresses": {
|
|
662
|
-
"type": "array",
|
|
663
|
-
"items": {
|
|
664
|
-
"type": "object",
|
|
665
|
-
"required": [
|
|
666
|
-
"street1",
|
|
667
|
-
"street2",
|
|
668
|
-
"postcode"
|
|
669
|
-
],
|
|
670
|
-
"properties": {
|
|
671
|
-
"street1": {
|
|
672
|
-
"type": "string",
|
|
673
|
-
"example": [
|
|
674
|
-
"11, Fox Road"
|
|
675
|
-
]
|
|
676
|
-
},
|
|
677
|
-
"street2": {
|
|
678
|
-
"type": "string",
|
|
679
|
-
"example": [
|
|
680
|
-
"My Home Town"
|
|
681
|
-
]
|
|
682
|
-
},
|
|
683
|
-
"postcode": {
|
|
684
|
-
"type": "integer",
|
|
685
|
-
"example": [
|
|
686
|
-
12345
|
|
687
|
-
]
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
## Generate Code
|
|
697
|
-
1. install simpleapp-generetor `npm install -g simpleapp-generator`
|
|
698
|
-
2. create a folder `~/myapp/definations`
|
|
699
|
-
3. copy above jsonschema example as `~/myapp/definations/person.ps.jsonschema.json`.
|
|
700
|
-
* `person`: unique document name (small letter alphabet `[a-z]`)
|
|
701
|
-
* `ps`: unique document type (small letter `[a-z]`)
|
|
702
|
-
* `jsonschema.json`: all files ending with this extension will process
|
|
703
|
-
4. create `~/myapp/config.json` with below content
|
|
704
|
-
```json
|
|
705
|
-
{
|
|
706
|
-
"definationsFolder":"./definations",
|
|
707
|
-
"backendFolder":"./mybackend",
|
|
708
|
-
"backendPort":"8000",
|
|
709
|
-
"mongoConnectStr":"mongodb://<user>:<pass>@<host>:<port>/<db>?authMechanism=DEFAULT",
|
|
710
|
-
"frontendFolder":"./myfrontend",
|
|
711
|
-
"frontendPort":"8080",
|
|
712
|
-
"openapi3Yaml":"./openapi.yaml",
|
|
713
|
-
}
|
|
714
|
-
```
|
|
715
|
-
5. run `simpleapp-generator -c ./config.json`
|
|
716
|
-
6. restart nestjs, the microservice is ready and you can test at `http://localhost:8000/api`. All generated api accessible via swagger-ui.
|
|
717
|
-
7. Frontend need further work. Browse `http://localhost:8000/api-yaml`, save content as `openapi.yaml`
|
|
718
|
-
8. Rerun `simpleapp-generator -c ./config.json`, it will help us to generate axios executable using openapi.yaml
|
|
719
|
-
9. use vscode open both `~/myapp/frontend` and `~/myapp/backend`
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
## perform simple development
|
|
724
|
-
1. in `frontend` project, edit `app.vue`, put in below code:
|
|
725
|
-
```vue
|
|
726
|
-
<template>
|
|
727
|
-
<div>
|
|
728
|
-
<div>
|
|
729
|
-
<label>Firstname</label>
|
|
730
|
-
<input v-model="reactivedata.name.firstName">
|
|
731
|
-
</div>
|
|
732
|
-
{{ reactivedata }}
|
|
733
|
-
<button @click="person.create().then((res)=>console.log(res.data))">try</button>
|
|
734
|
-
</div>
|
|
735
|
-
</template>
|
|
736
|
-
<script setup lang="ts">
|
|
737
|
-
import {PersonDoc} from './server/docs/PersonDoc'
|
|
738
|
-
const person = new PersonDoc()
|
|
739
|
-
|
|
740
|
-
// person.update().then((res)=>console.log("dosomething"))
|
|
741
|
-
// person.delete('record-id').then((res)=>console.log("dosomething"))
|
|
742
|
-
// person.getById('record-id').then((res)=>console.log("dosomething"))
|
|
743
|
-
// person.list().then((res)=>console.log(res))
|
|
744
|
-
const noreactivedata = person.getData() //give not reactive data, it cant apply 2 way data binding
|
|
745
|
-
const reactivedata = person.getReactiveData() //give vue reactive data, it can apply 2 way data binding using v-model
|
|
746
|
-
</script>
|
|
747
|
-
```
|
|
748
|
-
|
|
749
|
-
We notice:
|
|
750
|
-
1. `PersonDoc` auto generated, it come with plenty of build in crud features which you can use without knowing API:
|
|
751
|
-
```typescript
|
|
752
|
-
person.create().then((res)=>console.log("dosomething"))
|
|
753
|
-
person.update().then((res)=>console.log("dosomething"))
|
|
754
|
-
person.delete('record-id').then((res)=>console.log("dosomething"))
|
|
755
|
-
person.getById('record-id').then((res)=>console.log("dosomething"))
|
|
756
|
-
person.list().then((res)=>console.log(res))
|
|
757
|
-
```
|
|
758
|
-
2. `person.getData()` gave reactive object, we can bind all properties directly to `vue` component using `v-model`
|
|
759
|
-
3. you may try add more input bind to `reactivedata.name.lastName`,`reactivedata.email`, `reactivedata.age` and monitor result
|
|
760
|
-
4. `button` can directly trigger `save` method from person.getData()
|
|
761
|
-
5. You wont able to save the record because it not pass validation rules, check browser console it tell you what is happening
|
|
762
|
-
6. There is UI component `simpleapp-uicomponent` which can integrate nicely with with `PersonDoc`. Refer the link [here](...)
|
|
763
|
-
|
|
764
|
-
# We can do more With SimpleApp
|
|
765
|
-
## no time for full documentation yet
|
|
766
|
-
1. Monitor variable change at frontend
|
|
767
|
-
step 1: add new methods for frontend's class `PesonDoc.ts`
|
|
768
|
-
```
|
|
769
|
-
watchChanges = ()=>{
|
|
770
|
-
watch(this.getReactiveData(),(newdata)=>{
|
|
771
|
-
this.getReactiveData().age=calculateAge(newdata.dob)
|
|
772
|
-
//apply others changes here
|
|
773
|
-
})
|
|
774
|
-
}
|
|
775
|
-
```
|
|
776
|
-
step 2: edit `app.vue` to on the watcher
|
|
777
|
-
```typescript
|
|
778
|
-
//others codes
|
|
779
|
-
const person = new PersonDoc()
|
|
780
|
-
person.watchChanges() //<-- add this line to on watcher at frontend
|
|
781
|
-
//others codes
|
|
782
|
-
```
|
|
783
|
-
|
|
784
|
-
2. create more api to `person`, such as `post /person/:id/sendEmail {title:"title",body:"body"}`
|
|
785
|
-
step 1: edit backend `<backend>/src/docs/pes/pes.controller.ts`, add new source code between `<begin-controller-code>` and `<end-controller-code>`:
|
|
786
|
-
```typescript
|
|
787
|
-
//<begin-controller-code>
|
|
788
|
-
//new api, wont override when regenerate code
|
|
789
|
-
@Get('/try/:id')
|
|
790
|
-
@ApiResponse({
|
|
791
|
-
status: 200,
|
|
792
|
-
description: 'success',
|
|
793
|
-
type: pesapischema.Person,
|
|
794
|
-
})
|
|
795
|
-
@ApiResponse({ status: 404, description: 'Document not found' })
|
|
796
|
-
@ApiResponse({ status: 500, description: 'Internal error' })
|
|
797
|
-
@ApiOperation({ operationId: 'newFindOne' }) //important, frontend access it via person.newFindOne()
|
|
798
|
-
async newFindOne(@Param('id') id: string) {
|
|
799
|
-
return this._findOne(id);
|
|
800
|
-
}
|
|
801
|
-
//<end-controller-code>
|
|
802
|
-
```
|
|
803
|
-
step 2: try browse to `http://localhost:8000/api` to check new api appear or not.
|
|
804
|
-
step 3: You shall regenerate the code
|
|
805
|
-
```bash
|
|
806
|
-
simpleapp-generator -c ./config.json
|
|
807
|
-
```
|
|
808
|
-
step 4: go frontend project, edit `app.vue` you may try type `person.newFindOne()` see new method exists?
|
|
809
|
-
|
|
810
|
-
step 3: Regenerate code for frontend
|
|
811
|
-
|
|
812
|
-
4. create backend only execution for `person`. It is useful cause some work only
|
|
813
|
-
step 1: Edit backend `backend/src/docs/pes/pes.service.ts`, add new source code between `<begin-backend-code>` and `<end-backend-code>`:
|
|
814
|
-
```typescript
|
|
815
|
-
//<begin-backend-code>
|
|
816
|
-
//new method, wont override when regenerate code
|
|
817
|
-
logSomething = () => {
|
|
818
|
-
console.log('Access try api');
|
|
819
|
-
};
|
|
820
|
-
//<end-backend-code>
|
|
821
|
-
```
|
|
822
|
-
step 2: modify `<backend>/src/docs/pes/pes.controller.ts`, call the new method
|
|
823
|
-
```typescript
|
|
824
|
-
async newFindOne(@Param('id') id: string) {
|
|
825
|
-
this.service.logSomething(); //this.service is our service class
|
|
826
|
-
return this._findOne(id);
|
|
827
|
-
}
|
|
828
|
-
```
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
5. create frontend only code for `person`, such as:
|
|
832
|
-
`person.addHobbies('hobby1')`,`person.addAddress({})`,`person.delAddress(index:number)` edit `newFindOne`:
|
|
833
|
-
```
|
|
834
|
-
```
|
|
835
|
-
6. create bothend code for `person`
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
foreign key
|
|
840
|
-
cat
|
|
841
|
-
category_id
|
|
842
|
-
category_code
|
|
843
|
-
category_name
|
|
844
|
-
|
|
845
|
-
product
|
|
846
|
-
product_id
|
|
847
|
-
product_code
|
|
848
|
-
product_name
|
|
849
|
-
category => category_id: category_code
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
invoice
|
|
854
|
-
invoice_id
|
|
855
|
-
invoice_no
|
|
856
|
-
invoice_date
|
|
857
|
-
total
|
|
858
|
-
details =>
|
|
859
|
-
product => product_id: product_code
|
|
860
|
-
qty
|
|
861
|
-
price
|
|
862
|
-
subtotal
|
|
863
|
-
|
|
864
|
-
order
|
|
865
|
-
order_id
|
|
866
|
-
order_no
|
|
867
|
-
order_date
|
|
868
|
-
total
|
|
869
|
-
details =>
|
|
870
|
-
product => product_id: product_code
|
|
871
|
-
qty
|
|
872
|
-
price
|
|
873
|
-
subtotal
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
cat => foreignkey: []
|
|
877
|
-
prd => foreignkey: category => category
|
|
878
|
-
invoice => foreignkey: detail.product=>product
|
|
879
|
-
order => foreignkey: detail.product=>product
|
|
880
|
-
|
|
881
|
-
cat =[product.category]
|
|
882
|
-
product=[invoice.detail.product, order.detail.product]
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
todo:
|
|
888
|
-
## high priority Job
|
|
889
|
-
|
|
890
|
-
[ ] add special search like isolate by user for autocomplete (add property of)
|
|
891
|
-
choose org then branch
|
|
892
|
-
[ ] create invoice and receipt
|
|
893
|
-
[x] fix error reporting and success reporting at frontend
|
|
894
|
-
[x] define some allow override and some not
|
|
895
|
-
[ ] json schema can set generate what page type, no define = no generate page
|
|
896
|
-
[ ] create tenant/org/branch auto increament
|
|
897
|
-
[ ] focus on functions customer, product, invoice and receipt
|
|
898
|
-
[~] repeat same typscript formula at frontend and backend
|
|
899
|
-
[ ] frontend search
|
|
900
|
-
[ ] new transaction CRUD ui
|
|
901
|
-
[ ] student UI
|
|
902
|
-
[ ] structure of save into another document
|
|
903
|
-
|
|
904
|
-
Permission and Authorization
|
|
905
|
-
[x] hide no permission window
|
|
906
|
-
[ ] hide no permission buttons
|
|
907
|
-
[x] permission user/group (pick hard coded group from some place)
|
|
908
|
-
[ ] figure how to get enum list from permission list for user schema
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
1. copy group-to-role to both frontend and backend
|
|
913
|
-
2. loop backend role code, and define into user role
|
|
914
|
-
3. loop frontend role code, and
|
|
915
|
-
1 update to getMenus,
|
|
916
|
-
2. existing all menus store as permission list
|
|
917
|
-
3. crud and etc page need verify existing user can go in this menu or not. if can't will render no permission
|
|
918
|
-
4. use directive to control show or not show button (new, save, delete)
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
Custom Document Status and API
|
|
923
|
-
[ ] document status control
|
|
924
|
-
[ ] document api touch up
|
|
925
|
-
1. auto add document status column
|
|
926
|
-
2. change document status when change status
|
|
927
|
-
3. enum document status, but UI dont show the field
|
|
928
|
-
4. have document action, then show document button
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
# Quick start
|
|
932
|
-
** You need to have mongodb installed **
|
|
933
|
-
1. git clone from simpleapp-generator
|
|
934
|
-
```sh
|
|
935
|
-
npm -i @simitgroup/simpleapp-generator@latest
|
|
936
|
-
git clone https://github.com/SIMITGROUP/simpleapp-generator-template myapp
|
|
937
|
-
# edit myapp/config.json to match you mongodb connection string
|
|
938
|
-
cd ~/myapp
|
|
939
|
-
simpleapp-generator -c config.json
|
|
940
|
-
```
|
|
941
|
-
2. start backend
|
|
942
|
-
```sh
|
|
943
|
-
cd ~/myapp/backend
|
|
944
|
-
pnpm start:dev
|
|
945
|
-
```
|
|
946
|
-
3. start frontend
|
|
947
|
-
```sh
|
|
948
|
-
cd ~/myapp/frontend
|
|
949
|
-
pnpm dev
|
|
950
|
-
```
|
|
951
|
-
4. try ui:
|
|
952
|
-
* frontend: [http://localhost:8080](http://localhost:8080)
|
|
953
|
-
* backend: [http://localhost:8000/api](http://localhost:8000/api)
|
|
954
|
-
5. Open project with vscode, explore json schema and the generated forms
|
|
955
|
-
```sh
|
|
956
|
-
code ~/mydoc
|
|
957
|
-
```
|
|
958
|
-
you can change your project at:
|
|
959
|
-
* myapp/backend/.env
|
|
960
|
-
* myapp/backend/src/hooks/*
|
|
961
|
-
|
|
962
|
-
* myapp/frontend/.env
|
|
963
|
-
* myapp/frontend/pages/*
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
# Special Properties:
|
|
968
|
-
## Special root level property
|
|
969
|
-
_id:
|
|
970
|
-
tenantId:
|
|
971
|
-
orgId:
|
|
972
|
-
branchId:
|
|
973
|
-
created:
|
|
974
|
-
createdBy:
|
|
975
|
-
updated:
|
|
976
|
-
updatedBy:
|
|
977
|
-
documentStatus
|
|
978
|
-
_v:
|
|
979
|
-
x-document-status: [optional]array of document satus: such as:
|
|
980
|
-
{
|
|
981
|
-
"":{"readonly":false,"allowApi":["confirm","void"],"description":"new"},
|
|
982
|
-
"D":{"readonly":false,"allowApi":["confirm","void"],"description":"draft"},
|
|
983
|
-
"V":{"readonly":true,"allowApi":[],"description":"v"},
|
|
984
|
-
"CO":{"readonly":true,"allowApi":["void","revert"],"description":"confirmed"},
|
|
985
|
-
"CL":{"readonly":true,"allowApi":[],"description":"closed"}
|
|
986
|
-
}
|
|
987
|
-
x-document-api: [optional]array of custom api (beside default)
|
|
988
|
-
|
|
989
|
-
```typescript
|
|
990
|
-
[
|
|
991
|
-
{"action":"confirm","method":"put","setDocumentStatus":"CO", "bpmn":"generic-confirm",
|
|
992
|
-
"data":{"document":"document"}},
|
|
993
|
-
{"action":"void",,"method":"put", "setDocumentStatus":"V", "bpmn":"generic-void",
|
|
994
|
-
"data":{"document":"document"}},
|
|
995
|
-
{"action":"revert",,"method":"put", "setDocumentStatus":"D", "bpmn":"generic-revert",
|
|
996
|
-
"data":{"document":"document"}},
|
|
997
|
-
{"action":"duplicate", ,"method":"post","data":{"document":"document"}},
|
|
998
|
-
{"action":"switchStatus",,"method":"put","data":{"statusName":"string","document":"document"}}
|
|
999
|
-
]
|
|
1000
|
-
```
|
|
1001
|
-
## Custom Format
|
|
1002
|
-
|
|
1003
|
-
## Custom Property
|
|
1004
|
-
|
|
1005
|
-
# Concept of Development
|
|
1006
|
-
Development using simpleapp-generator involve below steps:
|
|
1007
|
-
## Simple
|
|
1008
|
-
1. create appropriate jsonschema
|
|
1009
|
-
2. generate frontend and backend architectures
|
|
1010
|
-
3. start backend service, obtain and save api definations into openapi.yaml
|
|
1011
|
-
4. regenerate codes so frontend can obtain openapi clients
|
|
1012
|
-
5. align frontend UI, add necessary component such as css and ui components
|
|
1013
|
-
|
|
1014
|
-
## Advance
|
|
1015
|
-
1. complete simple task
|
|
1016
|
-
2. add more api/process at backend `controller`,`service`,`schema`. Such as:
|
|
1017
|
-
a. customized search and filters
|
|
1018
|
-
b. customized workflows
|
|
1019
|
-
c. connect external api
|
|
1020
|
-
d. additional data processing and validation which is not supported by jsonschema (AJV)
|
|
1021
|
-
3. security like sso/jwt, plugins
|
|
1022
|
-
a. keycloak integration at frontends
|
|
1023
|
-
b. backend manage jwt
|
|
1024
|
-
4. allow additional field formats, validations by modifying ajv
|
|
1025
|
-
a. allow custom jsonschema field property, and do something at backend
|
|
1026
|
-
b. allow custom field format, and do something at backend
|
|
1027
|
-
5. repeat same typscript formula at frontend and backend
|
|
1028
|
-
|
|
1029
|
-
Special Root Level property
|
|
1030
|
-
[x] x-ignore-autocomplete: optional boolean, define it to allow undefine x-document-no & x-document-label
|
|
1031
|
-
[x] x-isolation-type: optional string, how data isolated, 'none,tenant,org,branch', default 'org'
|
|
1032
|
-
|
|
1033
|
-
Special Field Level property
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
# JSON Schema supported String Format
|
|
1038
|
-
all format recognize by ajv plus below:
|
|
1039
|
-
|
|
1040
|
-
1. tel: only digit, auto generate input tel
|
|
1041
|
-
2. documentno : will use documentno generator for auto generate document no
|
|
1042
|
-
3. text: do nothing, will auto generate textarea
|
|
1043
|
-
4. html editor: do nothing, will auto generate html editor
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
# Todo
|
|
1048
|
-
## Update documentation and reference
|
|
1049
|
-
1. create github simpleapp-generator-template and documentation
|
|
1050
|
-
2. update documentation for `simpleapp-generator` and `simpleapp-vue-component`
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
workflow ideal
|
|
1054
|
-
1. define apiserver at backend .env
|
|
1055
|
-
2. api-service class can have standardway for
|
|
1056
|
-
a. excute new workflow
|
|
1057
|
-
b. get tasklist belong to me or my group
|
|
1058
|
-
c. trigger task move
|
|
1059
|
-
d. cancel workflow
|
|
1060
|
-
e. can define workflow inputs
|
|
1061
|
-
3. bind hook to workflow?
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
1. try possibility of no backend modifications
|
|
1068
|
-
3. completely hide all generated codes of frontend and backend, except allow change items
|
|
1069
|
-
1. define hidden control infra of admin tenant, user api+ui (like need special role system-admin from keycloak)
|
|
1070
|
-
add lodash plugin at both side
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
autocomplete can have more dependency filter like setting in jsonschema
|
|
1074
|
-
2. way in jsonschema to use share source code for frontend/backend like
|
|
1075
|
-
calculate tax
|
|
1076
|
-
calculate subtotal
|
|
1077
|
-
|
|
1078
|
-
5. new transaction crud
|
|
1079
|
-
d. windows
|
|
1080
|
-
new user no tenant record how to do?
|
|
1081
|
-
8. way to handle :id/api
|
|
1082
|
-
9. service class which not using source code
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
1. create follow data
|
|
1087
|
-
a. users
|
|
1088
|
-
b. tenant / users
|
|
1089
|
-
c. org
|
|
1090
|
-
branch/user
|
|
1091
|
-
group
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
3. json schema setting can define isolation type
|
|
1095
|
-
2. page/index first login can pick tenant
|
|
1096
|
-
3. create all window as xorg/index
|
|
1097
|
-
4. transaction crud window
|
|
1098
|
-
with x-document-api can have button for api-buttons, control by document status
|
|
1099
|
-
support readonly status
|
|
1100
|
-
5. simple crud only support crud
|
|
1101
|
-
6. support document-no
|
|
1102
|
-
7. add special isolation method by user
|
|
1103
|
-
8. beautify nuxt page
|
|
1104
|
-
9. foreign key with different schema
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
2. tidy up error at frontend/backend messages
|
|
1108
|
-
fix success msg at frontend
|
|
1109
|
-
11.add simple and consistent external hook in service class.
|
|
1110
|
-
13.have way to create more api using different openapi schema but on same object
|
|
1111
|
-
1. support half schema setting in crud, the rest at background
|
|
1112
|
-
|
|
1113
|
-
no auto logout after session expired, or auto renew token
|
|
1114
|
-
- menulist ** less priority, can customize manually
|
|
1115
|
-
10.auto bind apiclient methods to compatible with openapi methods
|
|
1116
|
-
a. create backend service method
|
|
1117
|
-
b. create controller handle
|
|
1118
|
-
|
|
1119
|
-
b. add popup dialog for edit table
|
|
1120
|
-
c. separate list table and form table
|
|
1121
|
-
d.
|
|
1122
|
-
5. tenant setting
|
|
1123
|
-
6. user management
|
|
1124
|
-
5. security of string input, block xss
|
|
1125
|
-
12.add pusher listener in apiclient also
|
|
1126
|
-
|
|
1127
|
-
18. add transaction screen templates
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
## Lower Priority
|
|
1131
|
-
3. multi-lingual
|
|
1132
|
-
6. audit trails
|
|
1133
|
-
7. permissions
|
|
1134
|
-
7. update record need replace updated,updatedBy, line item also need headache
|
|
1135
|
-
|
|
1136
|
-
11.frontend add parent/child ui for invoices
|
|
1137
|
-
|
|
1138
|
-
[done]
|
|
1139
|
-
x16. support table details in generator
|
|
1140
|
-
x3. settle instancePath in form
|
|
1141
|
-
x17. auto add source code for addarray item
|
|
1142
|
-
a. render autocomplete readonly field
|
|
1143
|
-
xauto index x-document-name
|
|
1144
|
-
x8. jwt
|
|
1145
|
-
ximprove tel control to allow empty string
|
|
1146
|
-
x15. some autocomplete wish to allow additional column like 6% tax, now become additional fields
|
|
1147
|
-
x9. frontend authentication
|
|
1148
|
-
x1. auto pretty backend and frontend
|
|
1149
|
-
x2. fix pages:id issue
|
|
1150
|
-
x3. search at backend
|
|
1151
|
-
1. remain codes after regenerate (backend)
|
|
1152
|
-
x - service
|
|
1153
|
-
x - schema
|
|
1154
|
-
x - controller
|
|
1155
|
-
x8. block uniquekey
|
|
1156
|
-
1. remain codes after regenerate (frontend)
|
|
1157
|
-
x - pages
|
|
1158
|
-
x - composable (no need )
|
|
1159
|
-
x6. fill in data for tenant/org/branch created,updated,createdBy,updatedBy
|
|
1160
|
-
14. force x-document-no/name is required
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
## Bug fix
|
|
1165
|
-
1. Openapi some schema like primarykey/more not generated, cause error in ide
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
Document Numbering System
|
|
1169
|
-
1. generate prepare list of document no for generate.
|
|
1170
|
-
x-document-no + document-format
|
|
1171
|
-
2. if x-document-no, will auto add docformat={}
|
|
1172
|
-
3. button can pick document-no format
|
|
1173
|
-
4. have add new function
|
|
1174
|
-
5. if type manually wont create new
|
|
1175
|
-
6. preview next no api
|
|
1176
|
-
7. generate next no api
|
|
1177
|
-
8. if _id = '', will auto preview next no
|
|
1178
|
-
9. after change default format, will preview another next no
|
|
1179
|
-
10. have list to pick format
|
|
1180
|
-
11. support transactions
|
|
1181
|
-
12. only list current branch document no options
|
|
1182
|
-
11. master data
|
|
1183
|
-
a. add list for document type
|
|
1184
|
-
b. click doctype then can available document settings
|
|
1185
|
-
c. document will set by branch
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
SimpleApp-Vue-Component Fix:
|
|
1189
|
-
1. table
|
|
1190
|
-
a. column title
|
|
1191
|
-
b. nested column data, like primarykey label
|
|
1192
|
-
c. search and functions like filters, pagination, large datas
|
|
1193
|
-
1. single/multi select
|
|
1194
|
-
4. search at frontend
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
Coding Rules
|
|
1198
|
-
1. create type and codes in 'shares'
|
|
1199
|
-
2. service class and doc class
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
JSON Properties
|
|
1205
|
-
document level property
|
|
1206
|
-
{
|
|
1207
|
-
"type":"object"
|
|
1208
|
-
"x-simpleapp-config":{
|
|
1209
|
-
//isolation type, none/tenant/org/branch
|
|
1210
|
-
"isolationType":"none",
|
|
1211
|
-
|
|
1212
|
-
//what special allow access it, undefine mean only super admin, and resource+action role can go in
|
|
1213
|
-
"requiredRoles":["SuperAdmin"],
|
|
1214
|
-
|
|
1215
|
-
// page type (example: crud), undefine will not generate page in frontend
|
|
1216
|
-
"pageType":"crud",
|
|
1217
|
-
|
|
1218
|
-
//unique key for document, it build compound index depends on isolationtype
|
|
1219
|
-
"uniqueKey":"invoiceNo",
|
|
1220
|
-
|
|
1221
|
-
//use as display name in autocomplete, also add into textsearch
|
|
1222
|
-
"documentTitle":"InvoiceTitle", //no define this will not have auto complete and text search for this field
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
//frontend uniqueKey field become special input field which can generate doc number, once activated auto create new field `docNoFormat`
|
|
1226
|
-
"generateDocumentNumber":true,
|
|
1227
|
-
|
|
1228
|
-
//frontend use this field to show current month document, docNumberFormat generator will have monthly document number setting
|
|
1229
|
-
"documentDate":"invoiceDate",
|
|
1230
|
-
|
|
1231
|
-
//manage document status and accessibility, it auto add field `documentStatus` when define
|
|
1232
|
-
"allStatus":[
|
|
1233
|
-
{"status":"CO","readOnly":true,"actions":["revert","void","close"]},
|
|
1234
|
-
{"status":"V","readOnly":true,"actions":["revert"]},
|
|
1235
|
-
],
|
|
1236
|
-
|
|
1237
|
-
//all custom api, response, paras, operation put here. variable define at entryPoint or querypara
|
|
1238
|
-
"allApi":[{
|
|
1239
|
-
"action":"confirm",
|
|
1240
|
-
"entrypoint":":id/confirm",
|
|
1241
|
-
"requiredrole":["SuperUser"],
|
|
1242
|
-
"method":"post",
|
|
1243
|
-
"execute":"ping",
|
|
1244
|
-
"description":"confirm document and change status to CO"
|
|
1245
|
-
},{
|
|
1246
|
-
"action":"void",
|
|
1247
|
-
"entrypoint":":id/void",
|
|
1248
|
-
"querypara":["reason"],
|
|
1249
|
-
"requiredrole":["SuperUser"],
|
|
1250
|
-
"method":"post",
|
|
1251
|
-
"execute":"ping",
|
|
1252
|
-
"description":"confirm document and change status to CO"
|
|
1253
|
-
}],
|
|
1254
|
-
|
|
1255
|
-
// simple => pure model and service(no page,api),
|
|
1256
|
-
// default => force masterdata property,
|
|
1257
|
-
// transaction => force masterdata property
|
|
1258
|
-
"schemaType": "default",
|
|
1259
|
-
|
|
1260
|
-
//frontend(client) and backend (processor) typescript class auto import this lib, helper for `formula`
|
|
1261
|
-
"libs":[{"lib":"lodash","as":"_"}], // both process class and frontend client class will import same lib
|
|
1262
|
-
|
|
1263
|
-
// frontend apply recalculation everytime current document change
|
|
1264
|
-
// backend auto apply formula during create and update
|
|
1265
|
-
"formula": [ //apply both frontend and backend, it different with concept on change, sequence of formula important
|
|
1266
|
-
{"jsonPath":"$.subtotal","formula":"jslib.getDocumentSubTotal(@F{$.details})"}, //apply formula into single field
|
|
1267
|
-
{"jsonPath":"$.tags","formula":"$F{$.tags}.map(item=>item.toUppeCase())"}, //apply upper case to all item in string array
|
|
1268
|
-
{"jsonPath":"$.details","loop":"jslib.calculateLineTotal(item)"}, //apply multiple calculation of subtotal, tax, amtaftertax and etc, using loop
|
|
1269
|
-
{"jsonPath":"$.total","formula":"@F{$.subtotal} + @F{$.taxamt}"}, //apply simple formula here
|
|
1270
|
-
],
|
|
1271
|
-
|
|
1272
|
-
// auto generate fields
|
|
1273
|
-
documentType: 'SI',
|
|
1274
|
-
documentName: 'Sales Invoice',
|
|
1275
|
-
|
|
1276
|
-
//auto generated foreign keys catalogue
|
|
1277
|
-
"foreignKeys":{ "customer":["$.customer._id"], "user":[{"$.preparedby._id"},{$.approveby._id"}]}
|
|
1278
|
-
},
|
|
1279
|
-
"properties":{
|
|
1280
|
-
"invoiceDate":{"type":"string"},
|
|
1281
|
-
//and others field
|
|
1282
|
-
}
|
|
1283
|
-
}
|