adminforth 1.5.15-next.6 → 1.5.15

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.
Files changed (94) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +63 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/spa/.eslintrc.cjs +14 -0
  6. package/dist/spa/README.md +39 -0
  7. package/dist/spa/env.d.ts +1 -0
  8. package/dist/spa/index.html +23 -0
  9. package/dist/spa/package-lock.json +5062 -0
  10. package/dist/spa/package.json +58 -0
  11. package/dist/spa/postcss.config.js +6 -0
  12. package/dist/spa/public/assets/favicon.png +0 -0
  13. package/dist/spa/src/App.vue +432 -0
  14. package/dist/spa/src/adminforth.ts +160 -0
  15. package/dist/spa/src/afcl/AreaChart.vue +160 -0
  16. package/dist/spa/src/afcl/BarChart.vue +170 -0
  17. package/dist/spa/src/afcl/Button.vue +27 -0
  18. package/dist/spa/src/afcl/Checkbox.vue +24 -0
  19. package/dist/spa/src/afcl/Dropzone.vue +128 -0
  20. package/dist/spa/src/afcl/Input.vue +42 -0
  21. package/dist/spa/src/afcl/Link.vue +17 -0
  22. package/dist/spa/src/afcl/LinkButton.vue +25 -0
  23. package/dist/spa/src/afcl/PieChart.vue +175 -0
  24. package/dist/spa/src/afcl/ProgressBar.vue +57 -0
  25. package/dist/spa/src/afcl/Select.vue +246 -0
  26. package/dist/spa/src/afcl/Skeleton.vue +26 -0
  27. package/dist/spa/src/afcl/Spinner.vue +9 -0
  28. package/dist/spa/src/afcl/Table.vue +116 -0
  29. package/dist/spa/src/afcl/Tooltip.vue +43 -0
  30. package/dist/spa/src/afcl/VerticalTabs.vue +49 -0
  31. package/dist/spa/src/afcl/index.ts +20 -0
  32. package/dist/spa/src/assets/base.css +2 -0
  33. package/dist/spa/src/assets/logo.svg +19 -0
  34. package/dist/spa/src/components/AcceptModal.vue +44 -0
  35. package/dist/spa/src/components/Breadcrumbs.vue +41 -0
  36. package/dist/spa/src/components/BreadcrumbsWithButtons.vue +25 -0
  37. package/dist/spa/src/components/CustomDatePicker.vue +180 -0
  38. package/dist/spa/src/components/CustomDateRangePicker.vue +218 -0
  39. package/dist/spa/src/components/CustomRangePicker.vue +156 -0
  40. package/dist/spa/src/components/Filters.vue +235 -0
  41. package/dist/spa/src/components/GroupsTable.vue +218 -0
  42. package/dist/spa/src/components/HelloWorld.vue +17 -0
  43. package/dist/spa/src/components/MenuLink.vue +41 -0
  44. package/dist/spa/src/components/ResourceForm.vue +260 -0
  45. package/dist/spa/src/components/ResourceListTable.vue +486 -0
  46. package/dist/spa/src/components/ShowTable.vue +81 -0
  47. package/dist/spa/src/components/SingleSkeletLoader.vue +13 -0
  48. package/dist/spa/src/components/SkeleteLoader.vue +18 -0
  49. package/dist/spa/src/components/ThreeDotsMenu.vue +43 -0
  50. package/dist/spa/src/components/Toast.vue +78 -0
  51. package/dist/spa/src/components/ValueRenderer.vue +141 -0
  52. package/dist/spa/src/components/icons/IconCalendar.vue +5 -0
  53. package/dist/spa/src/components/icons/IconCommunity.vue +7 -0
  54. package/dist/spa/src/components/icons/IconDocumentation.vue +7 -0
  55. package/dist/spa/src/components/icons/IconEcosystem.vue +7 -0
  56. package/dist/spa/src/components/icons/IconSupport.vue +7 -0
  57. package/dist/spa/src/components/icons/IconTime.vue +5 -0
  58. package/dist/spa/src/components/icons/IconTooling.vue +19 -0
  59. package/dist/spa/src/composables/useFrontendApi.ts +28 -0
  60. package/dist/spa/src/i18n.ts +54 -0
  61. package/dist/spa/src/index.scss +34 -0
  62. package/dist/spa/src/main.ts +22 -0
  63. package/dist/spa/src/renderers/CompactField.vue +46 -0
  64. package/dist/spa/src/renderers/CompactUUID.vue +46 -0
  65. package/dist/spa/src/renderers/CountryFlag.vue +65 -0
  66. package/dist/spa/src/renderers/HumanNumber.vue +58 -0
  67. package/dist/spa/src/renderers/RelativeTime.vue +42 -0
  68. package/dist/spa/src/renderers/URL.vue +18 -0
  69. package/dist/spa/src/router/index.ts +70 -0
  70. package/dist/spa/src/spa_types/core.ts +51 -0
  71. package/dist/spa/src/stores/core.ts +228 -0
  72. package/dist/spa/src/stores/filters.ts +27 -0
  73. package/dist/spa/src/stores/modal.ts +48 -0
  74. package/dist/spa/src/stores/toast.ts +30 -0
  75. package/dist/spa/src/stores/user.ts +79 -0
  76. package/dist/spa/src/types/Adapters.ts +26 -0
  77. package/dist/spa/src/types/Back.ts +1344 -0
  78. package/dist/spa/src/types/Common.ts +940 -0
  79. package/dist/spa/src/types/FrontendAPI.ts +189 -0
  80. package/dist/spa/src/utils.ts +184 -0
  81. package/dist/spa/src/views/CreateView.vue +167 -0
  82. package/dist/spa/src/views/EditView.vue +171 -0
  83. package/dist/spa/src/views/ListView.vue +442 -0
  84. package/dist/spa/src/views/LoginView.vue +199 -0
  85. package/dist/spa/src/views/PageNotFound.vue +20 -0
  86. package/dist/spa/src/views/ResourceParent.vue +50 -0
  87. package/dist/spa/src/views/ShowView.vue +209 -0
  88. package/dist/spa/src/websocket.ts +129 -0
  89. package/dist/spa/tailwind.config.js +19 -0
  90. package/dist/spa/tsconfig.app.json +14 -0
  91. package/dist/spa/tsconfig.json +11 -0
  92. package/dist/spa/tsconfig.node.json +19 -0
  93. package/dist/spa/vite.config.ts +52 -0
  94. package/package.json +2 -5
@@ -0,0 +1,940 @@
1
+
2
+ /**
3
+ * Types that are common for both frontend side (SPA) and backend side (server).
4
+ */
5
+
6
+ export enum AdminForthDataTypes {
7
+ STRING = 'string',
8
+ INTEGER = 'integer',
9
+ FLOAT = 'float',
10
+ DECIMAL = 'decimal',
11
+ BOOLEAN = 'boolean',
12
+ DATE = 'date',
13
+ DATETIME = 'datetime',
14
+ TIME = 'time',
15
+ TEXT = 'text',
16
+ JSON = 'json',
17
+ RICHTEXT = 'richtext',
18
+ }
19
+
20
+ export enum AdminForthFilterOperators {
21
+ EQ = 'eq',
22
+ NE = 'ne',
23
+ GT = 'gt',
24
+ LT = 'lt',
25
+ GTE = 'gte',
26
+ LTE = 'lte',
27
+ LIKE = 'like',
28
+ ILIKE = 'ilike',
29
+ IN = 'in',
30
+ NIN = 'nin',
31
+ };
32
+
33
+ export enum AdminForthSortDirections {
34
+ asc = 'asc',
35
+ desc = 'desc',
36
+ };
37
+
38
+
39
+ export interface AdminForthColumnEnumItem {
40
+ value: any | null,
41
+ label: string,
42
+ }
43
+
44
+ export enum ActionCheckSource {
45
+ DisplayButtons = 'displayButtons',
46
+ ListRequest = 'listRequest',
47
+ ShowRequest = 'showRequest',
48
+ EditLoadRequest = 'editLoadRequest', // when data for edit page is loaded
49
+ EditRequest = 'editRequest',
50
+ CreateRequest = 'createRequest',
51
+ DeleteRequest = 'deleteRequest',
52
+ BulkActionRequest = 'bulkActionRequest',
53
+ }
54
+
55
+ export enum AllowedActionsEnum {
56
+ show = 'show',
57
+ list = 'list',
58
+ edit = 'edit',
59
+ create = 'create',
60
+ delete = 'delete',
61
+ filter = 'filter',
62
+ }
63
+
64
+
65
+ export type AllowedActionsResolved = {
66
+ [key in AllowedActionsEnum]: boolean
67
+ }
68
+
69
+ export interface AdminUser {
70
+ /**
71
+ * primaryKey field value of user in table which is defined by {@link AdminForthConfig.auth.usersResourceId}
72
+ */
73
+ pk: string | null,
74
+
75
+ /**
76
+ * Username which taken from {@link AdminForthConfig.auth.usernameField} field in user resource {@link AdminForthConfig.auth.usersResourceId}
77
+ */
78
+ username: string,
79
+
80
+ /**
81
+ * User record fetched from database, from resource defined in {@link AdminForthConfig.auth.usersResourceId}
82
+ */
83
+ dbUser: any,
84
+ }
85
+
86
+
87
+ export interface AdminForthBulkActionCommon {
88
+ id?: string,
89
+
90
+ /**
91
+ * Label for action button which will be displayed in the list view
92
+ */
93
+ label: string,
94
+ state: string,
95
+
96
+ /**
97
+ * Icon for action button which will be displayed in the list view
98
+ */
99
+ icon?: string,
100
+
101
+ /**
102
+ * Confirmation message which will be displayed to user before action is executed.
103
+ */
104
+ confirm?: string,
105
+
106
+ /**
107
+ * Success message which will be displayed to user after action is executed.
108
+ */
109
+ successMessage?: string,
110
+
111
+ }
112
+
113
+ export interface AdminForthFieldComponents {
114
+ /**
115
+ * Show component is used to redefine cell which renders field value in show view.
116
+ * Component accepts next properties: [record, column, resource, adminUser, meta].
117
+ *
118
+ * Example: `FullName.vue`
119
+ *
120
+ * ```html
121
+ * <template>
122
+ * {{ record.firstName }} {{ record.lastName }}
123
+ * </template>
124
+ *
125
+ * <script setup>
126
+ * defineProps(['record']);
127
+ * </script>
128
+ *
129
+ * ```ts
130
+ * {
131
+ * label: 'Full Name',
132
+ * virtual: true,
133
+ * showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
134
+ * components: {
135
+ * show: '@@/FullName.vue',
136
+ * list: '@@/FullName.vue',
137
+ * },
138
+ * }
139
+ * ```
140
+ *
141
+ */
142
+ show?: AdminForthComponentDeclaration,
143
+
144
+ /**
145
+ * showRow component is similar to {@link AdminForthFieldComponent.show} but rewrites full table row (both \<td\> tags)
146
+ * Accepts next properties: [record, column, resource, adminUser]
147
+ */
148
+ showRow?: AdminForthComponentDeclaration,
149
+
150
+ /**
151
+ * Create component is used to redefine input field in create view.
152
+ * Component accepts next properties: [record, column, resource, adminUser].
153
+ */
154
+ create?: AdminForthComponentDeclaration,
155
+
156
+ /**
157
+ * Edit component is used to redefine input field in edit view.
158
+ * Component accepts next properties: [record, column, resource, adminUser].
159
+ */
160
+ edit?: AdminForthComponentDeclaration,
161
+
162
+ /**
163
+ * List component is used to redefine cell which renders field value in list view.
164
+ * Component accepts next properties: [record, column, resource, adminUser].
165
+ * Component can emit events:
166
+ * - `update:value` - to update record value.
167
+ * - `update:inValidity` - emit true once entered value became not valid (e.g. emit('update:inValidity', true) ). Emit false once entered value became valid. Emit default value in mounted hook.
168
+ * - `update:emptiness` - emit true once entered value became empty (e.g. emit('update:emptiness', true) ). Emit false once entered value became not empty. Emit default value in mounted hook.
169
+ * emptiness emit is optional and required for complex cases. For example for virtual columns where initial value is not set.
170
+ */
171
+ list?: AdminForthComponentDeclaration,
172
+ }
173
+
174
+
175
+ export interface AdminForthComponentDeclarationFull {
176
+ /**
177
+ * Path to custom component which will be used to render field in the admin panel.
178
+ * e.g. `@@/MyCustomComponent.vue`
179
+ */
180
+ file : string,
181
+
182
+ /**
183
+ * Optional Meta object which will be passed to custom component as props. For example used by plugins
184
+ * to pass plugin options to custom components.
185
+ *
186
+ * Example:
187
+ *
188
+ * ```ts
189
+ * {
190
+ * name: 'Country Flag',
191
+ * virtual: true,
192
+ * showIn: [AdminForthResourcePages.SHOW],
193
+ * components: {
194
+ * show: {
195
+ * file: '@@/Flag.vue',
196
+ * meta: {
197
+ * flagType: 'country',
198
+ * },
199
+ * },
200
+ * },
201
+ * },
202
+ * {
203
+ * name: 'Team Flag',
204
+ * virtual: true,
205
+ * showIn: [AdminForthResourcePages.SHOW],
206
+ * components: {
207
+ * show: {
208
+ * file: '@@/Flag.vue',
209
+ * meta: {
210
+ * flagType: 'team',
211
+ * },
212
+ * },
213
+ * },
214
+ * }
215
+ * ```
216
+ *
217
+ * In Flag.vue you can access this meta object like this:
218
+ *
219
+ * ```html
220
+ * <template>
221
+ * <img :src="loadFile(`@@/flags/${meta.flagType}/${meta.flagType === 'country' ? record.countryIso : record.teamCode}.png`)" />
222
+ * </template>
223
+ *
224
+ * <script setup>
225
+ * import { loadFile } from '@/utils';
226
+ * defineProps(['meta', 'record']);
227
+ * </script>
228
+ *
229
+ */
230
+ meta?: any,
231
+ }
232
+
233
+ export type AdminForthComponentDeclaration = AdminForthComponentDeclarationFull | string;
234
+
235
+ /**
236
+ * Resource describes one table or collection in database.
237
+ * AdminForth generates set of pages for 'list', 'show', 'edit', 'create', 'filter' operations for each resource.
238
+ */
239
+ export interface AdminForthResourceInputCommon {
240
+ /**
241
+ * Unique identifier of resource. By default it equals to table name in database.
242
+ * If you wish you can explicitly set it to any string.
243
+ * We added to support cases when 2 datasources have tables with the same name.
244
+ */
245
+ resourceId?: string,
246
+
247
+ /**
248
+ * Label for resource which will be displayed in the admin panel.
249
+ * By default it equals to table name in database.
250
+ */
251
+ label?: string,
252
+
253
+ /**
254
+ * Table name in database which will be used to fetch data from. Might be case sensitive.
255
+ */
256
+ table: string,
257
+
258
+ /**
259
+ * ID of datasource which will be used to fetch data from.
260
+ */
261
+ dataSource: string,
262
+
263
+ /**
264
+ * Array of columns which will be displayed in the admin panel.
265
+ * Each column has its own configuration.
266
+ */
267
+ columns: Array<AdminForthResourceColumnInputCommon>,
268
+
269
+ /**
270
+ * Hook which allow you to modify record label
271
+ *
272
+ * Example:
273
+ *
274
+ * ```ts
275
+ * recordLabel: (record) => `${record.name} - ${record.id}`,
276
+ * ```
277
+ *
278
+ */
279
+ recordLabel?: (item: any) => string,
280
+
281
+
282
+ /**
283
+ * General options for resource.
284
+ */
285
+ options?: {
286
+
287
+ /**
288
+ * Default sort for list view.
289
+ * Example:
290
+ *
291
+ * ```ts
292
+ * import { AdminForthSortDirections } from 'adminforth';
293
+ *
294
+ * ...
295
+ *
296
+ * defaultSort: {
297
+ * columnName: 'created_at',
298
+ * direction: AdminForthSortDirections.ASC,
299
+ * }
300
+ * ```
301
+ *
302
+ */
303
+ defaultSort?: {
304
+
305
+ /**
306
+ * Column name which will be used to sort records.
307
+ */
308
+ columnName: string,
309
+
310
+ /**
311
+ * Direction of sorting. Can be 'asc' or 'desc'.
312
+ */
313
+ direction: AdminForthSortDirections | string,
314
+ }
315
+
316
+ /**
317
+ * Custom bulk actions list. Bulk actions available in list view when user selects multiple records by
318
+ * using checkboxes.
319
+ */
320
+ bulkActions?: AdminForthBulkActionCommon[],
321
+
322
+ /**
323
+ * Allowed actions for resource.
324
+ *
325
+ * Example:
326
+ *
327
+ * ```ts
328
+ * allowedActions: {
329
+ * create: ({ resource, adminUser }) => {
330
+ * // Allow only superadmin to create records
331
+ * return adminUser.dbUser.role === 'superadmin';
332
+ * },
333
+ * delete: false, // disable delete action for all users
334
+ * }
335
+ * ```
336
+ *
337
+ */
338
+ allowedActions?: AllowedActionsResolved,
339
+
340
+ /**
341
+ * Allows to make groups of columns in show, create and edit resource pages.
342
+ */
343
+ fieldGroups?: {
344
+ groupName: string;
345
+ columns: string[];
346
+ }[];
347
+ createFieldGroups?: {
348
+ groupName: string;
349
+ columns: string[];
350
+ }[];
351
+ editFieldGroups?: {
352
+ groupName: string;
353
+ columns: string[];
354
+ }[];
355
+ showFieldGroups?: {
356
+ groupName: string;
357
+ columns: string[];
358
+ }[];
359
+
360
+ /**
361
+ * Page size for list view
362
+ */
363
+ listPageSize?: number,
364
+
365
+ /**
366
+ * Callback to define what happens when user clicks on record in list view.
367
+ * By default show view will be opened.
368
+ * If you wish to open custom page, return URL to the custom page (can start with https://, or relative adminforth path)
369
+ * If you wish to open page in new tab, add `target=_blank` get param to returned URL, example:
370
+ *
371
+ * ```ts
372
+ * listTableClickUrl: async (record, adminUser) => {
373
+ * return `https://google.com/search?q=${record.name}&target=_blank`;
374
+ * }
375
+ * ```
376
+ *
377
+ * If you wish to do nothing on click, return null.
378
+ *
379
+ * Example:
380
+ *
381
+ * ```ts
382
+ * listTableClickUrl: async (record, adminUser) => {
383
+ * return null;
384
+ * }
385
+ * ```
386
+ *
387
+ * @param record - record which was clicked
388
+ * @param adminUser - user who clicked
389
+ * @returns
390
+ */
391
+ listTableClickUrl?: (record: any, adminUser: AdminUser) => Promise<string | null>,
392
+
393
+ /**
394
+ * Whether to refresh existing list rows automatically every N seconds.
395
+ */
396
+ listRowsAutoRefreshSeconds?: number,
397
+
398
+ /**
399
+ * Custom components which can be injected into AdminForth CRUD pages.
400
+ * Each injection is a path to a custom component which will be displayed in the admin panel.
401
+ * Can be also array to render multiple injections one after another.
402
+ *
403
+ * Example:
404
+ *
405
+ * ```ts
406
+ * pageInjections: {
407
+ * list: {
408
+ * beforeBreadcrumbs: '@@/Announcement.vue',
409
+ * }
410
+ * }
411
+ * ```
412
+ *
413
+ *
414
+ */
415
+ pageInjections?: {
416
+
417
+
418
+ /**
419
+ * Custom components which can be injected into resource list page.
420
+ *
421
+ * Component accepts next props: [resource, adminUser, meta]
422
+ */
423
+ list?: {
424
+ beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
425
+ afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
426
+ bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
427
+ threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
428
+ customActionIcons?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
429
+ },
430
+
431
+ /**
432
+ * Custom components which can be injected into resource show page.
433
+ *
434
+ * Component accepts next props: [record, resource, adminUser, meta]
435
+ */
436
+ show?: {
437
+ beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
438
+ afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
439
+ bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
440
+ threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
441
+ },
442
+
443
+ /**
444
+ * Custom components which can be injected into resource edit page.
445
+ *
446
+ * Component accepts next props: [record, resource, adminUser, meta]
447
+ */
448
+ edit?: {
449
+ beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
450
+ afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
451
+ bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
452
+ threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
453
+ },
454
+
455
+ /**
456
+ * Custom components which can be injected into resource create page.
457
+ *
458
+ * Component accepts next props: [resource, adminUser, meta]
459
+ */
460
+ create?: {
461
+ beforeBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
462
+ afterBreadcrumbs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
463
+ bottom?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
464
+ threeDotsDropdownItems?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
465
+ },
466
+ }
467
+ },
468
+ }
469
+
470
+ export interface AdminForthResourceCommon extends AdminForthResourceInputCommon {
471
+ resourceId: string,
472
+ label: string,
473
+
474
+ columns: Array<AdminForthResourceColumnCommon>,
475
+ }
476
+
477
+
478
+ export type ValidationObject = {
479
+ /**
480
+ * Should be pure string (not RegExp string)
481
+ *
482
+ * Example:
483
+ *
484
+ * ```ts
485
+ * // regex for email
486
+ * regExp: '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$',
487
+ * ```
488
+ *
489
+ */
490
+ regExp: string,
491
+
492
+ /**
493
+ * Error message shown to user if validation fails
494
+ *
495
+ * Example: "Invalid email format"
496
+ */
497
+ message: string,
498
+
499
+ /**
500
+ * Whether to check case sensitivity (i flag)
501
+ */
502
+ caseSensitive?: boolean,
503
+
504
+ /**
505
+ * Whether to check Multiline strings (m flag)
506
+ */
507
+ multiline?: boolean,
508
+
509
+ /**
510
+ * Whether to check global strings (g flag)
511
+ */
512
+ global?: boolean
513
+ }
514
+
515
+
516
+
517
+ export enum AdminForthResourcePages {
518
+ list = 'list',
519
+ show = 'show',
520
+ edit = 'edit',
521
+ create = 'create',
522
+ filter = 'filter',
523
+
524
+ }
525
+
526
+
527
+ export interface AdminForthForeignResourceCommon {
528
+ resourceId: string,
529
+ }
530
+
531
+ /**
532
+ * Column describes one field in the table or collection in database.
533
+ */
534
+ export interface AdminForthResourceColumnInputCommon {
535
+ /**
536
+ * Column name in database.
537
+ */
538
+ name: string,
539
+
540
+ /**
541
+ * How column can be labled in the admin panel.
542
+ * Use it for renaming columns. Defaulted to column name with Uppercased first letter.
543
+ */
544
+ label?: string,
545
+
546
+ /**
547
+ * Type of data in column.
548
+ * AdminForth will use this information to render proper input fields in the admin panel.
549
+ * AdminForth tries to guess type of data from database column type automatically for typed databases like SQL-based.
550
+ * 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.
551
+ */
552
+ type?: AdminForthDataTypes,
553
+
554
+ /**
555
+ * An optional configuration object for extra settings.
556
+ */
557
+ extra?: {
558
+
559
+ /**
560
+ * How many levels of JSON should be collapsed.
561
+ * `0` means - root level will be already collapsed e.g. `{a:1}` will show `{...}` where `'...'` is clickable
562
+ * `1` means - root level will be shown, but next sub-level will be collapsed e.g. `{a: {b: 1}}` will show `{a: ...}` where `'...'` is clickable
563
+ *
564
+ * Default is 1.
565
+ */
566
+ jsonCollapsedLevel?: number
567
+ }
568
+
569
+ /**
570
+ * Whether to use this column as record identifier.
571
+ * Only one column can be primary key.
572
+ * AdminForth tries to guess primary key automatically first.
573
+ */
574
+ primaryKey?: boolean,
575
+
576
+ /**
577
+ * Whether AdminForth will require this field to be filled in create and edit forms.
578
+ * Can be set to boolean or object with create and edit properties.
579
+ * If boolean, it will be used for both create and edit forms.
580
+ */
581
+ required?: boolean | { create?: boolean, edit?: boolean },
582
+
583
+ /**
584
+ * Whether AdminForth will show editing note near the field in edit/create form.
585
+ */
586
+ editingNote?: string | { create?: string, edit?: string },
587
+
588
+ /**
589
+ * Whether AdminForth will allow to edit this field in editing mode.
590
+ */
591
+ editReadonly?: boolean,
592
+
593
+ /**
594
+ * On which AdminForth pages this field will be shown. By default all.
595
+ * Example: if you want to show field only in create and edit pages, set it to
596
+ *
597
+ * ```ts
598
+ * showIn: [AdminForthResourcePages.CREATE, AdminForthResourcePages.EDIT]
599
+ * ```
600
+ *
601
+ */
602
+ showIn?: Array<AdminForthResourcePages | keyof typeof AdminForthResourcePages>,
603
+
604
+ /**
605
+ * Whether AdminForth will show this field in show view.
606
+ */
607
+ fillOnCreate?: Function,
608
+
609
+ /**
610
+ * Whether AdminForth will request user to enter unique value during creating or editing record.
611
+ * This option causes AdminForth to make a request to database to check if value is unique.
612
+ * (Constraints are not used, so for large-tables performance make sure you have unique index in database if you set this option to true)
613
+ */
614
+ isUnique?: boolean,
615
+
616
+ /**
617
+ * Will automatically convert any capital letters to lowercase in input during editing
618
+ */
619
+ enforceLowerCase?: boolean,
620
+
621
+ /**
622
+ * Runtime validation Regexp rules for this field.
623
+ */
624
+ validation?: Array<ValidationObject>,
625
+
626
+ /**
627
+ * Allows to make the field which does not exist in database table.
628
+ * Examples: add custom show field with user country flag:
629
+ *
630
+ * ```ts
631
+ * {
632
+ * label: 'Country Flag',
633
+ * type: AdminForthDataTypes.STRING,
634
+ * virtual: true,
635
+ * showIn: [AdminForthResourcePages.SHOW, AdminForthResourcePages.LIST],
636
+ * components: {
637
+ * show: '@@/CountryFlag.vue',
638
+ * list: '@@/CountryFlag.vue',
639
+ * },
640
+ * }
641
+ * ```
642
+ *
643
+ * 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:
644
+ *
645
+ * ```html
646
+ * <template>
647
+ * {{ getFlagEmojiFromIso(record.ipCountry) }}
648
+ * </template>
649
+ *
650
+ * <script setup>
651
+ * const props = defineProps(['record']);
652
+ *
653
+ * function getFlagEmojiFromIso(iso) {
654
+ * return iso.toUpperCase().replace(/./g, (char) => String.fromCodePoint(char.charCodeAt(0) + 127397));
655
+ * }
656
+ * </script>
657
+ * ```
658
+ *
659
+ */
660
+ virtual?: boolean,
661
+
662
+ /**
663
+ * Whether AdminForth will show this field in list view.
664
+ */
665
+ allowMinMaxQuery?: boolean,
666
+
667
+ /**
668
+ * Custom components which will be used to render this field in the admin panel.
669
+ */
670
+ components?: AdminForthFieldComponents
671
+
672
+ /**
673
+ * Maximum length of string that can be entered in this field.
674
+ */
675
+ maxLength?: number,
676
+
677
+ /**
678
+ * Minimum length of string that can be entered in this field.
679
+ */
680
+ minLength?: number,
681
+
682
+ min?: number,
683
+ max?: number,
684
+
685
+ /**
686
+ * Minimum value that can be entered in this field.
687
+ */
688
+ minValue?: number,
689
+
690
+ /**
691
+ * Maximum value that can be entered in this field.
692
+ */
693
+ maxValue?: number,
694
+
695
+ /**
696
+ * Enum of possible values for this field.
697
+ */
698
+ enum?: Array<AdminForthColumnEnumItem>,
699
+
700
+ /**
701
+ * Foreign resource which has pk column with values same that written in this column.
702
+ */
703
+ foreignResource?: AdminForthForeignResourceCommon,
704
+
705
+ sortable?: boolean,
706
+
707
+ /**
708
+ * if true field will !not be passed to UI under no circumstances, but will be presented in hooks
709
+ */
710
+ backendOnly?: boolean,
711
+
712
+ /**
713
+ * Masked fields will be displayed as `*****` on Edit and Create pages.
714
+ */
715
+ masked?: boolean,
716
+
717
+ }
718
+
719
+ export interface AdminForthResourceColumnCommon extends AdminForthResourceColumnInputCommon {
720
+
721
+ /**
722
+ * Internal type which indicates original type of column in database.
723
+ */
724
+ _underlineType?: string,
725
+
726
+ required?: { create?: boolean, edit?: boolean },
727
+
728
+ editingNote?: { create?: string, edit?: string },
729
+
730
+ }
731
+
732
+ export enum AdminForthMenuTypes {
733
+ /**
734
+ * HEADING is just a label in the menu.
735
+ * Respect `label` and `icon` property in {@link AdminForthConfigMenuItem}
736
+ */
737
+ heading = 'heading',
738
+
739
+ /**
740
+ * GROUP is a group of menu items.
741
+ * Respects `label`, `icon` and `children` properties in {@link AdminForthConfigMenuItem}
742
+ * use @AdminForthMenuTypes.open to set if group is open by default
743
+ */
744
+ group = 'group',
745
+
746
+ /**
747
+ * RESOURCE is a link to a resource.
748
+ * Respects `label`, `icon`, `resourceId`, `homepage`, `isStaticRoute` properties in {@link AdminForthConfigMenuItem}
749
+ */
750
+ resource = 'resource',
751
+
752
+ /**
753
+ * PAGE is a link to a custom page.
754
+ * Respects `label`, `icon`, `path`, `component`, `homepage`, `isStaticRoute`, properties in {@link AdminForthConfigMenuItem}
755
+ *
756
+ * Example:
757
+ *
758
+ * ```ts
759
+ * \{
760
+ * type: AdminForthMenuTypes.PAGE,
761
+ * label: 'Custom Page',
762
+ * icon: 'home',
763
+ * path: '/dash',
764
+ * component: '@@/Dashboard.vue',
765
+ * homepage: true,
766
+ * \}
767
+ * ```
768
+ *
769
+ */
770
+ page = 'page',
771
+
772
+ /**
773
+ * GAP ads some space between menu items.
774
+ */
775
+ gap = 'gap',
776
+
777
+ /**
778
+ * DIVIDER is a divider between menu items.
779
+ */
780
+ divider = 'divider',
781
+ }
782
+
783
+
784
+ /**
785
+ * Menu item which displayed in the left sidebar of the admin panel.
786
+ */
787
+ export interface AdminForthConfigMenuItem {
788
+ type?: AdminForthMenuTypes | keyof typeof AdminForthMenuTypes,
789
+
790
+ /**
791
+ * Label for menu item which will be displayed in the admin panel.
792
+ */
793
+ label?: string,
794
+
795
+ /**
796
+ * Icon for menu item which will be displayed in the admin panel.
797
+ * Supports iconify icons in format `<icon set name>:<icon name>`
798
+ * Browse available icons here: https://icon-sets.iconify.design/
799
+ *
800
+ * Example:
801
+ *
802
+ * ```ts
803
+ * icon: 'flowbite:brain-solid',
804
+ * ```
805
+ *
806
+ */
807
+ icon?: string,
808
+
809
+ /**
810
+ * Path to custom component which will be displayed in the admin panel.
811
+ *
812
+ */
813
+ path?: string,
814
+
815
+ /**
816
+ * Component to be used for this menu item. Component should be placed in custom folder and referenced with `@@/` prefix.
817
+ * Supported for AdminForthMenuTypes.PAGE only!
818
+ * Example:
819
+ *
820
+ * ```ts
821
+ * component: '@@/Dashboard.vue',
822
+ * ```
823
+ *
824
+ */
825
+ component?: string,
826
+
827
+ /**
828
+ * Resource ID which will be used to fetch data from.
829
+ * Supported for AdminForthMenuTypes.RESOURCE only!
830
+ *
831
+ */
832
+ resourceId?: string,
833
+
834
+ /**
835
+ * If true, group will be open by default after user login to the admin panel.
836
+ * Also will be used to redirect from root path.
837
+ */
838
+ homepage?: boolean,
839
+
840
+ /**
841
+ * Where Group is open by default
842
+ * Supported for AdminForthMenuTypes.GROUP only!
843
+ *
844
+ */
845
+ open?: boolean,
846
+
847
+ /**
848
+ * Children menu items which will be displayed in this group.
849
+ * Supported for AdminForthMenuTypes.GROUP only!
850
+ */
851
+ children?: Array<AdminForthConfigMenuItem>,
852
+
853
+ /**
854
+ * By default all pages are imported dynamically with lazy import().
855
+ * If you wish to import page statically, set this option to true.
856
+ * Homepage will be imported statically by default. but you can override it with this option.
857
+ */
858
+ isStaticRoute?: boolean,
859
+
860
+ meta?: {
861
+ title?: string,
862
+ },
863
+
864
+ /**
865
+ * Optional callback which will be called before rendering the menu for each item.
866
+ * You can use it to hide menu items depending on some user
867
+ */
868
+ visible?: (user: AdminUser) => boolean,
869
+
870
+ /**
871
+ * Optional callback which will be called before rendering the menu for each item.
872
+ * Result of callback if not null will be used as a small badge near the menu item.
873
+ */
874
+ badge?: string | ((user: AdminUser) => Promise<string>),
875
+
876
+ /**
877
+ * Tooltip shown on hover for badge
878
+ */
879
+ badgeTooltip?: string,
880
+
881
+
882
+
883
+ /**
884
+ * Item id will be automatically generated from hashed resourceId+Path+label
885
+ */
886
+ itemId?: string, // todo move to runtime type
887
+ }
888
+
889
+
890
+ export interface ResourceVeryShort {
891
+ resourceId: string,
892
+ label: string,
893
+ }
894
+
895
+ export interface UserData {
896
+ pk: string,
897
+ [key: string]: any,
898
+ }
899
+
900
+ export type AnnouncementBadgeResponse = { text?: string, html?: string, closable?: boolean, title?: string };
901
+
902
+ export interface AdminForthConfigForFrontend {
903
+ brandName: string,
904
+ usernameFieldName: string,
905
+ loginBackgroundImage: string,
906
+ loginBackgroundPosition: string,
907
+ title?: string,
908
+ demoCredentials?: string,
909
+ loginPromptHTML?: string,
910
+ loginPageInjections: {
911
+ underInputs: Array<AdminForthComponentDeclaration>,
912
+ },
913
+ rememberMeDays: number,
914
+ showBrandNameInSidebar: boolean,
915
+ brandLogo?: string,
916
+ datesFormat: string,
917
+ timeFormat: string,
918
+ auth: any,
919
+ userFullnameField: string,
920
+ usernameField: string,
921
+ emptyFieldPlaceholder?: string | {
922
+ show?: string,
923
+ list?: string,
924
+ },
925
+ announcementBadge?: AnnouncementBadgeResponse | null,
926
+ globalInjections: {
927
+ userMenu: Array<AdminForthComponentDeclarationFull>,
928
+ header: Array<AdminForthComponentDeclarationFull>,
929
+ sidebar: Array<AdminForthComponentDeclarationFull>,
930
+ }
931
+ }
932
+
933
+ export interface GetBaseConfigResponse {
934
+ user: UserData,
935
+ resources: ResourceVeryShort[],
936
+ menu: AdminForthConfigMenuItem[],
937
+ config: AdminForthConfigForFrontend,
938
+ adminUser: AdminUser,
939
+ version: string,
940
+ }