@nest-my-admin/core 0.10.4 → 0.10.5
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/README.md
CHANGED
|
@@ -861,7 +861,11 @@ export class OrderAdmin extends AdminResourceBase<Order> {
|
|
|
861
861
|
```
|
|
862
862
|
|
|
863
863
|
- **`inline`**: the child resource class. Its entity needs exactly one many-to-one (or owning one-to-one) relation to the parent's entity: that relation's field is the **link** (`orderId`). With several candidates, name it with `link: 'orderId'`. The server sets the link; a client that sends it is refused (422), and an update cannot change it.
|
|
864
|
-
- **`display`**: `cards` (default; each child is a card with the child's own form layout) or `table` (one row per child, one cell per field: for short rows like order lines; on phones the table scrolls sideways).
|
|
864
|
+
- **`display`**: `cards` (default; each child is a card with the child's own form layout) or `table` (one row per child, one cell per field: for short rows like order lines; on phones the table scrolls sideways), or `gallery` (a product's pictures: one box of thumbnails, one child per picture). A gallery needs `order`, and its picture is the first single-file `image` field in `fields`. Several files can be chosen or dropped at once (a new row each, up to `max`), each thumbnail has × (remove) and ☆ (make it the first by `order`; `cards.markFirst` labels it), thumbnails reorder by dragging, and the other fields of the thumbnail chosen (alt text, a variant) are edited below the box:
|
|
865
|
+
|
|
866
|
+
```ts
|
|
867
|
+
{ section: 'Pictures', inline: ProductPictureAdmin, display: 'gallery', fields: ['path', 'alt'], order: 'sort', max: 40, cards: { markFirst: 'Main picture' } }
|
|
868
|
+
```
|
|
865
869
|
- **`fields`**: which of the child's form fields the inline shows, in order (default: the child's update form fields without the link). Fields it does not show keep their stored values, and their DTO defaults on create.
|
|
866
870
|
- **`order`**: a number field of the child. Rows are read sorted by it (then by key), and dragging or the up/down buttons write 0, 1, 2… into it on save. Without it rows go by key and cannot be reordered.
|
|
867
871
|
- **`min`**, **`max`** (default 100, at most 500): how many rows a save may leave, checked on the server after the changes (422 on the inline). `max` is also how many rows are read: a record with more shows them read-only, with a link to the child's list filtered by the parent.
|
package/dist/contract.d.ts
CHANGED
|
@@ -135,8 +135,13 @@ export interface FormLayoutInline {
|
|
|
135
135
|
inline: string;
|
|
136
136
|
/** The section's title, else the child resource's label. */
|
|
137
137
|
label: string;
|
|
138
|
-
/**
|
|
139
|
-
|
|
138
|
+
/**
|
|
139
|
+
* `cards`: one card per row with the child's fields; `table`: one row per child, one cell per field; `gallery`: one
|
|
140
|
+
* box of thumbnails, one row per picture (several uploaded at once), the other fields of the picture chosen below it.
|
|
141
|
+
*/
|
|
142
|
+
display: 'cards' | 'table' | 'gallery';
|
|
143
|
+
/** `gallery`: the child's image field each row's picture is in. */
|
|
144
|
+
image?: string;
|
|
140
145
|
/** The child's fields the inline shows, in order (never the link field; only fields this user may see). */
|
|
141
146
|
fields: string[];
|
|
142
147
|
/** A number field of the child that orders the rows (written 0, 1, 2… on reorder); without it rows go by key. */
|
|
@@ -14,7 +14,9 @@ export interface RegisteredInline {
|
|
|
14
14
|
relation: RelationMetadataLike;
|
|
15
15
|
/** The parent's property the link holds (the relation's referenced column, normally the primary key). */
|
|
16
16
|
referenced: string;
|
|
17
|
-
display: 'cards' | 'table';
|
|
17
|
+
display: 'cards' | 'table' | 'gallery';
|
|
18
|
+
/** `gallery`: the child's image field each row's picture is in. */
|
|
19
|
+
image?: string;
|
|
18
20
|
/** The child's fields the inline shows, in order (never `link`). */
|
|
19
21
|
fields: string[];
|
|
20
22
|
order?: string;
|
|
@@ -43,6 +43,7 @@ export function toLayoutInline(inline, label, text, childLabel) {
|
|
|
43
43
|
inline: inline.name,
|
|
44
44
|
label: label ?? childLabel,
|
|
45
45
|
display: inline.display,
|
|
46
|
+
...(inline.image !== undefined ? { image: inline.image } : {}),
|
|
46
47
|
fields: [...inline.fields],
|
|
47
48
|
...(inline.order !== undefined ? { order: inline.order } : {}),
|
|
48
49
|
...(inline.min !== undefined ? { min: inline.min } : {}),
|
|
@@ -106,6 +107,11 @@ function resolveInline(entry, node, entries, fail) {
|
|
|
106
107
|
for (const key of node.computed ?? [])
|
|
107
108
|
if (!child.computed.has(key))
|
|
108
109
|
fail(`${where}: computed: "${key}" is not a list.computed column of ${childName}${didYouMean(key, [...child.computed.keys()])}`);
|
|
110
|
+
const fields = node.fields ? [...node.fields] : child.schema.form.update.filter((name) => name !== link);
|
|
111
|
+
// A gallery's picture: the first image field it shows that holds one file (a `many` field is already a gallery).
|
|
112
|
+
const image = node.display === 'gallery' ? fields.find((name) => { const field = fieldOf(name); return field?.widget === 'image' && field.file?.many !== true; }) : undefined;
|
|
113
|
+
if (node.display === 'gallery' && image === undefined)
|
|
114
|
+
fail(`${where}: a gallery shows its rows as pictures: list a single-file image field of ${childName} in fields`);
|
|
109
115
|
const referenced = relation.joinColumns[0].referencedColumn?.propertyName ?? entry.schema.primaryKeys[0];
|
|
110
116
|
return {
|
|
111
117
|
name: child.schema.name,
|
|
@@ -114,7 +120,8 @@ function resolveInline(entry, node, entries, fail) {
|
|
|
114
120
|
relation,
|
|
115
121
|
referenced,
|
|
116
122
|
display: node.display ?? 'cards',
|
|
117
|
-
|
|
123
|
+
...(image !== undefined ? { image } : {}),
|
|
124
|
+
fields,
|
|
118
125
|
...(node.order !== undefined ? { order: node.order } : {}),
|
|
119
126
|
...(node.min !== undefined ? { min: node.min } : {}),
|
|
120
127
|
max: node.max ?? DEFAULT_INLINE_MAX,
|
|
@@ -38,8 +38,13 @@ export interface LayoutInlineConfig {
|
|
|
38
38
|
inline: abstract new (...args: any[]) => AdminResourceBase<any>;
|
|
39
39
|
/** The child's field that points at the parent (`productId`), when there are several candidates. */
|
|
40
40
|
link?: string;
|
|
41
|
-
/**
|
|
42
|
-
|
|
41
|
+
/**
|
|
42
|
+
* `cards` (default): stacked cards with the child's form layout; `table`: one row per child, one cell per field;
|
|
43
|
+
* `gallery`: a product's pictures. One box of thumbnails, one child per picture: several files are uploaded at once
|
|
44
|
+
* (a row each), each has a remove button and «make main» (moves it first by `order`, which a gallery needs), and the
|
|
45
|
+
* other fields of the chosen picture show below. The picture is the first single-file image field of `fields`.
|
|
46
|
+
*/
|
|
47
|
+
display?: 'cards' | 'table' | 'gallery';
|
|
43
48
|
/** Which of the child's form fields the inline shows, in order. Default: its update form fields but the link. */
|
|
44
49
|
fields?: string[];
|
|
45
50
|
/** A number field of the child: rows are read by it (then by key) and reordering writes 0, 1, 2… into it. */
|
|
@@ -375,8 +375,10 @@ function checkInlineShape(node, fail) {
|
|
|
375
375
|
if (typeof node.inline !== 'function')
|
|
376
376
|
fail('form.layout: `inline` must be a resource class (`inline: VariantAdmin`)');
|
|
377
377
|
const where = `form.layout inline ${node.inline.name}`;
|
|
378
|
-
if (node.display !== undefined && node.display !== 'cards' && node.display !== 'table')
|
|
379
|
-
fail(`${where}: display must be "cards" or "
|
|
378
|
+
if (node.display !== undefined && node.display !== 'cards' && node.display !== 'table' && node.display !== 'gallery')
|
|
379
|
+
fail(`${where}: display must be "cards", "table" or "gallery"`);
|
|
380
|
+
if (node.display === 'gallery' && node.order === undefined)
|
|
381
|
+
fail(`${where}: a gallery needs an order field: the main picture is the first by it`);
|
|
380
382
|
const max = node.max ?? DEFAULT_INLINE_MAX;
|
|
381
383
|
if (!Number.isInteger(max) || max < 1 || max > MAX_INLINE_ROWS)
|
|
382
384
|
fail(`${where}: max: must be an integer from 1 to ${MAX_INLINE_ROWS}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-my-admin/core",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"description": "Django-admin-class admin panel for NestJS + TypeORM",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nest-my-admin/ui": "0.10.
|
|
38
|
+
"@nest-my-admin/ui": "0.10.5"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@nestjs/common": "^11.0.0 || ^12.0.0",
|