@grupo-argenta/schema-kit-ng 0.0.22 → 0.0.23
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.
|
@@ -23,7 +23,7 @@ import { InputSelectComponent } from '@schema-kit';
|
|
|
23
23
|
| `items` | `T[]` | `[]` | Lista local |
|
|
24
24
|
| `loadFrom` | `Promise \| Observable<IPaginatedResult<T>> \| SchemaService` | `null` | Fonte dos itens. Tem prioridade sobre `schemaService` |
|
|
25
25
|
| `schemaService` | `SchemaService` | `null` | Busca na API e define `bindLabel`/`bindValue` padrão |
|
|
26
|
-
| `bindLabel` | `keyof T \| (item: T) => string \| TemplateRef`
|
|
26
|
+
| `bindLabel` | `keyof T \| Type<IInputSelectOptionComponent<T>> \| (item: T) => string \| TemplateRef \| Type` | do service | Texto, template ou componente de cada item na lista |
|
|
27
27
|
| `bindValue` | `keyof T \| (item: T) => V` | do service | Valor gravado no form |
|
|
28
28
|
| `lstFilter` | `IIndexFilter[]` | `null` | Filtros enviados ao `index` (só `SchemaService`) |
|
|
29
29
|
| `clearable` | `boolean` | `false` | Botão de limpar |
|
|
@@ -32,6 +32,30 @@ Comuns (`label`, `placeholder`, `loading`, `tooltipInfo`): [input-base](../input
|
|
|
32
32
|
|
|
33
33
|
**Valor:** `V | null`
|
|
34
34
|
|
|
35
|
+
## Componente como label
|
|
36
|
+
|
|
37
|
+
O componente passado em `bindLabel` precisa implementar `IBindLabelComponent`. O mesmo componente vale para a célula
|
|
38
|
+
da tabela, que não passa `index`:
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
export interface IBindLabelComponent<T> {
|
|
42
|
+
item: InputSignal<T>;
|
|
43
|
+
index: InputSignal<number | undefined>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
@Component({ selector: 'produto-option', template: '{{ item().nome }} <small>{{ item().codigo }}</small>' })
|
|
49
|
+
export class ProdutoOptionComponent implements IBindLabelComponent<IProduto> {
|
|
50
|
+
item: InputSignal<IProduto> = input.required<IProduto>();
|
|
51
|
+
index: InputSignal<number | undefined> = input<number>();
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<input-select label="Produto" [schemaService]="produtoService" [bindLabel]="ProdutoOptionComponent" [formField]="form.uuidProduto" />
|
|
57
|
+
```
|
|
58
|
+
|
|
35
59
|
## Atenção
|
|
36
60
|
|
|
37
61
|
- Com `SchemaService`, a busca vai para a API (`index`, 10 itens por página) e as páginas seguintes carregam ao rolar
|
|
@@ -41,3 +65,5 @@ Comuns (`label`, `placeholder`, `loading`, `tooltipInfo`): [input-base](../input
|
|
|
41
65
|
- Valor fora da lista (ex.: ao editar um registro): com `SchemaService` e valor `string`, o item é carregado com `show()`.
|
|
42
66
|
- O valor é comparado com `===`: o tipo tem que bater com o `bindValue` (`1` ≠ `'1'`).
|
|
43
67
|
- Um Observable precisa completar (é lido com `lastValueFrom`).
|
|
68
|
+
- Template ou componente no `bindLabel` aparece na lista e na célula da tabela. O item selecionado usa texto: o
|
|
69
|
+
`simpleBindLabel` do service (com `SchemaService`) ou o `value`.
|
|
@@ -82,8 +82,9 @@ interface SchemaServiceOptions<T> {
|
|
|
82
82
|
schema: SchemaFieldOptionsRecord<T>; // campos (colunas, filtros e o form do schema-view)
|
|
83
83
|
listSchema?: SchemaFieldOptionsRecord<T>; // se informado, define as colunas no lugar de `schema`
|
|
84
84
|
breadcrumbs?: IBreadcrumbItem[]; // substitui o breadcrumb padrão ([{ label: title }])
|
|
85
|
-
bindValue: keyof T | ((value: T) =>
|
|
86
|
-
bindLabel: keyof T | ((value: T) => string | T
|
|
85
|
+
bindValue: keyof T | ((value: T) => unknown);
|
|
86
|
+
bindLabel: keyof T | ((value: T) => string) | TemplateRef<unknown> | Type<IBindLabelComponent<T>>; // texto, template ou componente
|
|
87
|
+
simpleBindLabel?: keyof T | ((value: T) => string); // texto da confirmação de exclusão
|
|
87
88
|
}
|
|
88
89
|
```
|
|
89
90
|
|
|
@@ -265,7 +266,7 @@ O `label` vira o cabeçalho e o `tooltipInfo` mostra um ícone (?) ao lado dele.
|
|
|
265
266
|
| `Icon` | O ícone |
|
|
266
267
|
| `JSON` | Botão que abre um dialog com o JSON formatado e botão de copiar |
|
|
267
268
|
| `File` | Preview e nome de cada arquivo (URL ou lista de URLs) |
|
|
268
|
-
| `Select` com `service` | O `bindLabel` do registro relacionado (ver [Select com service](#select-com-service)) |
|
|
269
|
+
| `Select` com `service` | O `bindLabel` do registro relacionado: texto, template ou componente (ver [Select com service](#select-com-service)) |
|
|
269
270
|
| `Select` com `lstOptions` | **O valor cru** (ex.: `KG`). Use um template para mostrar o label |
|
|
270
271
|
|
|
271
272
|
### Template no schema: `listOptions.template`
|
|
@@ -304,6 +305,29 @@ mostra o valor cru.
|
|
|
304
305
|
{ "lstUuids": ["3f2a…", "9b1c…"], "page": 1, "size": 2 }
|
|
305
306
|
```
|
|
306
307
|
|
|
308
|
+
O `bindLabel`/`bindValue` das `options` do campo têm prioridade sobre os do service. O label é resolvido como no
|
|
309
|
+
input-select: chave e função viram texto; um `TemplateRef` recebe o registro relacionado em `$implicit`; um componente
|
|
310
|
+
recebe ele no input `item`. Na tabela, `index` não é passado.
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
export interface IBindLabelComponent<T> {
|
|
314
|
+
item: InputSignal<T>;
|
|
315
|
+
index: InputSignal<number | undefined>;
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
```ts
|
|
320
|
+
@Component({ selector: 'categoria-label', template: '{{ item().nome }} <small>{{ item().codigo }}</small>' })
|
|
321
|
+
export class CategoriaLabelComponent implements IBindLabelComponent<ICategoria> {
|
|
322
|
+
item: InputSignal<ICategoria> = input.required<ICategoria>();
|
|
323
|
+
index: InputSignal<number | undefined> = input<number>();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// No CategoriaService: aparece assim no select e na coluna `uuidCategoria` da tabela de produtos
|
|
327
|
+
bindLabel: CategoriaLabelComponent,
|
|
328
|
+
simpleBindLabel: 'nome',
|
|
329
|
+
```
|
|
330
|
+
|
|
307
331
|
### Bool editável
|
|
308
332
|
|
|
309
333
|
A célula de um `Bool` é um switch. Ao clicar, a tabela envia `PATCH ${endpoint}/${uuid}` só com aquele campo, mostra um
|
|
@@ -401,7 +425,7 @@ SchemaKitModule.forRoot({
|
|
|
401
425
|
|
|
402
426
|
| Permissão de exclusão | Efeito |
|
|
403
427
|
| --------------------- | ----------------------------------------------------------------------------------- |
|
|
404
|
-
| permitida | Botão de lixeira: confirma com `Deseja realmente excluir "<
|
|
428
|
+
| permitida | Botão de lixeira: confirma com `Deseja realmente excluir "<simpleBindLabel>"?`, envia `DELETE ${endpoint}/${uuid}` e recarrega |
|
|
405
429
|
| negada | Sem botão de excluir |
|
|
406
430
|
|
|
407
431
|
Não há input para desligar editar/excluir: para uma tabela só de leitura, passe uma permissão que o checker nega. Sem
|