nest-my-admin 0.4.1 → 0.6.0
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 +28 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -479,6 +479,7 @@ export class OrderAdmin extends AdminResourceBase<Order> {
|
|
|
479
479
|
- **Selections.** A bulk action runs on up to 100 records.
|
|
480
480
|
- By default each record gets its own transaction: the answer is `{ ok, failed: [{ id, code, message }], message? }`, and one failure does not stop the others. The list shows how many ran and why the others did not.
|
|
481
481
|
- `atomic: true` runs them all in one transaction: every record is checked first, and one failure is the answer, with nothing applied. It needs the admin's transactions (boot fails with `transactions: false`). The confirmation says "all or nothing".
|
|
482
|
+
- **Picking a record.** `@AdminField({ pickFrom: 'categoryId' })` on an input property shows the same picker as the resource's own relation field `categoryId`; the property receives the chosen id (validate it with `@IsInt()`, and check it exists in the method).
|
|
482
483
|
- **Refusing.** Throw from the method:
|
|
483
484
|
- an `HttpException` below 500 answers with its status and message (409 is `CONFLICT`, 400 is `BUSINESS_RULE`), and the UI shows the message;
|
|
484
485
|
- a 401 from host code is answered as 400, because 401 means signed out to the admin: an action, a settings page's `load`/`save`, or a resource's `create`/`update`/`delete` (and their hooks) that rethrows a provider's `UnauthorizedException` gets a 400 `BUSINESS_RULE` with its message (an `errorMapper` sees that 400, with the original as its `cause`);
|
|
@@ -488,6 +489,33 @@ export class OrderAdmin extends AdminResourceBase<Order> {
|
|
|
488
489
|
- **Files.** An action that hard-deletes a record, or changes a file column itself, does not release the files: the objects and their `nma_file` rows stay. Only the admin's own update, delete and purge do that for now.
|
|
489
490
|
- **API.** `POST /api/resources/:resource/actions/:action` with `{ ids?, input? }`. One distinct id answers `{ message?, record }` (`record` is `null` when the action took it out of the user's view), several answer the bulk result, and a resource action answers `{ message? }`.
|
|
490
491
|
|
|
492
|
+
### Printing records
|
|
493
|
+
|
|
494
|
+
A print template is a resource method that returns the body of a printed page. The record page shows a button per template (the list selection too, with `bulk`); it opens a page in a new tab that is sized for the paper and prints itself. «Save as PDF» in the browser's print dialog is the PDF.
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
import { AdminPrint, html } from '@nest-my-admin/core';
|
|
498
|
+
|
|
499
|
+
@AdminPrint({ label: { en: 'Invoice', fa: 'فاکتور' }, paper: 'A4', bulk: true, icon: 'receipt' })
|
|
500
|
+
invoice(orders: Order[], ctx: AdminContext) {
|
|
501
|
+
return html`${orders.map((order) => html`<section class="nma-print-page"><h1>${order.number}</h1>…</section>`)}`;
|
|
502
|
+
}
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
- `html` escapes every value it puts in; another `html` (or `raw('…')`, for trusted markup only) goes in as it is. Wrap each record in `<section class="nma-print-page">` to start it on a new sheet.
|
|
506
|
+
- `paper`: `A4` (default), `A5`, `label` (100×150 mm) or any CSS `@page` size (`'80mm 200mm'`). The page has a 10 mm margin and the admin's language and direction.
|
|
507
|
+
- Permissions: `{resource}.view`, the user's row scopes and `{resource}.print.{name}`. The method gets whole entities, like an action. Throw an `HttpException` to refuse a record (an unpaid order's label).
|
|
508
|
+
- Each printed record is written to the audit log (`{resource}.print.{name}`).
|
|
509
|
+
- API: `GET /api/resources/:resource/print/:name?id=…[&id=…]&lang=fa` answers the HTML page (up to 100 ids with `bulk`, else one).
|
|
510
|
+
|
|
511
|
+
### Exporting a list to Excel
|
|
512
|
+
|
|
513
|
+
```ts
|
|
514
|
+
list: ListConfig<Order> = { columns: [...], export: true }; // or { columns: ['number', 'customer', 'total'], max: 50_000 }
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
«Export to Excel» on the list downloads the rows the list shows now (filters, search, tab, sort, row scopes) as an `.xlsx`, in `columns` (default: the list's field columns), up to `max` rows (default 10,000, at most 100,000; the UI says when it was cut). Fields the user may not see are left out. Numbers and money are numbers, dates are dates (on the exporter's clock), enums and relations show their labels and titles; the sheet is right to left in an RTL language. It needs `{resource}.export` and is written to the audit log. API: `GET /api/resources/:resource/export?<list query>&offset=<minutes east of UTC>`.
|
|
518
|
+
|
|
491
519
|
### Settings pages
|
|
492
520
|
|
|
493
521
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-my-admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Django-admin-class admin panel for NestJS + TypeORM (the same package as @nest-my-admin/core)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@nest-my-admin/core": "0.
|
|
32
|
+
"@nest-my-admin/core": "0.6.0"
|
|
33
33
|
}
|
|
34
34
|
}
|