nest-my-admin 0.4.1 → 0.5.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.
Files changed (2) hide show
  1. package/README.md +27 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -488,6 +488,33 @@ export class OrderAdmin extends AdminResourceBase<Order> {
488
488
  - **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
489
  - **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
490
 
491
+ ### Printing records
492
+
493
+ 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.
494
+
495
+ ```ts
496
+ import { AdminPrint, html } from '@nest-my-admin/core';
497
+
498
+ @AdminPrint({ label: { en: 'Invoice', fa: 'فاکتور' }, paper: 'A4', bulk: true, icon: 'receipt' })
499
+ invoice(orders: Order[], ctx: AdminContext) {
500
+ return html`${orders.map((order) => html`<section class="nma-print-page"><h1>${order.number}</h1>…</section>`)}`;
501
+ }
502
+ ```
503
+
504
+ - `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.
505
+ - `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.
506
+ - 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).
507
+ - Each printed record is written to the audit log (`{resource}.print.{name}`).
508
+ - API: `GET /api/resources/:resource/print/:name?id=…[&id=…]&lang=fa` answers the HTML page (up to 100 ids with `bulk`, else one).
509
+
510
+ ### Exporting a list to Excel
511
+
512
+ ```ts
513
+ list: ListConfig<Order> = { columns: [...], export: true }; // or { columns: ['number', 'customer', 'total'], max: 50_000 }
514
+ ```
515
+
516
+ «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>`.
517
+
491
518
  ### Settings pages
492
519
 
493
520
  ```ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-my-admin",
3
- "version": "0.4.1",
3
+ "version": "0.5.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.4.1"
32
+ "@nest-my-admin/core": "0.5.0"
33
33
  }
34
34
  }