adminforth 1.0.84 → 1.0.86
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/dist/index.js +15 -16
- package/dist/modules/codeInjector.js +2 -2
- package/dist/plugins/ForeignInlineListPlugin/index.js +3 -2
- package/dist/servers/express.js +0 -3
- package/dist/spa/spa/package-lock.json +13 -0
- package/dist/spa/spa/package.json +1 -0
- package/dist/spa/spa/src/App.vue +44 -19
- package/dist/spa/spa/src/components/AcceptModal.vue +2 -9
- package/dist/spa/spa/src/components/Toast.vue +65 -0
- package/dist/spa/spa/src/components/ValueRenderer.vue +8 -8
- package/dist/spa/spa/src/composables/useStores.ts +51 -0
- package/dist/spa/spa/src/stores/core.ts +5 -1
- package/dist/spa/spa/src/stores/modal.ts +13 -2
- package/dist/spa/spa/src/stores/toast.ts +15 -0
- package/dist/spa/spa/src/views/CreateView.vue +5 -5
- package/dist/spa/spa/src/views/EditView.vue +8 -7
- package/dist/spa/spa/src/views/ListView.vue +8 -9
- package/dist/spa/spa/src/views/ShowView.vue +13 -10
- package/dist/types/AdminForthConfig.js +25 -17
- package/dist/types/FrontendAPI.js +7 -0
- package/documentation/docs/Getting Started.md +374 -0
- package/documentation/docs/Glossary.md +37 -0
- package/documentation/docs/image.png +0 -0
- package/documentation/docusaurus.config.ts +1 -1
- package/index.ts +29 -35
- package/modules/codeInjector.ts +4 -4
- package/package.json +1 -1
- package/plugins/ForeignInlineListPlugin/index.ts +3 -3
- package/servers/express.ts +4 -9
- package/spa/package-lock.json +13 -0
- package/spa/package.json +1 -0
- package/spa/src/App.vue +44 -19
- package/spa/src/components/AcceptModal.vue +2 -9
- package/spa/src/components/Toast.vue +65 -0
- package/spa/src/components/ValueRenderer.vue +8 -8
- package/spa/src/composables/useStores.ts +51 -0
- package/spa/src/stores/core.ts +5 -1
- package/spa/src/stores/modal.ts +13 -2
- package/spa/src/stores/toast.ts +15 -0
- package/spa/src/views/CreateView.vue +5 -5
- package/spa/src/views/EditView.vue +8 -7
- package/spa/src/views/ListView.vue +8 -9
- package/spa/src/views/ShowView.vue +13 -10
- package/types/AdminForthConfig.ts +332 -62
- package/types/FrontendAPI.ts +73 -0
|
@@ -1,13 +1,89 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
-
export interface CodeInjector {
|
|
3
|
+
export interface CodeInjectorType {
|
|
4
4
|
srcFoldersToSync: Object;
|
|
5
5
|
allComponentNames: Object;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Implement this interface to create custom HTTP server adapter for AdminForth.
|
|
10
|
+
*/
|
|
11
|
+
export interface GenericHttpServer {
|
|
12
|
+
|
|
13
|
+
// constructor(adminforth: AdminForthClass): void;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sets up HTTP server to serve AdminForth SPA.
|
|
17
|
+
* if hotReload is true, it should proxy all requests and headers to Vite dev server at `http://localhost:5173$\{req.url\}`
|
|
18
|
+
* otherwise it should serve AdminForth SPA from dist folder. See Express for example.
|
|
19
|
+
*/
|
|
20
|
+
setupSpaServer(): void;
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ExpressHttpServer extends GenericHttpServer {
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Call this method to serve AdminForth SPA from Express instance.
|
|
28
|
+
* @param app : Express instance
|
|
29
|
+
*/
|
|
30
|
+
serve(app: Express): void;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Method (middleware) to wrap express endpoints with authorization check.
|
|
34
|
+
* Adds adminUser to request object if user is authorized. Drops request with 401 status if user is not authorized.
|
|
35
|
+
* @param callable : Function which will be called if user is authorized.
|
|
36
|
+
*
|
|
37
|
+
* Example:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* expressApp.get('/myApi', authorize((req, res) => \{
|
|
41
|
+
* console.log('User is authorized', req.adminUser);
|
|
42
|
+
* res.json(\{ message: 'Hello World' \});
|
|
43
|
+
* \}));
|
|
44
|
+
* ``
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
authorize(callable: Function): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
8
51
|
export interface AdminForthClass {
|
|
9
52
|
config: AdminForthConfig;
|
|
10
|
-
codeInjector:
|
|
53
|
+
codeInjector: CodeInjectorType;
|
|
54
|
+
express: GenericHttpServer;
|
|
55
|
+
|
|
56
|
+
auth: {
|
|
57
|
+
|
|
58
|
+
verify(jwt : string): any;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Internal flag which indicates if AdminForth is running in hot reload mode.
|
|
63
|
+
*/
|
|
64
|
+
runningHotReload: boolean;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Connects to databases defined in datasources and fetches described resource columns to find out data types and constraints.
|
|
69
|
+
* You must call this method as soon as possible after AdminForth class is instantiated.
|
|
70
|
+
*/
|
|
71
|
+
discoverDatabases(): Promise<void>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Bundles AdminForth SPA by injecting custom components into internal pre-made SPA source code. It generates internally dist which then will be
|
|
75
|
+
* served by AdminForth HTTP adapter.
|
|
76
|
+
* Bundle is generated in /tmp folder so if you have ramfs or tmpfs this operation will be faster.
|
|
77
|
+
*
|
|
78
|
+
* We recommend calling this method from dedicated script which will be run by CI/CD pipeline in build time. This ensures lowest downtime for your users.
|
|
79
|
+
* However for simple setup you can call it from your main script, and users will see some "AdminForth is bundling" message in the admin panel while app is bundling.
|
|
80
|
+
*/
|
|
81
|
+
bundleNow({ hotReload, verbose }: { hotReload: boolean, verbose: boolean }): Promise<void>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* This method will be automatically called from AdminForth HTTP adapter to serve AdminForth SPA.
|
|
85
|
+
*/
|
|
86
|
+
setupEndpoints(server: GenericHttpServer): void;
|
|
11
87
|
}
|
|
12
88
|
|
|
13
89
|
|
|
@@ -19,59 +95,71 @@ export interface AdminForthPluginType {
|
|
|
19
95
|
componentPath(componentFile: string): string;
|
|
20
96
|
}
|
|
21
97
|
|
|
22
|
-
export enum
|
|
98
|
+
export enum AdminForthMenuTypes {
|
|
23
99
|
/**
|
|
24
100
|
* HEADING is just a label in the menu.
|
|
25
|
-
* Respect `label` and `icon` property in @AdminForthConfigMenuItem
|
|
101
|
+
* Respect `label` and `icon` property in {@link AdminForthConfigMenuItem}
|
|
26
102
|
*/
|
|
27
|
-
|
|
103
|
+
heading = 'heading',
|
|
28
104
|
|
|
29
105
|
/**
|
|
30
106
|
* GROUP is a group of menu items.
|
|
31
|
-
* Respects `label`, `icon` and `children` properties in @AdminForthConfigMenuItem
|
|
32
|
-
* use @
|
|
107
|
+
* Respects `label`, `icon` and `children` properties in {@link AdminForthConfigMenuItem}
|
|
108
|
+
* use @AdminForthMenuTypes.open to set if group is open by default
|
|
33
109
|
*/
|
|
34
|
-
|
|
110
|
+
group = 'group',
|
|
35
111
|
|
|
36
112
|
/**
|
|
37
113
|
* RESOURCE is a link to a resource.
|
|
38
|
-
* Respects `label`, `icon`, `resourceId`, `homepage`, `isStaticRoute` properties in @AdminForthConfigMenuItem
|
|
114
|
+
* Respects `label`, `icon`, `resourceId`, `homepage`, `isStaticRoute` properties in {@link AdminForthConfigMenuItem}
|
|
39
115
|
*/
|
|
40
|
-
|
|
116
|
+
resource = 'resource',
|
|
41
117
|
|
|
42
118
|
/**
|
|
43
119
|
* PAGE is a link to a custom page.
|
|
44
|
-
* Respects `label`, `icon`, `path`, `component`, `homepage`, `isStaticRoute`, properties in @AdminForthConfigMenuItem
|
|
120
|
+
* Respects `label`, `icon`, `path`, `component`, `homepage`, `isStaticRoute`, properties in {@link AdminForthConfigMenuItem}
|
|
45
121
|
*
|
|
46
122
|
* Example:
|
|
47
123
|
*
|
|
48
124
|
* ```ts
|
|
49
|
-
* {
|
|
50
|
-
* type:
|
|
125
|
+
* \{
|
|
126
|
+
* type: AdminForthMenuTypes.PAGE,
|
|
51
127
|
* label: 'Custom Page',
|
|
52
128
|
* icon: 'home',
|
|
53
129
|
* path: '/dash',
|
|
54
130
|
* component: '@@/Dashboard.vue',
|
|
55
131
|
* homepage: true,
|
|
56
|
-
* }
|
|
132
|
+
* \}
|
|
57
133
|
* ```
|
|
58
134
|
*
|
|
59
135
|
*/
|
|
60
|
-
|
|
136
|
+
page = 'page',
|
|
61
137
|
|
|
62
138
|
/**
|
|
63
139
|
* GAP ads some space between menu items.
|
|
64
140
|
*/
|
|
65
|
-
|
|
141
|
+
gap = 'gap',
|
|
66
142
|
|
|
67
143
|
/**
|
|
68
144
|
* DIVIDER is a divider between menu items.
|
|
69
145
|
*/
|
|
70
|
-
|
|
146
|
+
divider = 'divider',
|
|
71
147
|
}
|
|
72
148
|
|
|
149
|
+
export enum AdminForthResourcePages {
|
|
150
|
+
list = 'list',
|
|
151
|
+
show = 'show',
|
|
152
|
+
edit = 'edit',
|
|
153
|
+
create = 'create',
|
|
154
|
+
filter = 'filter',
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Menu item which displayed in the left sidebar of the admin panel.
|
|
160
|
+
*/
|
|
73
161
|
export type AdminForthConfigMenuItem = {
|
|
74
|
-
type?:
|
|
162
|
+
type?: AdminForthMenuTypes | keyof typeof AdminForthMenuTypes,
|
|
75
163
|
|
|
76
164
|
/**
|
|
77
165
|
* Label for menu item which will be displayed in the admin panel.
|
|
@@ -100,7 +188,7 @@ export type AdminForthConfigMenuItem = {
|
|
|
100
188
|
|
|
101
189
|
/**
|
|
102
190
|
* Component to be used for this menu item. Component should be placed in custom folder and referenced with `@@/` prefix.
|
|
103
|
-
* Supported for
|
|
191
|
+
* Supported for AdminForthMenuTypes.PAGE only!
|
|
104
192
|
* Example:
|
|
105
193
|
*
|
|
106
194
|
* ```ts
|
|
@@ -112,7 +200,7 @@ export type AdminForthConfigMenuItem = {
|
|
|
112
200
|
|
|
113
201
|
/**
|
|
114
202
|
* Resource ID which will be used to fetch data from.
|
|
115
|
-
* Supported for
|
|
203
|
+
* Supported for AdminForthMenuTypes.RESOURCE only!
|
|
116
204
|
*
|
|
117
205
|
*/
|
|
118
206
|
resourceId?: string,
|
|
@@ -125,14 +213,14 @@ export type AdminForthConfigMenuItem = {
|
|
|
125
213
|
|
|
126
214
|
/**
|
|
127
215
|
* Where Group is open by default
|
|
128
|
-
* Supported for
|
|
216
|
+
* Supported for AdminForthMenuTypes.GROUP only!
|
|
129
217
|
*
|
|
130
|
-
|
|
218
|
+
*/
|
|
131
219
|
open?: boolean,
|
|
132
220
|
|
|
133
221
|
/**
|
|
134
222
|
* Children menu items which will be displayed in this group.
|
|
135
|
-
* Supported for
|
|
223
|
+
* Supported for AdminForthMenuTypes.GROUP only!
|
|
136
224
|
*/
|
|
137
225
|
children?: Array<AdminForthConfigMenuItem>,
|
|
138
226
|
|
|
@@ -148,33 +236,144 @@ export type AdminForthConfigMenuItem = {
|
|
|
148
236
|
},
|
|
149
237
|
}
|
|
150
238
|
|
|
151
|
-
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Column describes one field in the table or collection in database.
|
|
242
|
+
*/
|
|
152
243
|
export type AdminForthResourceColumn = {
|
|
244
|
+
/**
|
|
245
|
+
* Column name in database.
|
|
246
|
+
*/
|
|
153
247
|
name: string,
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* How column can be labled in the admin panel.
|
|
251
|
+
* Use it for renaming columns. Defaulted to column name with Uppercased first letter.
|
|
252
|
+
*/
|
|
154
253
|
label?: string,
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Type of data in column.
|
|
257
|
+
* AdminForth will use this information to render proper input fields in the admin panel.
|
|
258
|
+
* AdminForth tries to guess type of data from database column type automatically for typed databases like SQL-based.
|
|
259
|
+
* However you can explicitly set it to any value. E.g. set AdminForthDataTypes.DATETIME for your string column in SQLite, which stores ISO date strings.
|
|
260
|
+
*/
|
|
155
261
|
type?: AdminForthDataTypes,
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Whether to use this column as record identifier.
|
|
265
|
+
* Only one column can be primary key.
|
|
266
|
+
* AdminForth tries to guess primary key automatically first.
|
|
267
|
+
*/
|
|
156
268
|
primaryKey?: boolean,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Whether AdminForth will require this field to be filled in create and edit forms.
|
|
272
|
+
* Can be set to boolean or object with create and edit properties.
|
|
273
|
+
* If boolean, it will be used for both create and edit forms.
|
|
274
|
+
*/
|
|
275
|
+
required?: boolean | { create?: boolean, edit?: boolean },
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Whether AdminForth will show editing note near the field in edit/create form.
|
|
279
|
+
*/
|
|
280
|
+
editingNote?: string | { create?: string, edit?: string },
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* On which AdminForth pages this field will be shown. By default all.
|
|
284
|
+
* Example: if you want to show field only in create and edit pages, set it to
|
|
285
|
+
*
|
|
286
|
+
* ```ts
|
|
287
|
+
* showIn: [AdminForthResourcePages.CREATE, AdminForthResourcePages.EDIT]
|
|
288
|
+
* ```
|
|
289
|
+
*
|
|
290
|
+
*/
|
|
291
|
+
showIn?: Array<AdminForthResourcePages | keyof typeof AdminForthResourcePages>,
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Whether AdminForth will show this field in show view.
|
|
295
|
+
*/
|
|
160
296
|
fillOnCreate?: Function,
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Whether AdminForth will request user to enter unique value during creating or editing record.
|
|
300
|
+
* This option causes AdminForth to make a request to database to check if value is unique.
|
|
301
|
+
* (Constraints are not used, so for large-tables performance make sure you have unique index in database if you set this option to true)
|
|
302
|
+
*/
|
|
161
303
|
isUnique?: boolean,
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Runtime validation Regexp rules for this field.
|
|
308
|
+
*/
|
|
162
309
|
validation?: Array<ValidationObject>,
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Allows to make the field which does not exist in database table.
|
|
313
|
+
* Examples: add custom show field with user country flag:
|
|
314
|
+
*
|
|
315
|
+
* ```ts
|
|
316
|
+
* {
|
|
317
|
+
* label: 'Country',
|
|
318
|
+
* type: AdminForthDataTypes.STRING,
|
|
319
|
+
* virtual: true,
|
|
320
|
+
* showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
|
|
321
|
+
* components: {
|
|
322
|
+
* show: '@@/CountryFlag.vue',
|
|
323
|
+
* list: '@@/CountryFlag.vue',
|
|
324
|
+
* },
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* This field will be displayed in show and list views with custom component `CountryFlag.vue`. CountryFlag.vue should be placed in custom folder and can be next:
|
|
329
|
+
*
|
|
330
|
+
* ```vue
|
|
331
|
+
* <template>
|
|
332
|
+
* {{ getFlagEmojiFromIso(record.ipCountry) }}
|
|
333
|
+
* </template>
|
|
334
|
+
*
|
|
335
|
+
* <script setup>
|
|
336
|
+
* const props = defineProps(['record']);
|
|
337
|
+
*
|
|
338
|
+
* function getFlagEmojiFromIso(iso) {
|
|
339
|
+
* return iso.toUpperCase().replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397));
|
|
340
|
+
* }
|
|
341
|
+
* </script>
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
*/
|
|
163
345
|
virtual?: boolean,
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Whether AdminForth will show this field in list view.
|
|
349
|
+
*/
|
|
164
350
|
allowMinMaxQuery?: boolean,
|
|
165
|
-
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Custom components which will be used to render this field in the admin panel.
|
|
354
|
+
*/
|
|
355
|
+
components?: AdminForthFieldComponents
|
|
166
356
|
maxLength?: number,
|
|
167
357
|
minLength?: number,
|
|
168
358
|
min?: number,
|
|
169
359
|
max?: number,
|
|
170
360
|
minValue?: number,
|
|
171
361
|
maxValue?: number,
|
|
172
|
-
enum?: Array<
|
|
173
|
-
foreignResource?:
|
|
362
|
+
enum?: Array<AdminForthColumnEnumItem>,
|
|
363
|
+
foreignResource?:AdminForthForeignResource,
|
|
174
364
|
sortable?: boolean,
|
|
175
365
|
backendOnly?: boolean, // if true field will not be passed to UI under no circumstances, but will be presented in hooks
|
|
176
|
-
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Masked fields will be displayed as `*****` on Edit and Create pages.
|
|
369
|
+
*/
|
|
370
|
+
masked?: boolean,
|
|
371
|
+
}
|
|
177
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Resource describes one table or collection in database.
|
|
375
|
+
* AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
|
|
376
|
+
*/
|
|
178
377
|
export type AdminForthResource = {
|
|
179
378
|
/**
|
|
180
379
|
* Unique identifier of resource. By default it equals to table name in database.
|
|
@@ -205,28 +404,23 @@ export type AdminForthResource = {
|
|
|
205
404
|
*/
|
|
206
405
|
columns: Array<AdminForthResourceColumn>,
|
|
207
406
|
|
|
407
|
+
|
|
208
408
|
dataSourceColumns?: Array<AdminForthResourceColumn>, // TODO, mark as private
|
|
209
409
|
|
|
210
410
|
/**
|
|
211
|
-
* Hook which allow you to modify
|
|
411
|
+
* Hook which allow you to modify record label
|
|
212
412
|
*
|
|
213
413
|
* Example:
|
|
214
414
|
*
|
|
215
415
|
* ```ts
|
|
216
|
-
*
|
|
416
|
+
* recordLabel: (record) => `${record.name} - ${record.id}`,
|
|
217
417
|
* ```
|
|
218
418
|
*
|
|
219
419
|
*/
|
|
220
|
-
|
|
420
|
+
recordLabel?: Function,
|
|
221
421
|
|
|
222
422
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* Example:
|
|
226
|
-
*
|
|
227
|
-
* ```ts
|
|
228
|
-
* itemTitle: (item) => `${item.name} - ${item.id}`,
|
|
229
|
-
* ```
|
|
423
|
+
* Array of plugins which will be used to modify resource configuration.
|
|
230
424
|
*
|
|
231
425
|
*/
|
|
232
426
|
plugins?: Array<AdminForthPluginType>,
|
|
@@ -282,23 +476,47 @@ export type AdminForthResource = {
|
|
|
282
476
|
* }
|
|
283
477
|
* ```
|
|
284
478
|
*
|
|
479
|
+
*
|
|
285
480
|
*/
|
|
286
481
|
pageInjections?: {
|
|
482
|
+
/**
|
|
483
|
+
* Custom components which can be injected into resource list page.
|
|
484
|
+
*
|
|
485
|
+
* Component accepts next props: [resource, adminUser]
|
|
486
|
+
*/
|
|
287
487
|
list?: {
|
|
288
488
|
beforeBreadcrumbs?: string | Array<string>,
|
|
289
489
|
afterBreadcrumbs?: string | Array<string>,
|
|
290
490
|
bottom?: string | Array<string>,
|
|
291
491
|
},
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Custom components which can be injected into resource show page.
|
|
495
|
+
*
|
|
496
|
+
* Component accepts next props: [record, resource, adminUser]
|
|
497
|
+
*/
|
|
292
498
|
show?: {
|
|
293
499
|
beforeBreadcrumbs?: string | Array<string>,
|
|
294
500
|
afterBreadcrumbs?: string | Array<string>,
|
|
295
501
|
bottom?: string | Array<string>,
|
|
296
502
|
},
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Custom components which can be injected into resource edit page.
|
|
506
|
+
*
|
|
507
|
+
* Component accepts next props: [record, resource, adminUser]
|
|
508
|
+
*/
|
|
297
509
|
edit?: {
|
|
298
510
|
beforeBreadcrumbs?: string | Array<string>,
|
|
299
511
|
afterBreadcrumbs?: string | Array<string>,
|
|
300
512
|
bottom?: string | Array<string>,
|
|
301
513
|
},
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Custom components which can be injected into resource create page.
|
|
517
|
+
*
|
|
518
|
+
* Component accepts next props: [resource, adminUser]
|
|
519
|
+
*/
|
|
302
520
|
create?: {
|
|
303
521
|
beforeBreadcrumbs?: string | Array<string>,
|
|
304
522
|
afterBreadcrumbs?: string | Array<string>,
|
|
@@ -308,11 +526,27 @@ export type AdminForthResource = {
|
|
|
308
526
|
},
|
|
309
527
|
}
|
|
310
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Data source describes database connection which will be used to fetch data for resources.
|
|
531
|
+
* Each resource should use one data source.
|
|
532
|
+
*/
|
|
311
533
|
export type AdminForthDataSource = {
|
|
312
|
-
|
|
313
|
-
|
|
534
|
+
/**
|
|
535
|
+
* ID of datasource which you will use in resources to specify from which database to fetch data from
|
|
536
|
+
*/
|
|
537
|
+
id: string,
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* URL to database. Examples:
|
|
541
|
+
*
|
|
542
|
+
* - MongoDB: `mongodb://<user>:<password>@<host>:<port>/<database>`
|
|
543
|
+
* - PostgreSQL: `postgresql://<user>:<password>@<host>:<port>/<database>`
|
|
544
|
+
* - SQLite: `sqlite://<path>`
|
|
545
|
+
*/
|
|
546
|
+
url: string,
|
|
314
547
|
}
|
|
315
548
|
|
|
549
|
+
|
|
316
550
|
/**
|
|
317
551
|
* Main configuration object for AdminForth
|
|
318
552
|
*/
|
|
@@ -401,7 +635,7 @@ export type AdminForthConfig = {
|
|
|
401
635
|
* Datasource is one database connection
|
|
402
636
|
*
|
|
403
637
|
*/
|
|
404
|
-
dataSources: Array<
|
|
638
|
+
dataSources: Array<AdminForthDataSource>,
|
|
405
639
|
|
|
406
640
|
/**
|
|
407
641
|
* Settings which allow you to customize AdminForth
|
|
@@ -454,7 +688,7 @@ export type AdminForthConfig = {
|
|
|
454
688
|
* For example if file path is `./custom/comp/my.vue`, you can use it in AdminForth config like this:
|
|
455
689
|
*
|
|
456
690
|
* ```ts
|
|
457
|
-
*
|
|
691
|
+
* components: {
|
|
458
692
|
* show: '@@/comp/my.vue',
|
|
459
693
|
* }
|
|
460
694
|
* ```
|
|
@@ -512,6 +746,7 @@ export type AllowedActions = {
|
|
|
512
746
|
edit?: boolean,
|
|
513
747
|
show?: boolean,
|
|
514
748
|
delete?: boolean,
|
|
749
|
+
filter?: boolean,
|
|
515
750
|
}
|
|
516
751
|
|
|
517
752
|
export type ValidationObject = {
|
|
@@ -536,27 +771,62 @@ export type ValidationObject = {
|
|
|
536
771
|
message: string,
|
|
537
772
|
}
|
|
538
773
|
|
|
539
|
-
|
|
774
|
+
|
|
775
|
+
export type AdminForthFieldComponents = {
|
|
540
776
|
/**
|
|
541
|
-
*
|
|
777
|
+
* Show component is used to redefine cell which renders field value in show view.
|
|
778
|
+
* Component accepts next properties: [record, column, resource, adminUser].
|
|
779
|
+
*
|
|
780
|
+
* Example: `FullName.vue`
|
|
781
|
+
*
|
|
782
|
+
* ```vue
|
|
783
|
+
* <template>
|
|
784
|
+
* {{ record.firstName }} {{ record.lastName }}
|
|
785
|
+
* </template>
|
|
786
|
+
*
|
|
787
|
+
* <script setup>
|
|
788
|
+
* defineProps(['record']);
|
|
789
|
+
* </script>
|
|
790
|
+
*
|
|
791
|
+
* ```ts
|
|
792
|
+
* {
|
|
793
|
+
* label: 'Full Name',
|
|
794
|
+
* virtual: true,
|
|
795
|
+
* showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
|
|
796
|
+
* components: {
|
|
797
|
+
* show: '@@/FullName.vue',
|
|
798
|
+
* list: '@@/FullName.vue',
|
|
799
|
+
* },
|
|
800
|
+
* }
|
|
801
|
+
* ```
|
|
802
|
+
*
|
|
542
803
|
*/
|
|
543
|
-
|
|
804
|
+
show?: string,
|
|
544
805
|
|
|
545
806
|
/**
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
* - MongoDB: `mongodb://<user>:<password>@<host>:<port>/<database>`
|
|
549
|
-
* - PostgreSQL: `postgresql://<user>:<password>@<host>:<port>/<database>`
|
|
550
|
-
* - SQLite: `sqlite://<path>`
|
|
807
|
+
* showRow component is similar to {@link AdminForthFieldComponent.show} but rewrites full table row (both \<td\> tags)
|
|
808
|
+
* Accepts next properties: [record, column, resource, adminUser]
|
|
551
809
|
*/
|
|
552
|
-
|
|
553
|
-
}
|
|
810
|
+
showRow?: string,
|
|
554
811
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
812
|
+
/**
|
|
813
|
+
* Create component is used to redefine input field in create view.
|
|
814
|
+
* Component accepts next properties: [record, column, resource, adminUser].
|
|
815
|
+
*/
|
|
558
816
|
create?: string,
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Edit component is used to redefine input field in edit view.
|
|
820
|
+
* Component accepts next properties: [record, column, resource, adminUser].
|
|
821
|
+
*/
|
|
559
822
|
edit?: string,
|
|
823
|
+
|
|
824
|
+
/**
|
|
825
|
+
* List component is used to redefine cell which renders field value in list view.
|
|
826
|
+
* Component accepts next properties: [record, column, resource, adminUser].
|
|
827
|
+
*
|
|
828
|
+
* Exa
|
|
829
|
+
*/
|
|
560
830
|
list?: string,
|
|
561
831
|
}
|
|
562
832
|
|
|
@@ -592,12 +862,12 @@ export enum AdminForthSortDirections {
|
|
|
592
862
|
};
|
|
593
863
|
|
|
594
864
|
|
|
595
|
-
export type
|
|
596
|
-
value:
|
|
865
|
+
export type AdminForthColumnEnumItem = {
|
|
866
|
+
value: any | null,
|
|
597
867
|
label: string,
|
|
598
868
|
}
|
|
599
869
|
|
|
600
|
-
export type
|
|
870
|
+
export type AdminForthForeignResource = {
|
|
601
871
|
resourceId: string,
|
|
602
872
|
hooks?: {
|
|
603
873
|
dropdownList?: {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
export interface FrontendAPIInterface {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Show a confirmation dialog
|
|
6
|
+
*
|
|
7
|
+
* The dialog will be displayed to the user
|
|
8
|
+
*
|
|
9
|
+
* Example:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const isConfirmed = await window.adminforth.confirm({message: 'Are you sure?', yes: 'Yes', no: 'No'})
|
|
13
|
+
* if (isConfirmed) {
|
|
14
|
+
* your code...
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param params - The parameters of the dialog
|
|
19
|
+
* @returns A promise that resolves when the user confirms the dialog
|
|
20
|
+
*/
|
|
21
|
+
confirm(params:ConfirmParams ): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Show an alert
|
|
24
|
+
*
|
|
25
|
+
* The alert will be displayed to the user
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* window.adminforth.alert({message: 'Hello', variant: 'success'})
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param params - The parameters of the alert
|
|
34
|
+
*/
|
|
35
|
+
alert(params:AlertParams): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ConfirmParams = {
|
|
39
|
+
/**
|
|
40
|
+
* The message to display in the dialog
|
|
41
|
+
*/
|
|
42
|
+
message?: string;
|
|
43
|
+
/**
|
|
44
|
+
* The text to display in the "accept" button
|
|
45
|
+
*/
|
|
46
|
+
yes?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The text to display in the "cancel" button
|
|
49
|
+
*/
|
|
50
|
+
no?: string;
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type AlertParams = {
|
|
55
|
+
/**
|
|
56
|
+
* The message to display in the alert
|
|
57
|
+
*/
|
|
58
|
+
message?: string;
|
|
59
|
+
/**
|
|
60
|
+
* The variant of the alert
|
|
61
|
+
*/
|
|
62
|
+
variant?: AlertVariant;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum AlertVariant {
|
|
66
|
+
Danger = 'danger',
|
|
67
|
+
Success = 'success',
|
|
68
|
+
Warning = 'warning',
|
|
69
|
+
Info = 'info'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|