@zambon-dev/ui 1.2.2 → 1.4.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.
@@ -1,5 +1,20 @@
1
1
  {
2
+ "OperationsHistory-List-ChangedFields": "{{count}} field(s) changed",
3
+ "OperationsHistory-Modal-After": "After",
4
+ "OperationsHistory-Modal-Before": "Before",
5
+ "OperationsHistory-Modal-Changed": "changed",
6
+ "OperationsHistory-Modal-Field": "Field",
7
+ "OperationsHistory-Modal-NoChanges": "This operation changed no fields.",
8
+ "OperationsHistory-Modal-ShowAllFields": "Show all fields",
9
+ "OperationsHistory-Modal-SystemFields": "System fields",
2
10
  "OperationsHistory-Modal-Title": "Object changes details",
11
+ "OperationsHistory-Operation-Added": "Created",
12
+ "OperationsHistory-Operation-Deleted": "Deleted",
13
+ "OperationsHistory-Operation-Modified": "Updated",
14
+ "OperationsHistory-Operation-Unchanged": "Unchanged",
15
+ "OperationsHistory-Value-Empty": "—",
16
+ "OperationsHistory-Value-No": "No",
17
+ "OperationsHistory-Value-Yes": "Yes",
3
18
 
4
19
  "": ""
5
20
  }
@@ -1,5 +1,20 @@
1
1
  {
2
+ "OperationsHistory-List-ChangedFields": "{{count}} campo(s) alterado(s)",
3
+ "OperationsHistory-Modal-After": "Depois",
4
+ "OperationsHistory-Modal-Before": "Antes",
5
+ "OperationsHistory-Modal-Changed": "alterado",
6
+ "OperationsHistory-Modal-Field": "Campo",
7
+ "OperationsHistory-Modal-NoChanges": "Esta operação não alterou nenhum campo.",
8
+ "OperationsHistory-Modal-ShowAllFields": "Mostrar todos os campos",
9
+ "OperationsHistory-Modal-SystemFields": "Campos de sistema",
2
10
  "OperationsHistory-Modal-Title": "Detalhes de alteração do objeto",
11
+ "OperationsHistory-Operation-Added": "Criado",
12
+ "OperationsHistory-Operation-Deleted": "Excluído",
13
+ "OperationsHistory-Operation-Modified": "Alterado",
14
+ "OperationsHistory-Operation-Unchanged": "Sem alteração",
15
+ "OperationsHistory-Value-Empty": "—",
16
+ "OperationsHistory-Value-No": "Não",
17
+ "OperationsHistory-Value-Yes": "Sim",
3
18
 
4
19
  "": ""
5
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zambon-dev/ui",
3
- "version": "1.2.2",
3
+ "version": "1.4.0",
4
4
  "description": "Angular UI components, application framework and shared application layer for Zambon applications.",
5
5
  "keywords": [
6
6
  "angular",
@@ -30,6 +30,73 @@ export declare enum FrameworkViewType {
30
30
  /** A list/grid view (no data provider, no sub-views). */
31
31
  List = "list"
32
32
  }
33
+ /**
34
+ * What a details view's `visibleWhen` and `enabledWhen` conditions receive.
35
+ *
36
+ * A context object rather than positional arguments, so a field can be added later without
37
+ * breaking the conditions already written.
38
+ */
39
+ export interface IDetailsViewContext<TEntity = any> {
40
+ /** The record the details tab shows: `null` while it loads, for a new record, or after a load error. */
41
+ readonly entity: TEntity | null;
42
+ /** The record's ID, or `undefined` for a new record. */
43
+ readonly entityID: number | undefined;
44
+ /** The details route, the parent of every view. */
45
+ readonly route: ActivatedRouteSnapshot;
46
+ }
47
+ /**
48
+ * Decides, per record, whether a details view is shown or available.
49
+ *
50
+ * It runs in an injection context, so it may call `inject()` -- a condition can depend on a
51
+ * feature flag, a setting or the signed-in user, not only on the record. It runs again every time
52
+ * the data provider emits the record, so a save or a status change updates the views at once.
53
+ * Return an `Observable` when the answer comes from somewhere asynchronous; the latest value wins.
54
+ * A condition that throws or errors counts as `false`.
55
+ */
56
+ export type DetailsViewCondition<TEntity = any> = (context: IDetailsViewContext<TEntity>) => boolean | Observable<boolean>;
57
+ /**
58
+ * The route `data` that the framework reads from one view of a details route -- a child route of
59
+ * the route whose `data` holds `[FRAMEWORK_VIEW_TYPE]: FrameworkViewType.Details`.
60
+ *
61
+ * Usage in route config:
62
+ * ```ts
63
+ * children: [
64
+ * { path: '', component: MyFormComponent, data: { icon: 'fa-dice-d6', title: 'Button-Views-Details' } },
65
+ * {
66
+ * path: 'payments',
67
+ * component: MyPaymentsComponent,
68
+ * data: <IDetailsViewRouteData<IMyEntity>>{
69
+ * icon: 'fa-file-invoice-dollar',
70
+ * title: 'My-Button-Views-Payments',
71
+ * visibleWhen: ({ entity }: IDetailsViewContext<IMyEntity>) => entity?.isCustomer === true,
72
+ * },
73
+ * },
74
+ * ],
75
+ * ```
76
+ */
77
+ export interface IDetailsViewRouteData<TEntity = any> {
78
+ /** Actions the user needs for the view to be listed. An empty list asks for none. */
79
+ allowedActions?: string[];
80
+ /** The API controller an audit-history view reads from. */
81
+ controllerName?: string;
82
+ /**
83
+ * When it returns `false`, the view is listed but cannot be chosen. While the first answer is
84
+ * pending the view is unavailable. Ignored on the first view, which every tab lands on.
85
+ */
86
+ enabledWhen?: DetailsViewCondition<TEntity>;
87
+ /** Font Awesome icon class shown beside the view's label. */
88
+ icon?: string;
89
+ /** Leaves the route out of the views menu and the tab history. */
90
+ ignoreRoute?: boolean;
91
+ /** Translation key of the view's label. */
92
+ title?: string;
93
+ /**
94
+ * When it returns `false`, the view is left out of the views menu. While the first answer is
95
+ * pending the view is hidden, so it never appears only to vanish. Ignored on the first view,
96
+ * which every tab lands on.
97
+ */
98
+ visibleWhen?: DetailsViewCondition<TEntity>;
99
+ }
33
100
  export interface ITab {
34
101
  clones: string[];
35
102
  entityBaseUrl?: string;
@@ -631,11 +698,14 @@ export declare class ButtonViewsComponent extends BaseButton implements OnInit {
631
698
  readonly detailsViewRoute: InputSignal<ActivatedRouteSnapshot | null>;
632
699
  private baseUrlPath?;
633
700
  private dataProviderService;
701
+ private hasViewStates;
702
+ private injector;
634
703
  private isInternalNavigation;
635
704
  private router;
636
705
  private readonly selectedViewId;
637
706
  private tabService;
638
707
  private tabViewService;
708
+ private readonly viewStates;
639
709
  protected get hasOptions(): boolean;
640
710
  protected get isNewEntity(): boolean;
641
711
  protected get selectedView(): IRibbonButtonOption | undefined;
@@ -644,13 +714,39 @@ export declare class ButtonViewsComponent extends BaseButton implements OnInit {
644
714
  ngOnInit(): void;
645
715
  protected onViewClicked(selectedOption: string | undefined): void;
646
716
  /**
647
- * Marks the chosen view as the current one, which is how the dropdown greys its own entry out.
717
+ * Writes each view's state into the options: hidden when its `visibleWhen` said no, and
718
+ * disabled when it is the current view or its `enabledWhen` said no.
648
719
  *
649
720
  * The options are rebuilt rather than edited in place: the ribbon button takes the list as an
650
- * input, so a field changed inside it is a change nothing can see.
721
+ * input, so a field changed inside it is a change nothing can see. An option whose state did not
722
+ * change keeps its identity, so the dropdown does not rebuild every row.
723
+ */
724
+ private applyViewStates;
725
+ /**
726
+ * Marks the chosen view as the current one, which is how the dropdown greys its own entry out.
651
727
  */
652
728
  private changeSelectedView;
729
+ /**
730
+ * Runs one condition for one record, as a stream of answers.
731
+ *
732
+ * A condition that throws, errors, or answers anything but `true` counts as `false`: a view whose
733
+ * condition is broken stays out of reach rather than showing where it should not.
734
+ */
735
+ private evaluateCondition;
653
736
  private getActiveOption;
737
+ /**
738
+ * Sends this tab back to its first view when the view it shows has been hidden or disabled --
739
+ * because the record changed under it, or because it was opened by a direct link.
740
+ *
741
+ * Only for the tab the router is showing: a detached tab keeps its subscriptions, and the
742
+ * navigation below always acts on the current tab.
743
+ */
744
+ private leaveUnavailableView;
745
+ /**
746
+ * Answers every conditional view again each time the data provider emits the record, so a save
747
+ * or a status change shows, hides, enables or disables views at once.
748
+ */
749
+ private watchViewConditions;
654
750
  static ɵfac: i0.ɵɵFactoryDeclaration<ButtonViewsComponent, never>;
655
751
  static ɵcmp: i0.ɵɵComponentDeclaration<ButtonViewsComponent, "framework-button-views", never, {
656
752
  "detailsViewRoute": {
@@ -113,17 +113,63 @@ export interface INotification {
113
113
  /** Whether the notification has been read. */
114
114
  isRead: boolean;
115
115
  }
116
+ /** What kind of value an audited field holds, as ZWebAPI reports it. */
117
+ export type OperationsHistoryFieldType = 'boolean' | 'date' | 'enum' | 'key' | 'number' | 'other' | 'text' | 'time';
118
+ /** One field of an audited record, before and after an operation. */
119
+ export interface IOperationsHistoryField {
120
+ /** Whether the operation wrote this field. A creation writes every field, a deletion removes every one. */
121
+ isChanged: boolean;
122
+ /** Bookkeeping rather than data: the key, the audit columns, the concurrency token. */
123
+ isSystem: boolean;
124
+ /** The property name, as the backend declares it (`NomeCompleto`). */
125
+ name: string;
126
+ /** The value after the operation; `null` for a deletion, or when the backend could not rebuild it. */
127
+ newValue?: unknown;
128
+ /** The value before the operation; `null` for a creation, or when the backend could not rebuild it. */
129
+ oldValue?: unknown;
130
+ type: OperationsHistoryFieldType;
131
+ }
116
132
  export interface IOperationsHistoryList {
117
133
  /** Capitalised `ID` is intentional: the backend property is `EntityID`, and the camelCase
118
134
  * serialization policy only lowercases a leading run of capitals — so the trailing ones survive. */
119
135
  entityID?: number;
120
136
  entityName?: string;
137
+ /**
138
+ * Every field of the record, before and after the operation. Sent by ZWebAPI 1.17 and later;
139
+ * without it only the fields the operation wrote are known, from `oldValues` and `newValues`.
140
+ */
141
+ fields?: IOperationsHistoryField[];
121
142
  id: number;
122
143
  newValues?: string;
123
144
  oldValues?: string;
124
145
  operationType?: string;
125
146
  tableName?: string;
126
147
  }
148
+ /**
149
+ * Turns an audited field into the label the audit shows for it.
150
+ *
151
+ * The result goes through the translation pipe, so it may be a translation key. A key with no
152
+ * translation shows as itself, which is why the default returns readable text rather than a key.
153
+ */
154
+ export type OperationsHistoryFieldLabel = (fieldName: string, entityName: string | undefined) => string;
155
+ /**
156
+ * Splits a PascalCase or camelCase property name into words, keeping acronyms whole.
157
+ *
158
+ * @param fieldName The property name.
159
+ * @returns The name as words, with only the first capitalised.
160
+ */
161
+ export declare function humanizeFieldName(fieldName: string): string;
162
+ /**
163
+ * Labels the fields of the audit's change details.
164
+ *
165
+ * The default splits the property name into words: `NomeCompleto` reads "Nome completo" and
166
+ * `CadastroID` reads "Cadastro ID". Provide a function to use the application's own field labels:
167
+ *
168
+ * ```ts
169
+ * { provide: OPERATIONS_HISTORY_FIELD_LABEL, useValue: (field, entity) => `${entity}-Field-${field}` }
170
+ * ```
171
+ */
172
+ export declare const OPERATIONS_HISTORY_FIELD_LABEL: InjectionToken<OperationsHistoryFieldLabel>;
127
173
  export interface IServicesHistoryList {
128
174
  changedByName: string;
129
175
  changedOn: Date;
@@ -397,9 +443,14 @@ export declare class OperationsHistoryChildListComponent extends ChildList<any>
397
443
  [key: string]: string;
398
444
  } | undefined);
399
445
  set serviceID(value: number | undefined);
446
+ /** @deprecated Read `selectedOperation` instead, which also carries the whole record. */
400
447
  readonly selectedNewValues: WritableSignal<any | null>;
448
+ /** @deprecated Read `selectedOperation` instead, which also carries the whole record. */
401
449
  readonly selectedOldValues: WritableSignal<any | null>;
450
+ readonly selectedOperation: WritableSignal<IOperationsHistoryList | null>;
402
451
  ngAfterViewInit(): void;
452
+ /** How many data fields an operation changed, for the summary beside it. */
453
+ protected changedFieldsOf(operation: IOperationsHistoryList): number;
403
454
  openModal(): void;
404
455
  selectedRowChanged(): void;
405
456
  static ɵfac: i0.ɵɵFactoryDeclaration<OperationsHistoryChildListComponent, never>;
@@ -418,12 +469,86 @@ export declare class OperationsHistoryChildListComponent extends ChildList<any>
418
469
  };
419
470
  }, {}, never, never, true, never>;
420
471
  }
472
+ /** A value ready to show: either text as it is, or a translation key. */
473
+ interface IOperationsHistoryValue {
474
+ isKey: boolean;
475
+ text: string;
476
+ }
477
+ /**
478
+ * Every field an operation shows.
479
+ *
480
+ * ZWebAPI 1.17 and later send the whole record, rebuilt from its history. An older backend sends
481
+ * only what the operation wrote, as two JSON objects; those are read as the changed fields, with
482
+ * their kind of value guessed from the value itself.
483
+ *
484
+ * @param operation The operation, or nothing.
485
+ * @returns The fields, in the order the backend declares them.
486
+ */
487
+ declare function getOperationFields(operation: IOperationsHistoryList | null | undefined): IOperationsHistoryField[];
488
+ /**
489
+ * How many data fields an operation changed, leaving bookkeeping out.
490
+ *
491
+ * @param operation The operation.
492
+ * @returns The count.
493
+ */
494
+ declare function countChangedFields(operation: IOperationsHistoryList | null | undefined): number;
495
+ /**
496
+ * Formats a field's value for the user.
497
+ *
498
+ * Dates follow the locale, with the time left out when it is midnight; numbers are grouped;
499
+ * booleans and empty values become translation keys.
500
+ *
501
+ * @param value The value as the backend sent it.
502
+ * @param type What kind of value the field holds.
503
+ * @param locale The locale to format in.
504
+ * @returns The text to show, or the key to translate.
505
+ */
506
+ declare function formatFieldValue(value: unknown, type: OperationsHistoryFieldType, locale: string): IOperationsHistoryValue;
507
+ /** One line of the change details. */
508
+ interface IOperationsHistoryRow {
509
+ isChanged: boolean;
510
+ isSystem: boolean;
511
+ label: string;
512
+ name: string;
513
+ newValue: IOperationsHistoryValue;
514
+ oldValue: IOperationsHistoryValue;
515
+ }
421
516
  export declare class OperationsHistoryModalComponent extends ModalBase {
422
517
  private readonly modal;
423
- readonly newValues: InputSignal<string | undefined>;
424
- readonly oldValues: InputSignal<string | undefined>;
518
+ /**
519
+ * @deprecated Bind `operation` instead, which also carries the whole record. Read only when
520
+ * `operation` is not bound.
521
+ */
522
+ readonly newValues: InputSignal<object | null | undefined>;
523
+ /**
524
+ * @deprecated Bind `operation` instead, which also carries the whole record. Read only when
525
+ * `operation` is not bound.
526
+ */
527
+ readonly oldValues: InputSignal<object | null | undefined>;
528
+ /** The operation whose changes the modal shows. */
529
+ readonly operation: InputSignal<IOperationsHistoryList | null | undefined>;
530
+ /** Whether the unchanged fields are listed too, rather than only what the operation changed. */
531
+ protected readonly showAllFields: WritableSignal<boolean>;
532
+ /** Whether the bookkeeping fields are listed, when every field is. */
533
+ protected readonly showSystemFields: WritableSignal<boolean>;
534
+ private readonly fieldLabel;
535
+ private readonly locale;
425
536
  /** Delegates to the inner modal; a signal query, so it re-runs once that child resolves. */
426
537
  readonly isModalShown: Signal<boolean>;
538
+ /** The operation shown, built from the deprecated inputs when `operation` is not bound. */
539
+ protected readonly currentOperation: Signal<IOperationsHistoryList | null>;
540
+ /** Only a backend that rebuilds the record sends the unchanged fields, so only then can they be listed. */
541
+ protected readonly hasFullRecord: Signal<boolean>;
542
+ protected readonly isAdded: Signal<boolean>;
543
+ protected readonly isDeleted: Signal<boolean>;
544
+ protected readonly operationLabel: Signal<string>;
545
+ /** Data fields: the changed ones, or every one when asked. */
546
+ protected readonly dataRows: Signal<IOperationsHistoryRow[]>;
547
+ /** Bookkeeping fields, listed apart and only when every field is. */
548
+ protected readonly systemRows: Signal<IOperationsHistoryRow[]>;
549
+ private readonly rows;
550
+ protected onShowAllFieldsChanged(event: Event): void;
551
+ protected onSystemFieldsToggled(): void;
427
552
  toggle(): void;
428
553
  static ɵfac: i0.ɵɵFactoryDeclaration<OperationsHistoryModalComponent, never>;
429
554
  static ɵcmp: i0.ɵɵComponentDeclaration<OperationsHistoryModalComponent, "shared-operations-history-modal", never, {
@@ -437,6 +562,11 @@ export declare class OperationsHistoryModalComponent extends ModalBase {
437
562
  "required": false;
438
563
  "isSignal": true;
439
564
  };
565
+ "operation": {
566
+ "alias": "operation";
567
+ "required": false;
568
+ "isSignal": true;
569
+ };
440
570
  }, {}, never, never, true, never>;
441
571
  }
442
572
  export declare class ServicesHistoryChildListComponent extends ChildList<any> implements AfterViewInit, OnInit {