@processpuzzle/base-entity 0.2.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 +63 -0
- package/fesm2022/processpuzzle-base-entity.mjs +1025 -0
- package/fesm2022/processpuzzle-base-entity.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/base-entity/base-entity-attr.descriptor.d.ts +43 -0
- package/lib/base-entity/base-entity.d.ts +3 -0
- package/lib/base-entity/base-entity.descriptor.d.ts +7 -0
- package/lib/base-entity-container.component.d.ts +15 -0
- package/lib/base-entity-container.store.d.ts +12 -0
- package/lib/base-entity-load-response.d.ts +7 -0
- package/lib/base-entity.mapper.d.ts +7 -0
- package/lib/base-entity.routes.d.ts +2 -0
- package/lib/base-entity.service.d.ts +25 -0
- package/lib/base-entity.store.d.ts +85 -0
- package/lib/base-form/base-entity-form.component.d.ts +25 -0
- package/lib/base-form/base-form-control.component.d.ts +14 -0
- package/lib/base-form/base-form-host.directive.d.ts +8 -0
- package/lib/base-form/checkbox/checkbox.component.d.ts +7 -0
- package/lib/base-form/datepicker/datepicker.component.d.ts +7 -0
- package/lib/base-form/dropdown/dropdown.component.d.ts +7 -0
- package/lib/base-form/foreign-key/foreign-key.component.d.ts +8 -0
- package/lib/base-form/label/label.component.d.ts +7 -0
- package/lib/base-form/radio/radio.component.d.ts +7 -0
- package/lib/base-form/textarea/textarea.component.d.ts +7 -0
- package/lib/base-form/textbox/textbox.component.d.ts +7 -0
- package/lib/base-form-navigator/base-form-navigator.store.d.ts +33 -0
- package/lib/base-form-navigator/base-url-segments.d.ts +7 -0
- package/lib/base-list/base-entity-list.component.d.ts +38 -0
- package/lib/base-statusbar/base-entity-statusbar.component.d.ts +12 -0
- package/lib/base-tabs/base-entity-tabs.component.d.ts +18 -0
- package/lib/base-tabs/base-entity-tabs.store.d.ts +16 -0
- package/lib/base-toolbar/base-entity-toolbar.component.d.ts +19 -0
- package/package.json +39 -0
- package/public-api.d.ts +16 -0
|
@@ -0,0 +1,1025 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Directive, input, Component, inject, computed, signal, effect, untracked, ViewChild, InjectionToken, Inject } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/forms';
|
|
4
|
+
import { ReactiveFormsModule, FormsModule, FormBuilder, FormControl, Validators } from '@angular/forms';
|
|
5
|
+
import { ROUTER_OUTLET_DATA, Router, ActivatedRoute, RouterOutlet } from '@angular/router';
|
|
6
|
+
import * as i1$1 from '@angular/common';
|
|
7
|
+
import { NgIf, NgStyle, NgClass, NgForOf, CommonModule } from '@angular/common';
|
|
8
|
+
import * as i3$1 from '@angular/material/form-field';
|
|
9
|
+
import { MatFormField, MatLabel, MatFormFieldModule, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
|
|
10
|
+
import * as i4 from '@angular/material/input';
|
|
11
|
+
import { MatInput, MatInputModule } from '@angular/material/input';
|
|
12
|
+
import * as i2 from '@angular/material/select';
|
|
13
|
+
import { MatSelectModule } from '@angular/material/select';
|
|
14
|
+
import * as i3 from '@angular/material/core';
|
|
15
|
+
import { MatCheckbox } from '@angular/material/checkbox';
|
|
16
|
+
import { MatCard, MatCardContent, MatCardActions } from '@angular/material/card';
|
|
17
|
+
import * as i5 from '@angular/material/datepicker';
|
|
18
|
+
import { MatDatepickerModule } from '@angular/material/datepicker';
|
|
19
|
+
import { MatButton } from '@angular/material/button';
|
|
20
|
+
import { MatIcon } from '@angular/material/icon';
|
|
21
|
+
import { MatTableDataSource, MatTable, MatHeaderCell, MatHeaderRow, MatRow, MatCell, MatColumnDef, MatHeaderCellDef, MatCellDef, MatHeaderRowDef, MatRowDef } from '@angular/material/table';
|
|
22
|
+
import { MatSort, MatSortHeader } from '@angular/material/sort';
|
|
23
|
+
import { MatPaginator } from '@angular/material/paginator';
|
|
24
|
+
import { MatProgressBar } from '@angular/material/progress-bar';
|
|
25
|
+
import { SelectionModel } from '@angular/cdk/collections';
|
|
26
|
+
import { signalStoreFeature, withState, withMethods, patchState, withHooks, withComputed } from '@ngrx/signals';
|
|
27
|
+
import { MatTabNav, MatTabLink, MatTabNavPanel } from '@angular/material/tabs';
|
|
28
|
+
import { MatToolbar } from '@angular/material/toolbar';
|
|
29
|
+
import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu';
|
|
30
|
+
import { LayoutService, RUNTIME_CONFIGURATION } from '@processpuzzle/util';
|
|
31
|
+
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
32
|
+
import { __decorate, __param, __metadata } from 'tslib';
|
|
33
|
+
import { map, pipe, tap, switchMap } from 'rxjs';
|
|
34
|
+
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
35
|
+
import buildUrl from 'build-url-ts';
|
|
36
|
+
import { rxMethod } from '@ngrx/signals/rxjs-interop';
|
|
37
|
+
import { tapResponse } from '@ngrx/operators';
|
|
38
|
+
|
|
39
|
+
class BaseFormHostDirective {
|
|
40
|
+
viewContainerRef;
|
|
41
|
+
constructor(viewContainerRef) {
|
|
42
|
+
this.viewContainerRef = viewContainerRef;
|
|
43
|
+
}
|
|
44
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormHostDirective, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
45
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.0.4", type: BaseFormHostDirective, isStandalone: true, selector: "[baseFormHost]", ngImport: i0 });
|
|
46
|
+
}
|
|
47
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormHostDirective, decorators: [{
|
|
48
|
+
type: Directive,
|
|
49
|
+
args: [{
|
|
50
|
+
standalone: true,
|
|
51
|
+
selector: '[baseFormHost]',
|
|
52
|
+
}]
|
|
53
|
+
}], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
|
|
54
|
+
|
|
55
|
+
var FormControlType;
|
|
56
|
+
(function (FormControlType) {
|
|
57
|
+
FormControlType["DATE"] = "DATE";
|
|
58
|
+
FormControlType["LABEL"] = "LABEL";
|
|
59
|
+
FormControlType["TITLE"] = "TITLE";
|
|
60
|
+
FormControlType["TEXT_BOX"] = "TEXT_BOX";
|
|
61
|
+
FormControlType["DROPDOWN"] = "DROPDOWN";
|
|
62
|
+
FormControlType["CHECKBOX"] = "CHECKBOX";
|
|
63
|
+
FormControlType["RADIO"] = "RADIO";
|
|
64
|
+
FormControlType["TEXTAREA"] = "TEXTAREA";
|
|
65
|
+
FormControlType["FOREIGN_KEY"] = "FOREIGN_KEY";
|
|
66
|
+
})(FormControlType || (FormControlType = {}));
|
|
67
|
+
class BaseEntityAttrDescriptor {
|
|
68
|
+
attrName;
|
|
69
|
+
description;
|
|
70
|
+
styleClass = '';
|
|
71
|
+
labelClass = '';
|
|
72
|
+
format;
|
|
73
|
+
isLinkToDetails;
|
|
74
|
+
formControlType;
|
|
75
|
+
selectables;
|
|
76
|
+
visible = true;
|
|
77
|
+
disabled = false;
|
|
78
|
+
isHeading;
|
|
79
|
+
style;
|
|
80
|
+
placeholder;
|
|
81
|
+
lines;
|
|
82
|
+
options;
|
|
83
|
+
_label;
|
|
84
|
+
_linkedEntityType;
|
|
85
|
+
constructor(attrName, formControlType, label, isLinkToDetails, options) {
|
|
86
|
+
this.attrName = attrName;
|
|
87
|
+
this.formControlType = formControlType;
|
|
88
|
+
this._label = label;
|
|
89
|
+
this.isLinkToDetails = isLinkToDetails;
|
|
90
|
+
this.options = { inputType: 'text', ...options };
|
|
91
|
+
}
|
|
92
|
+
// region properties
|
|
93
|
+
get label() {
|
|
94
|
+
return this._label ? this._label : this.attrName;
|
|
95
|
+
}
|
|
96
|
+
set label(label) {
|
|
97
|
+
this._label = label;
|
|
98
|
+
}
|
|
99
|
+
get linkedEntityType() {
|
|
100
|
+
return this._linkedEntityType;
|
|
101
|
+
}
|
|
102
|
+
setLinkedEntityType(linkedEntityType) {
|
|
103
|
+
this._linkedEntityType = linkedEntityType;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
class BaseFormControlComponent {
|
|
108
|
+
config = input.required();
|
|
109
|
+
entity = input.required();
|
|
110
|
+
formGroup;
|
|
111
|
+
store;
|
|
112
|
+
value = input.required();
|
|
113
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormControlComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
114
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: BaseFormControlComponent, isStandalone: true, selector: "ng-component", inputs: { config: { classPropertyName: "config", publicName: "config", isSignal: true, isRequired: true, transformFunction: null }, entity: { classPropertyName: "entity", publicName: "entity", isSignal: true, isRequired: true, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: ``, isInline: true, dependencies: [{ kind: "ngmodule", type: ReactiveFormsModule }] });
|
|
115
|
+
}
|
|
116
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseFormControlComponent, decorators: [{
|
|
117
|
+
type: Component,
|
|
118
|
+
args: [{
|
|
119
|
+
standalone: true,
|
|
120
|
+
template: ``,
|
|
121
|
+
imports: [ReactiveFormsModule],
|
|
122
|
+
}]
|
|
123
|
+
}] });
|
|
124
|
+
|
|
125
|
+
class LabelComponent extends BaseFormControlComponent {
|
|
126
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: LabelComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
127
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: LabelComponent, isStandalone: true, selector: "base-label", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <ng-container *ngIf=\"config().isHeading; else normalText\">\n <h3 [id]=\"config().attrName\">{{value()}}</h3>\n </ng-container>\n\n <ng-template #normalText>\n <p [id]=\"config().attrName\" [ngStyle]=\"config().style\">{{value()}}</p>\n </ng-template>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] });
|
|
128
|
+
}
|
|
129
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: LabelComponent, decorators: [{
|
|
130
|
+
type: Component,
|
|
131
|
+
args: [{ selector: 'base-label', standalone: true, imports: [NgIf, NgStyle], template: "<ng-container *ngIf=\"config().visible\">\n <ng-container *ngIf=\"config().isHeading; else normalText\">\n <h3 [id]=\"config().attrName\">{{value()}}</h3>\n </ng-container>\n\n <ng-template #normalText>\n <p [id]=\"config().attrName\" [ngStyle]=\"config().style\">{{value()}}</p>\n </ng-template>\n</ng-container>" }]
|
|
132
|
+
}] });
|
|
133
|
+
|
|
134
|
+
class TextboxComponent extends BaseFormControlComponent {
|
|
135
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: TextboxComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
136
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: TextboxComponent, isStandalone: true, selector: "base-textbox", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <input matInput formControlName=\"{{config().attrName}}\">\n </mat-form-field>\n </div>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "directive", type: MatLabel, selector: "mat-label" }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
|
|
137
|
+
}
|
|
138
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: TextboxComponent, decorators: [{
|
|
139
|
+
type: Component,
|
|
140
|
+
args: [{ selector: 'base-textbox', standalone: true, imports: [NgIf, MatFormField, MatInput, MatLabel, FormsModule, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <input matInput formControlName=\"{{config().attrName}}\">\n </mat-form-field>\n </div>\n</ng-container>" }]
|
|
141
|
+
}] });
|
|
142
|
+
|
|
143
|
+
class DropdownComponent extends BaseFormControlComponent {
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DropdownComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
145
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.4", type: DropdownComponent, isStandalone: true, selector: "base-dropdown", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <mat-select formControlName=\"{{config().attrName}}\">\n @for (option of config().selectables; track option) {\n <mat-option [value]=\"option.value\">{{option.value}}</mat-option>\n }\n </mat-select>\n </mat-form-field>\n </div>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "directive", type: MatLabel, selector: "mat-label" }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "ngmodule", type: MatSelectModule }, { kind: "component", type: i2.MatSelect, selector: "mat-select", inputs: ["aria-describedby", "panelClass", "disabled", "disableRipple", "tabIndex", "hideSingleSelectionIndicator", "placeholder", "required", "multiple", "disableOptionCentering", "compareWith", "value", "aria-label", "aria-labelledby", "errorStateMatcher", "typeaheadDebounceInterval", "sortComparator", "id", "panelWidth", "canSelectNullableOptions"], outputs: ["openedChange", "opened", "closed", "selectionChange", "valueChange"], exportAs: ["matSelect"] }, { kind: "component", type: i3.MatOption, selector: "mat-option", inputs: ["value", "id", "disabled"], outputs: ["onSelectionChange"], exportAs: ["matOption"] }] });
|
|
146
|
+
}
|
|
147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DropdownComponent, decorators: [{
|
|
148
|
+
type: Component,
|
|
149
|
+
args: [{ selector: 'base-dropdown', standalone: true, imports: [NgIf, ReactiveFormsModule, MatLabel, MatFormField, MatSelectModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <mat-select formControlName=\"{{config().attrName}}\">\n @for (option of config().selectables; track option) {\n <mat-option [value]=\"option.value\">{{option.value}}</mat-option>\n }\n </mat-select>\n </mat-form-field>\n </div>\n</ng-container>" }]
|
|
150
|
+
}] });
|
|
151
|
+
|
|
152
|
+
class CheckboxComponent extends BaseFormControlComponent {
|
|
153
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: CheckboxComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
154
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: CheckboxComponent, isStandalone: true, selector: "base-checkbox", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div [formGroup]=\"formGroup\" class=\"row\">\n <mat-checkbox [ngClass]=\"config().labelClass\" formControlName=\"{{config().attrName}}\">{{config().label}}</mat-checkbox>\n </div>\n</ng-container>", styles: ["mat-checkbox{margin-bottom:12px}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
|
|
155
|
+
}
|
|
156
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: CheckboxComponent, decorators: [{
|
|
157
|
+
type: Component,
|
|
158
|
+
args: [{ selector: 'base-checkbox', standalone: true, imports: [NgClass, NgIf, MatCheckbox, FormsModule, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div [formGroup]=\"formGroup\" class=\"row\">\n <mat-checkbox [ngClass]=\"config().labelClass\" formControlName=\"{{config().attrName}}\">{{config().label}}</mat-checkbox>\n </div>\n</ng-container>", styles: ["mat-checkbox{margin-bottom:12px}\n"] }]
|
|
159
|
+
}] });
|
|
160
|
+
|
|
161
|
+
class RadioComponent extends BaseFormControlComponent {
|
|
162
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: RadioComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
163
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: RadioComponent, isStandalone: true, selector: "base-radio", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <ng-container *ngIf=\"config().label\">\n <label [for]=\"config().attrName\">{{config().label}}</label>\n </ng-container>\n <div \n [ngClass]=\"config().styleClass ? config().styleClass : ''\"\n *ngFor=\"let radio of config().selectables; let i = index\">\n <input type=\"radio\"\n class=\"form-check-input\"\n [name]=\"config().attrName\"\n [id]=\"config().attrName + i\"\n [value]=\"radio.value\"\n [checked]=\"radio.key === value()\"\n [disabled]=\"config().disabled\"\n >\n <label [for]=\"config().attrName\" [ngClass]=\"config().labelClass ? config().labelClass : ''\">{{radio.value}}</label>\n </div>\n </div>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }] });
|
|
164
|
+
}
|
|
165
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: RadioComponent, decorators: [{
|
|
166
|
+
type: Component,
|
|
167
|
+
args: [{ selector: 'base-radio', standalone: true, imports: [NgIf, NgClass, NgForOf, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <ng-container *ngIf=\"config().label\">\n <label [for]=\"config().attrName\">{{config().label}}</label>\n </ng-container>\n <div \n [ngClass]=\"config().styleClass ? config().styleClass : ''\"\n *ngFor=\"let radio of config().selectables; let i = index\">\n <input type=\"radio\"\n class=\"form-check-input\"\n [name]=\"config().attrName\"\n [id]=\"config().attrName + i\"\n [value]=\"radio.value\"\n [checked]=\"radio.key === value()\"\n [disabled]=\"config().disabled\"\n >\n <label [for]=\"config().attrName\" [ngClass]=\"config().labelClass ? config().labelClass : ''\">{{radio.value}}</label>\n </div>\n </div>\n</ng-container>" }]
|
|
168
|
+
}] });
|
|
169
|
+
|
|
170
|
+
class TextareaComponent extends BaseFormControlComponent {
|
|
171
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: TextareaComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
172
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: TextareaComponent, isStandalone: true, selector: "base-textarea", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field [ngClass]=\"config().styleClass\">\n <mat-label [ngClass]=\"config().labelClass\">{{config().label}}</mat-label>\n <textarea matInput formControlName=\"{{config().attrName}}\" placeholder=\"Ex. It makes me feel...\"></textarea>\n </mat-form-field>\n </div>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "directive", type: MatLabel, selector: "mat-label" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
|
|
173
|
+
}
|
|
174
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: TextareaComponent, decorators: [{
|
|
175
|
+
type: Component,
|
|
176
|
+
args: [{ selector: 'base-textarea', standalone: true, imports: [NgIf, NgClass, MatFormField, MatInput, MatLabel, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field [ngClass]=\"config().styleClass\">\n <mat-label [ngClass]=\"config().labelClass\">{{config().label}}</mat-label>\n <textarea matInput formControlName=\"{{config().attrName}}\" placeholder=\"Ex. It makes me feel...\"></textarea>\n </mat-form-field>\n </div>\n</ng-container>" }]
|
|
177
|
+
}] });
|
|
178
|
+
|
|
179
|
+
class DatepickerComponent extends BaseFormControlComponent {
|
|
180
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DatepickerComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
181
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: DatepickerComponent, isStandalone: true, selector: "base-datepicker", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <input matInput [matDatepicker]=\"picker\" formControlName=\"{{config().attrName}}\">\n <mat-hint>MM-DD-YYYY</mat-hint>\n <mat-datepicker-toggle matIconSuffix [for]=\"picker\"></mat-datepicker-toggle>\n <mat-datepicker #picker></mat-datepicker>\n </mat-form-field>\n </div>\n</ng-container>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "ngmodule", type: MatFormFieldModule }, { kind: "component", type: i3$1.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i3$1.MatLabel, selector: "mat-label" }, { kind: "directive", type: i3$1.MatHint, selector: "mat-hint", inputs: ["align", "id"] }, { kind: "directive", type: i3$1.MatSuffix, selector: "[matSuffix], [matIconSuffix], [matTextSuffix]", inputs: ["matTextSuffix"] }, { kind: "ngmodule", type: MatInputModule }, { kind: "directive", type: i4.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "ngmodule", type: MatDatepickerModule }, { kind: "component", type: i5.MatDatepicker, selector: "mat-datepicker", exportAs: ["matDatepicker"] }, { kind: "directive", type: i5.MatDatepickerInput, selector: "input[matDatepicker]", inputs: ["matDatepicker", "min", "max", "matDatepickerFilter"], exportAs: ["matDatepickerInput"] }, { kind: "component", type: i5.MatDatepickerToggle, selector: "mat-datepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["matDatepickerToggle"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
|
|
182
|
+
}
|
|
183
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DatepickerComponent, decorators: [{
|
|
184
|
+
type: Component,
|
|
185
|
+
args: [{ selector: 'base-datepicker', standalone: true, imports: [CommonModule, FormsModule, MatFormFieldModule, MatInputModule, MatDatepickerModule, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{config().label}}</mat-label>\n <input matInput [matDatepicker]=\"picker\" formControlName=\"{{config().attrName}}\">\n <mat-hint>MM-DD-YYYY</mat-hint>\n <mat-datepicker-toggle matIconSuffix [for]=\"picker\"></mat-datepicker-toggle>\n <mat-datepicker #picker></mat-datepicker>\n </mat-form-field>\n </div>\n</ng-container>\n" }]
|
|
186
|
+
}] });
|
|
187
|
+
|
|
188
|
+
var BaseUrlSegments;
|
|
189
|
+
(function (BaseUrlSegments) {
|
|
190
|
+
BaseUrlSegments["DetailsForm"] = "details";
|
|
191
|
+
BaseUrlSegments["Feed"] = "feed";
|
|
192
|
+
BaseUrlSegments["ListForm"] = "list";
|
|
193
|
+
BaseUrlSegments["NewEntity"] = "new";
|
|
194
|
+
BaseUrlSegments["UnknownEntity"] = "unknown";
|
|
195
|
+
})(BaseUrlSegments || (BaseUrlSegments = {}));
|
|
196
|
+
|
|
197
|
+
class ForeignKeyComponent extends BaseFormControlComponent {
|
|
198
|
+
// region event handling methods
|
|
199
|
+
navigateToRelated() {
|
|
200
|
+
this.store.navigateToRelated(this.config().linkedEntityType, this.value());
|
|
201
|
+
}
|
|
202
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: ForeignKeyComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
203
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.0.4", type: ForeignKeyComponent, isStandalone: true, selector: "base-foreign-key", usesInheritance: true, ngImport: i0, template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{ config().attrName }}</mat-label>\n <input matInput formControlName=\"{{config().attrName}}\">\n </mat-form-field>\n <a (click)=\"navigateToRelated()\" aria-label=\"Related entity\">\n <mat-icon>link</mat-icon>\n </a>\n </div>\n</ng-container>", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: MatLabel, selector: "mat-label" }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i1.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }] });
|
|
204
|
+
}
|
|
205
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: ForeignKeyComponent, decorators: [{
|
|
206
|
+
type: Component,
|
|
207
|
+
args: [{ selector: 'base-foreign-key', standalone: true, imports: [NgIf, MatIcon, MatLabel, MatFormField, MatInput, ReactiveFormsModule], template: "<ng-container *ngIf=\"config().visible\">\n <div class=\"row\" [formGroup]=\"formGroup\">\n <mat-form-field>\n <mat-label>{{ config().attrName }}</mat-label>\n <input matInput formControlName=\"{{config().attrName}}\">\n </mat-form-field>\n <a (click)=\"navigateToRelated()\" aria-label=\"Related entity\">\n <mat-icon>link</mat-icon>\n </a>\n </div>\n</ng-container>" }]
|
|
208
|
+
}] });
|
|
209
|
+
|
|
210
|
+
class BaseEntityFormComponent {
|
|
211
|
+
baseEntityForm;
|
|
212
|
+
baseEntityListOptions = inject(ROUTER_OUTLET_DATA);
|
|
213
|
+
entityId = input.required();
|
|
214
|
+
componentHost;
|
|
215
|
+
formBuilder = inject(FormBuilder);
|
|
216
|
+
store = computed(() => this.baseEntityListOptions().store);
|
|
217
|
+
isNewObject = computed(() => this.entityId() === BaseUrlSegments.NewEntity);
|
|
218
|
+
entity = computed(() => (this.isNewObject() ? this.store().createEntity() : this.store().loadById(this.entityId())));
|
|
219
|
+
constructor() {
|
|
220
|
+
this.registerEffects();
|
|
221
|
+
}
|
|
222
|
+
// region angular lifecycle hooks
|
|
223
|
+
ngOnInit() {
|
|
224
|
+
this.store().determineActiveRouteSegment();
|
|
225
|
+
this.baseEntityForm = this.formBuilder.group({});
|
|
226
|
+
}
|
|
227
|
+
// endregion
|
|
228
|
+
// region event handlers
|
|
229
|
+
async onCancel() {
|
|
230
|
+
this.store().setCurrentEntity(undefined);
|
|
231
|
+
await this.store().navigateBack();
|
|
232
|
+
}
|
|
233
|
+
async onSubmit() {
|
|
234
|
+
const objectToSave = { ...this.entity(), ...this.baseEntityForm.value };
|
|
235
|
+
if (this.isNewObject()) {
|
|
236
|
+
this.store().save(objectToSave);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.store().update(objectToSave, objectToSave.id);
|
|
240
|
+
}
|
|
241
|
+
this.store().setCurrentEntity(undefined);
|
|
242
|
+
await this.store().navigateBack();
|
|
243
|
+
}
|
|
244
|
+
// endregion
|
|
245
|
+
// region protected, private helper methods
|
|
246
|
+
buildForm() {
|
|
247
|
+
this.componentHost.viewContainerRef.clear();
|
|
248
|
+
const viewContainerRef = this.componentHost.viewContainerRef;
|
|
249
|
+
this.baseEntityListOptions().columnDescriptors.forEach((column) => {
|
|
250
|
+
const formControlType = this.createFormControl(column);
|
|
251
|
+
const currentAttrValue = Reflect.get(this.entity(), column.attrName);
|
|
252
|
+
if (formControlType) {
|
|
253
|
+
const componentRef = viewContainerRef.createComponent(formControlType);
|
|
254
|
+
componentRef.instance.config = signal(column);
|
|
255
|
+
componentRef.instance.entity = this.entity;
|
|
256
|
+
componentRef.instance.formGroup = this.baseEntityForm;
|
|
257
|
+
componentRef.instance.store = this.store();
|
|
258
|
+
componentRef.instance.value = signal(currentAttrValue);
|
|
259
|
+
const formControl = new FormControl({ value: currentAttrValue, disabled: column.disabled }, Validators.required);
|
|
260
|
+
this.baseEntityForm.addControl(column.attrName, formControl);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
createFormControl(column) {
|
|
265
|
+
if (column.formControlType === FormControlType.LABEL) {
|
|
266
|
+
return LabelComponent;
|
|
267
|
+
}
|
|
268
|
+
else if (column.formControlType === FormControlType.DATE) {
|
|
269
|
+
return DatepickerComponent;
|
|
270
|
+
}
|
|
271
|
+
else if (column.formControlType === FormControlType.FOREIGN_KEY) {
|
|
272
|
+
return ForeignKeyComponent;
|
|
273
|
+
}
|
|
274
|
+
else if (column.formControlType === FormControlType.TEXT_BOX) {
|
|
275
|
+
return TextboxComponent;
|
|
276
|
+
}
|
|
277
|
+
else if (column.formControlType === FormControlType.DROPDOWN) {
|
|
278
|
+
return DropdownComponent;
|
|
279
|
+
}
|
|
280
|
+
else if (column.formControlType === FormControlType.CHECKBOX) {
|
|
281
|
+
return CheckboxComponent;
|
|
282
|
+
}
|
|
283
|
+
else if (column.formControlType === FormControlType.RADIO) {
|
|
284
|
+
return RadioComponent;
|
|
285
|
+
}
|
|
286
|
+
else if (column.formControlType === FormControlType.TEXTAREA) {
|
|
287
|
+
return TextareaComponent;
|
|
288
|
+
}
|
|
289
|
+
else
|
|
290
|
+
throw Error('Undefined form control type');
|
|
291
|
+
}
|
|
292
|
+
registerEffects() {
|
|
293
|
+
effect(() => {
|
|
294
|
+
if (this.entityId() && this.baseEntityListOptions() && this.entity())
|
|
295
|
+
untracked(() => {
|
|
296
|
+
this.buildForm();
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
effect(() => {
|
|
300
|
+
if (this.entity())
|
|
301
|
+
this.store().setCurrentEntity(this.entity().id);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityFormComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
305
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: BaseEntityFormComponent, isStandalone: true, selector: "base-form", inputs: { entityId: { classPropertyName: "entityId", publicName: "entityId", isSignal: true, isRequired: true, transformFunction: null } }, providers: [{ provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: 'outline' } }], viewQueries: [{ propertyName: "componentHost", first: true, predicate: BaseFormHostDirective, descendants: true, read: BaseFormHostDirective, static: true }], ngImport: i0, template: `
|
|
306
|
+
<mat-card appearance="outlined" class="dense-3">
|
|
307
|
+
<mat-card-content>
|
|
308
|
+
<form [formGroup]="baseEntityForm" (ngSubmit)="onSubmit()">
|
|
309
|
+
<ng-template baseFormHost></ng-template>
|
|
310
|
+
</form>
|
|
311
|
+
</mat-card-content>
|
|
312
|
+
<mat-card-actions>
|
|
313
|
+
<button id="cancel" mat-raised-button color="secondary" (click)="onCancel()">Cancel</button>
|
|
314
|
+
<button id="submit" mat-raised-button color="primary" type="submit" [disabled]="baseEntityForm.invalid || !baseEntityForm.dirty" (click)="onSubmit()">Save</button>
|
|
315
|
+
</mat-card-actions>
|
|
316
|
+
</mat-card>
|
|
317
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: BaseFormHostDirective, selector: "[baseFormHost]" }, { kind: "ngmodule", type: ReactiveFormsModule }, { kind: "directive", type: i1.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i1.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i1.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "component", type: MatCard, selector: "mat-card", inputs: ["appearance"], exportAs: ["matCard"] }, { kind: "directive", type: MatCardContent, selector: "mat-card-content" }, { kind: "directive", type: MatCardActions, selector: "mat-card-actions", inputs: ["align"], exportAs: ["matCardActions"] }, { kind: "component", type: MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }] });
|
|
318
|
+
}
|
|
319
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityFormComponent, decorators: [{
|
|
320
|
+
type: Component,
|
|
321
|
+
args: [{
|
|
322
|
+
selector: 'base-form',
|
|
323
|
+
standalone: true,
|
|
324
|
+
template: `
|
|
325
|
+
<mat-card appearance="outlined" class="dense-3">
|
|
326
|
+
<mat-card-content>
|
|
327
|
+
<form [formGroup]="baseEntityForm" (ngSubmit)="onSubmit()">
|
|
328
|
+
<ng-template baseFormHost></ng-template>
|
|
329
|
+
</form>
|
|
330
|
+
</mat-card-content>
|
|
331
|
+
<mat-card-actions>
|
|
332
|
+
<button id="cancel" mat-raised-button color="secondary" (click)="onCancel()">Cancel</button>
|
|
333
|
+
<button id="submit" mat-raised-button color="primary" type="submit" [disabled]="baseEntityForm.invalid || !baseEntityForm.dirty" (click)="onSubmit()">Save</button>
|
|
334
|
+
</mat-card-actions>
|
|
335
|
+
</mat-card>
|
|
336
|
+
`,
|
|
337
|
+
imports: [BaseFormHostDirective, ReactiveFormsModule, MatCard, MatCardContent, MatCardActions, MatButton],
|
|
338
|
+
providers: [{ provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { appearance: 'outline' } }],
|
|
339
|
+
}]
|
|
340
|
+
}], ctorParameters: () => [], propDecorators: { componentHost: [{
|
|
341
|
+
type: ViewChild,
|
|
342
|
+
args: [BaseFormHostDirective, { static: true, read: BaseFormHostDirective }]
|
|
343
|
+
}] } });
|
|
344
|
+
|
|
345
|
+
const BASE_LIST_DESCRIPTORS = new InjectionToken('BASE_TABLE_DISPLAYED_COLUMNS');
|
|
346
|
+
class BaseEntityListComponent {
|
|
347
|
+
dataSource = new MatTableDataSource();
|
|
348
|
+
selection = new SelectionModel(true, []);
|
|
349
|
+
baseEntityListOptions = inject(ROUTER_OUTLET_DATA);
|
|
350
|
+
columnDescriptors = computed(() => this.baseEntityListOptions().columnDescriptors);
|
|
351
|
+
displayedColumns = computed(() => {
|
|
352
|
+
const columns = this.columnDescriptors().map((column) => column.attrName);
|
|
353
|
+
columns.unshift('select');
|
|
354
|
+
return columns;
|
|
355
|
+
});
|
|
356
|
+
sort = {};
|
|
357
|
+
paginator = {};
|
|
358
|
+
store;
|
|
359
|
+
router = inject(Router);
|
|
360
|
+
constructor() {
|
|
361
|
+
this.store = this.baseEntityListOptions().store;
|
|
362
|
+
this.registerEffects();
|
|
363
|
+
}
|
|
364
|
+
// region Angular lifecycle events
|
|
365
|
+
ngAfterViewInit() {
|
|
366
|
+
this.dataSource = this.store?.matTableDataSource();
|
|
367
|
+
this.dataSource.sort = this.sort;
|
|
368
|
+
this.dataSource.paginator = this.paginator;
|
|
369
|
+
this.loadAllData();
|
|
370
|
+
}
|
|
371
|
+
ngOnInit() {
|
|
372
|
+
this.store.determineActiveRouteSegment();
|
|
373
|
+
}
|
|
374
|
+
// endregion
|
|
375
|
+
// region event handling methods
|
|
376
|
+
onChangeSelection(entity) {
|
|
377
|
+
if (entity && this.isSelected(entity))
|
|
378
|
+
this.store.selectEntity(entity.id);
|
|
379
|
+
else
|
|
380
|
+
this.store.deselectEntity(entity);
|
|
381
|
+
if (this.selection.selected.length === 1)
|
|
382
|
+
this.store.setCurrentEntity(this.selection.selected[0].id);
|
|
383
|
+
else
|
|
384
|
+
this.store.clearCurrentEntity();
|
|
385
|
+
}
|
|
386
|
+
onNavigateToDetails(entity) {
|
|
387
|
+
this.store.navigateToDetails(entity.id);
|
|
388
|
+
this.store.setCurrentEntity(entity.id);
|
|
389
|
+
}
|
|
390
|
+
onNavigateToRelated(config, entity) {
|
|
391
|
+
this.store.navigateToRelated(config.linkedEntityType, this.getPropertyValue(entity, config.attrName));
|
|
392
|
+
}
|
|
393
|
+
onRowClick(entity) {
|
|
394
|
+
this.selection.toggle(entity);
|
|
395
|
+
this.onChangeSelection(entity);
|
|
396
|
+
}
|
|
397
|
+
onToggleAllRows() {
|
|
398
|
+
if (this.isAllSelected()) {
|
|
399
|
+
this.cancelSelections();
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
this.dataSource.data.forEach((entity) => {
|
|
403
|
+
this.selection.select(entity);
|
|
404
|
+
this.store.selectEntity(entity.id);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
// endregion
|
|
409
|
+
// region protected, private helper methods
|
|
410
|
+
cancelSelections() {
|
|
411
|
+
this.store.deselectAll();
|
|
412
|
+
this.selection.clear();
|
|
413
|
+
}
|
|
414
|
+
doFilter(filterKey) {
|
|
415
|
+
this.dataSource.filter = filterKey.trim().toLocaleLowerCase();
|
|
416
|
+
}
|
|
417
|
+
getPropertyValue(entity, property) {
|
|
418
|
+
return Reflect.get(entity, property);
|
|
419
|
+
}
|
|
420
|
+
loadAllData() {
|
|
421
|
+
const path = new Map([]);
|
|
422
|
+
const filter = new Map([]);
|
|
423
|
+
this.store.load({ path, filter });
|
|
424
|
+
}
|
|
425
|
+
registerEffects() {
|
|
426
|
+
effect(() => (this.dataSource.data = this.store.entities()));
|
|
427
|
+
effect(() => {
|
|
428
|
+
if (this.store.filterKey())
|
|
429
|
+
this.doFilter(this.store.filterKey());
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
// endregion
|
|
433
|
+
// region properties
|
|
434
|
+
isAllSelected() {
|
|
435
|
+
const numSelected = this.selection.selected.length;
|
|
436
|
+
const numRows = this.dataSource.data.length;
|
|
437
|
+
return numSelected == numRows;
|
|
438
|
+
}
|
|
439
|
+
isSelected(row) {
|
|
440
|
+
return this.selection.isSelected(row);
|
|
441
|
+
}
|
|
442
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
443
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.4", type: BaseEntityListComponent, isStandalone: true, selector: "base-list", viewQueries: [{ propertyName: "sort", first: true, predicate: MatSort, descendants: true }, { propertyName: "paginator", first: true, predicate: MatPaginator, descendants: true }], ngImport: i0, template: "@if (store.isLoading()) {\r\n <mat-progress-bar mode=\"query\"></mat-progress-bar>\r\n}\r\n<table mat-table [dataSource]=\"dataSource\" class=\"mat-elevation-z8 demo-table\" matSort aria-describedby=\"base-entity-list\">\r\n <!-- Checkbox Column -->\r\n <ng-container matColumnDef=\"select\">\r\n <th mat-header-cell *matHeaderCellDef>\r\n <mat-checkbox (change)=\"$event ? onToggleAllRows() : null\" [checked]=\"selection.hasValue() && isAllSelected()\" [indeterminate]=\"selection.hasValue() && !isAllSelected()\"> </mat-checkbox>\r\n </th>\r\n <td mat-cell *matCellDef=\"let row\">\r\n <mat-checkbox (click)=\"$event.stopPropagation()\" (change)=\"$event ? selection.toggle(row) : null; onChangeSelection(row)\" [checked]=\"selection.isSelected(row)\"></mat-checkbox>\r\n </td>\r\n </ng-container>\r\n\r\n <ng-container *ngFor=\"let colDescriptor of columnDescriptors(); index as i\" [matColumnDef]=\"colDescriptor.attrName\">\r\n <th mat-header-cell *matHeaderCellDef mat-sort-header>{{ colDescriptor.label }}</th>\r\n <td (click)=\"onRowClick(element)\" *matCellDef=\"let element\" mat-cell>\r\n @if (colDescriptor.isLinkToDetails === true) {\r\n <a (click)=\"onNavigateToDetails(element)\">{{ element[colDescriptor.attrName] }}</a>\r\n } @else if (colDescriptor.linkedEntityType !== undefined ) {\r\n <a (click)=\"onNavigateToRelated(colDescriptor, element)\">{{ element[colDescriptor.attrName] }}</a>\r\n } @else {\r\n {{ element[colDescriptor.attrName] }}\r\n }\r\n </td>\r\n </ng-container>\r\n <tr mat-header-row *matHeaderRowDef=\"displayedColumns()\"></tr>\r\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns()\"></tr>\r\n</table>\r\n<mat-paginator [pageSizeOptions]=\"[3, 5, 8]\" showFirstLastButtons></mat-paginator>\r\n", styles: [".mat-column-select{overflow:initial}.mat-mdc-row:hover{background-color:#6495ed;cursor:pointer}\n"], dependencies: [{ kind: "component", type: MatTable, selector: "mat-table, table[mat-table]", exportAs: ["matTable"] }, { kind: "directive", type: MatSort, selector: "[matSort]", inputs: ["matSortActive", "matSortStart", "matSortDirection", "matSortDisableClear", "matSortDisabled"], outputs: ["matSortChange"], exportAs: ["matSort"] }, { kind: "directive", type: MatHeaderCell, selector: "mat-header-cell, th[mat-header-cell]" }, { kind: "component", type: MatPaginator, selector: "mat-paginator", inputs: ["color", "pageIndex", "length", "pageSize", "pageSizeOptions", "hidePageSize", "showFirstLastButtons", "selectConfig", "disabled"], outputs: ["page"], exportAs: ["matPaginator"] }, { kind: "component", type: MatHeaderRow, selector: "mat-header-row, tr[mat-header-row]", exportAs: ["matHeaderRow"] }, { kind: "component", type: MatRow, selector: "mat-row, tr[mat-row]", exportAs: ["matRow"] }, { kind: "directive", type: MatCell, selector: "mat-cell, td[mat-cell]" }, { kind: "directive", type: MatColumnDef, selector: "[matColumnDef]", inputs: ["matColumnDef"] }, { kind: "directive", type: NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: MatHeaderCellDef, selector: "[matHeaderCellDef]" }, { kind: "directive", type: MatCellDef, selector: "[matCellDef]" }, { kind: "directive", type: MatHeaderRowDef, selector: "[matHeaderRowDef]", inputs: ["matHeaderRowDef", "matHeaderRowDefSticky"] }, { kind: "directive", type: MatRowDef, selector: "[matRowDef]", inputs: ["matRowDefColumns", "matRowDefWhen"] }, { kind: "component", type: MatSortHeader, selector: "[mat-sort-header]", inputs: ["mat-sort-header", "arrowPosition", "start", "disabled", "sortActionDescription", "disableClear"], exportAs: ["matSortHeader"] }, { kind: "component", type: MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }, { kind: "component", type: MatCheckbox, selector: "mat-checkbox", inputs: ["aria-label", "aria-labelledby", "aria-describedby", "aria-expanded", "aria-controls", "aria-owns", "id", "required", "labelPosition", "name", "value", "disableRipple", "tabIndex", "color", "disabledInteractive", "checked", "disabled", "indeterminate"], outputs: ["change", "indeterminateChange"], exportAs: ["matCheckbox"] }] });
|
|
444
|
+
}
|
|
445
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityListComponent, decorators: [{
|
|
446
|
+
type: Component,
|
|
447
|
+
args: [{ selector: 'base-list', standalone: true, imports: [
|
|
448
|
+
MatTable,
|
|
449
|
+
MatSort,
|
|
450
|
+
MatHeaderCell,
|
|
451
|
+
MatPaginator,
|
|
452
|
+
MatHeaderRow,
|
|
453
|
+
MatRow,
|
|
454
|
+
MatCell,
|
|
455
|
+
MatColumnDef,
|
|
456
|
+
NgForOf,
|
|
457
|
+
MatHeaderCellDef,
|
|
458
|
+
MatCellDef,
|
|
459
|
+
MatHeaderRowDef,
|
|
460
|
+
MatRowDef,
|
|
461
|
+
MatSortHeader,
|
|
462
|
+
MatProgressBar,
|
|
463
|
+
MatCheckbox,
|
|
464
|
+
], template: "@if (store.isLoading()) {\r\n <mat-progress-bar mode=\"query\"></mat-progress-bar>\r\n}\r\n<table mat-table [dataSource]=\"dataSource\" class=\"mat-elevation-z8 demo-table\" matSort aria-describedby=\"base-entity-list\">\r\n <!-- Checkbox Column -->\r\n <ng-container matColumnDef=\"select\">\r\n <th mat-header-cell *matHeaderCellDef>\r\n <mat-checkbox (change)=\"$event ? onToggleAllRows() : null\" [checked]=\"selection.hasValue() && isAllSelected()\" [indeterminate]=\"selection.hasValue() && !isAllSelected()\"> </mat-checkbox>\r\n </th>\r\n <td mat-cell *matCellDef=\"let row\">\r\n <mat-checkbox (click)=\"$event.stopPropagation()\" (change)=\"$event ? selection.toggle(row) : null; onChangeSelection(row)\" [checked]=\"selection.isSelected(row)\"></mat-checkbox>\r\n </td>\r\n </ng-container>\r\n\r\n <ng-container *ngFor=\"let colDescriptor of columnDescriptors(); index as i\" [matColumnDef]=\"colDescriptor.attrName\">\r\n <th mat-header-cell *matHeaderCellDef mat-sort-header>{{ colDescriptor.label }}</th>\r\n <td (click)=\"onRowClick(element)\" *matCellDef=\"let element\" mat-cell>\r\n @if (colDescriptor.isLinkToDetails === true) {\r\n <a (click)=\"onNavigateToDetails(element)\">{{ element[colDescriptor.attrName] }}</a>\r\n } @else if (colDescriptor.linkedEntityType !== undefined ) {\r\n <a (click)=\"onNavigateToRelated(colDescriptor, element)\">{{ element[colDescriptor.attrName] }}</a>\r\n } @else {\r\n {{ element[colDescriptor.attrName] }}\r\n }\r\n </td>\r\n </ng-container>\r\n <tr mat-header-row *matHeaderRowDef=\"displayedColumns()\"></tr>\r\n <tr mat-row *matRowDef=\"let row; columns: displayedColumns()\"></tr>\r\n</table>\r\n<mat-paginator [pageSizeOptions]=\"[3, 5, 8]\" showFirstLastButtons></mat-paginator>\r\n", styles: [".mat-column-select{overflow:initial}.mat-mdc-row:hover{background-color:#6495ed;cursor:pointer}\n"] }]
|
|
465
|
+
}], ctorParameters: () => [], propDecorators: { sort: [{
|
|
466
|
+
type: ViewChild,
|
|
467
|
+
args: [MatSort]
|
|
468
|
+
}], paginator: [{
|
|
469
|
+
type: ViewChild,
|
|
470
|
+
args: [MatPaginator]
|
|
471
|
+
}] } });
|
|
472
|
+
|
|
473
|
+
const BASE_ENTITY_ROUTES = [
|
|
474
|
+
{ path: '', redirectTo: 'list', pathMatch: 'full' },
|
|
475
|
+
{ path: ':id/details', component: BaseEntityFormComponent },
|
|
476
|
+
{ path: 'list', component: BaseEntityListComponent },
|
|
477
|
+
];
|
|
478
|
+
|
|
479
|
+
const INITIAL_CONTAINER_STATE = {
|
|
480
|
+
filterKey: undefined,
|
|
481
|
+
};
|
|
482
|
+
function BaseEntityContainerStore() {
|
|
483
|
+
return signalStoreFeature(withState(INITIAL_CONTAINER_STATE), withMethods((store) => {
|
|
484
|
+
function doFilter(filterKey) {
|
|
485
|
+
patchState(store, { filterKey });
|
|
486
|
+
}
|
|
487
|
+
return { doFilter };
|
|
488
|
+
}));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
var RouteSegments;
|
|
492
|
+
(function (RouteSegments) {
|
|
493
|
+
RouteSegments["LIST_ROUTE"] = "LIST_ROUTE";
|
|
494
|
+
RouteSegments["DETAILS_ROUTE"] = "DETAILS_ROUTE";
|
|
495
|
+
})(RouteSegments || (RouteSegments = {}));
|
|
496
|
+
const INITIAL_NAVIGATION_STATE = {
|
|
497
|
+
activeRouteSegment: RouteSegments.LIST_ROUTE,
|
|
498
|
+
navigateTo: '',
|
|
499
|
+
returnTo: '',
|
|
500
|
+
};
|
|
501
|
+
function entityName(entityType) {
|
|
502
|
+
const entity = new entityType();
|
|
503
|
+
return entity.constructor.name;
|
|
504
|
+
}
|
|
505
|
+
function snakeCaseName(entityType) {
|
|
506
|
+
const nameOfEntity = entityName(entityType);
|
|
507
|
+
return nameOfEntity
|
|
508
|
+
.split(/(?=[A-Z])/)
|
|
509
|
+
.join('-')
|
|
510
|
+
.toLowerCase();
|
|
511
|
+
}
|
|
512
|
+
function BaseFormNavigatorStore(entityType) {
|
|
513
|
+
return signalStoreFeature(withState(INITIAL_NAVIGATION_STATE), withMethods((store, router = inject(Router), route = inject(ActivatedRoute)) => {
|
|
514
|
+
function determineActiveRouteSegment() {
|
|
515
|
+
const currentUrl = Reflect.get(route, '_routerState').snapshot.url;
|
|
516
|
+
if (currentUrl.endsWith(BaseUrlSegments.ListForm)) {
|
|
517
|
+
patchState(store, { activeRouteSegment: RouteSegments.LIST_ROUTE });
|
|
518
|
+
}
|
|
519
|
+
else if (currentUrl.endsWith(BaseUrlSegments.DetailsForm)) {
|
|
520
|
+
patchState(store, { activeRouteSegment: RouteSegments.DETAILS_ROUTE });
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
patchState(store, { activeRouteSegment: undefined });
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
function determineBaseUrl() {
|
|
527
|
+
determineActiveRouteSegment();
|
|
528
|
+
const currentUrl = determineCurrentUrl();
|
|
529
|
+
return store.activeRouteSegment() === RouteSegments.DETAILS_ROUTE ? levelUpUrl(levelUpUrl(levelUpUrl(currentUrl))) : levelUpUrl(levelUpUrl(currentUrl));
|
|
530
|
+
}
|
|
531
|
+
function determineCurrentUrl() {
|
|
532
|
+
return Reflect.get(route, '_routerState').snapshot.url;
|
|
533
|
+
}
|
|
534
|
+
function levelUpUrl(currentUrl) {
|
|
535
|
+
return currentUrl.substring(0, currentUrl.lastIndexOf('/'));
|
|
536
|
+
}
|
|
537
|
+
function navigateBack(defaultUrl) {
|
|
538
|
+
const goTo = store.returnTo() ? store.returnTo() : defaultUrl;
|
|
539
|
+
patchState(store, { returnTo: '' });
|
|
540
|
+
if (goTo) {
|
|
541
|
+
router
|
|
542
|
+
.navigateByUrl(goTo)
|
|
543
|
+
.then()
|
|
544
|
+
.catch((error) => patchState(store, { navigationError: error.message }));
|
|
545
|
+
}
|
|
546
|
+
else
|
|
547
|
+
navigateToList();
|
|
548
|
+
}
|
|
549
|
+
async function navigateToDetails(id, returnTo) {
|
|
550
|
+
if (store.activeRouteSegment() != RouteSegments.DETAILS_ROUTE) {
|
|
551
|
+
const snakeCaseEntityName = snakeCaseName(entityType);
|
|
552
|
+
const baseUrl = determineBaseUrl();
|
|
553
|
+
const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
|
|
554
|
+
await navigateToUrl(detailsFormPath, returnTo);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async function navigateToList(returnTo) {
|
|
558
|
+
const snakeCaseEntityName = snakeCaseName(entityType);
|
|
559
|
+
const baseUrl = determineBaseUrl();
|
|
560
|
+
const goToUrl = baseUrl + '/' + snakeCaseEntityName + '/list';
|
|
561
|
+
if (store.activeRouteSegment() != RouteSegments.LIST_ROUTE) {
|
|
562
|
+
await navigateToUrl(goToUrl, returnTo);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
async function navigateToRelated(relatedType, id, returnTo) {
|
|
566
|
+
const snakeCaseEntityName = snakeCaseName(relatedType);
|
|
567
|
+
const baseUrl = determineBaseUrl();
|
|
568
|
+
const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
|
|
569
|
+
await navigateToUrl(detailsFormPath, returnTo);
|
|
570
|
+
}
|
|
571
|
+
async function navigateToUrl(url, returnTo) {
|
|
572
|
+
if (!returnTo)
|
|
573
|
+
patchState(store, { returnTo: router.url });
|
|
574
|
+
else
|
|
575
|
+
patchState(store, { returnTo });
|
|
576
|
+
patchState(store, { navigateTo: url });
|
|
577
|
+
await router
|
|
578
|
+
.navigateByUrl(url)
|
|
579
|
+
.then(() => determineActiveRouteSegment())
|
|
580
|
+
.catch((error) => patchState(store, { navigationError: error.message }));
|
|
581
|
+
}
|
|
582
|
+
return { determineCurrentUrl, determineActiveRouteSegment, navigateBack, navigateToDetails, navigateToList, navigateToRelated, navigateToUrl };
|
|
583
|
+
}), withHooks((store) => ({
|
|
584
|
+
onInit: () => {
|
|
585
|
+
store.determineActiveRouteSegment();
|
|
586
|
+
},
|
|
587
|
+
})));
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
class BaseEntityToolbarComponent {
|
|
591
|
+
baseEntityListOptions = input.required();
|
|
592
|
+
layoutService = inject(LayoutService);
|
|
593
|
+
store;
|
|
594
|
+
// region Angular lifecycle hooks
|
|
595
|
+
ngOnInit() {
|
|
596
|
+
this.store = this.baseEntityListOptions().store;
|
|
597
|
+
}
|
|
598
|
+
// endregion
|
|
599
|
+
// event handling methods
|
|
600
|
+
onAddEntity() {
|
|
601
|
+
this.store.navigateToDetails(BaseUrlSegments.NewEntity);
|
|
602
|
+
}
|
|
603
|
+
onDeleteEntities() {
|
|
604
|
+
this.store.selectedEntities().forEach((entity) => this.store.delete(entity.id));
|
|
605
|
+
}
|
|
606
|
+
onDoFilter($event) {
|
|
607
|
+
const filterValue = $event.target.value;
|
|
608
|
+
this.store.doFilter(filterValue);
|
|
609
|
+
}
|
|
610
|
+
// endregion
|
|
611
|
+
// public queries and mutators
|
|
612
|
+
isSmallDevice() {
|
|
613
|
+
return this.layoutService.isSmallDevice();
|
|
614
|
+
}
|
|
615
|
+
// endregion
|
|
616
|
+
// protected, private helper methods
|
|
617
|
+
RouteSegments = RouteSegments;
|
|
618
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityToolbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
619
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.0.4", type: BaseEntityToolbarComponent, isStandalone: true, selector: "base-entity-toolbar", inputs: { baseEntityListOptions: { classPropertyName: "baseEntityListOptions", publicName: "baseEntityListOptions", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<mat-toolbar *ngIf=\"store.activeRouteSegment() === RouteSegments.LIST_ROUTE\">\n <div class=\"dense-3\" [ngStyle]=\"{'padding-top': '12px' }\">\n <mat-form-field>\n <input test-id=\"filter-input\" matInput type=\"text\" (keyup)=\"onDoFilter( $event )\" placeholder=\"Filter\">\n </mat-form-field>\n </div>\n <span class=\"toolbar-spacer\"></span>\n @if(isSmallDevice()) {\n <div [ngClass]=\"layoutService.layoutClass()\">\n <button test-id=\"menu-button\" mat-button [matMenuTriggerFor]=\"beforeMenu\"><mat-icon>menu</mat-icon> Choose action</button>\n <mat-menu test-id=\"menu\" #beforeMenu=\"matMenu\" xPosition=\"before\">\n <button test-id=\"add\" mat-menu-item (click)=\"onAddEntity()\"><mat-icon>add</mat-icon> New</button>\n <button test-id=\"delete\" mat-menu-item [disabled]=\"store.selectedEntities().length === 0\" (click)=\"onDeleteEntities()\"><mat-icon>delete</mat-icon> Delete</button>\n </mat-menu>\n </div>\n } @else {\n <div [ngClass]=\"layoutService.layoutClass()\">\n <button test-id=\"add\" mat-button (click)=\"onAddEntity()\"><mat-icon>add</mat-icon> New</button>\n <button test-id=\"delete\" mat-button [disabled]=\"store.selectedEntities().length === 0\" (click)=\"onDeleteEntities()\"><mat-icon>delete</mat-icon> Delete</button>\n </div>\n }\n</mat-toolbar>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1$1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: MatToolbar, selector: "mat-toolbar", inputs: ["color"], exportAs: ["matToolbar"] }, { kind: "component", type: MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl], input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly", "disabledInteractive"], exportAs: ["matInput"] }, { kind: "component", type: MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }, { kind: "component", type: MatMenu, selector: "mat-menu", inputs: ["backdropClass", "aria-label", "aria-labelledby", "aria-describedby", "xPosition", "yPosition", "overlapTrigger", "hasBackdrop", "class", "classList"], outputs: ["closed", "close"], exportAs: ["matMenu"] }, { kind: "component", type: MatMenuItem, selector: "[mat-menu-item]", inputs: ["role", "disabled", "disableRipple"], exportAs: ["matMenuItem"] }, { kind: "directive", type: MatMenuTrigger, selector: "[mat-menu-trigger-for], [matMenuTriggerFor]", inputs: ["mat-menu-trigger-for", "matMenuTriggerFor", "matMenuTriggerData", "matMenuTriggerRestoreFocus"], outputs: ["menuOpened", "onMenuOpen", "menuClosed", "onMenuClose"], exportAs: ["matMenuTrigger"] }] });
|
|
620
|
+
}
|
|
621
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityToolbarComponent, decorators: [{
|
|
622
|
+
type: Component,
|
|
623
|
+
args: [{ selector: 'base-entity-toolbar', standalone: true, imports: [CommonModule, MatToolbar, MatIcon, MatFormField, MatInput, MatButton, MatMenu, MatMenuItem, MatMenuTrigger], template: "<mat-toolbar *ngIf=\"store.activeRouteSegment() === RouteSegments.LIST_ROUTE\">\n <div class=\"dense-3\" [ngStyle]=\"{'padding-top': '12px' }\">\n <mat-form-field>\n <input test-id=\"filter-input\" matInput type=\"text\" (keyup)=\"onDoFilter( $event )\" placeholder=\"Filter\">\n </mat-form-field>\n </div>\n <span class=\"toolbar-spacer\"></span>\n @if(isSmallDevice()) {\n <div [ngClass]=\"layoutService.layoutClass()\">\n <button test-id=\"menu-button\" mat-button [matMenuTriggerFor]=\"beforeMenu\"><mat-icon>menu</mat-icon> Choose action</button>\n <mat-menu test-id=\"menu\" #beforeMenu=\"matMenu\" xPosition=\"before\">\n <button test-id=\"add\" mat-menu-item (click)=\"onAddEntity()\"><mat-icon>add</mat-icon> New</button>\n <button test-id=\"delete\" mat-menu-item [disabled]=\"store.selectedEntities().length === 0\" (click)=\"onDeleteEntities()\"><mat-icon>delete</mat-icon> Delete</button>\n </mat-menu>\n </div>\n } @else {\n <div [ngClass]=\"layoutService.layoutClass()\">\n <button test-id=\"add\" mat-button (click)=\"onAddEntity()\"><mat-icon>add</mat-icon> New</button>\n <button test-id=\"delete\" mat-button [disabled]=\"store.selectedEntities().length === 0\" (click)=\"onDeleteEntities()\"><mat-icon>delete</mat-icon> Delete</button>\n </div>\n }\n</mat-toolbar>" }]
|
|
624
|
+
}] });
|
|
625
|
+
|
|
626
|
+
class BaseEntityStatusbarComponent {
|
|
627
|
+
store;
|
|
628
|
+
baseEntityListOptions = input.required();
|
|
629
|
+
entityTitle = computed(() => eval(this.baseEntityListOptions().entityTitle));
|
|
630
|
+
isVisible = computed(() => this.store.currentEntity() != undefined || this.store.selectedEntities().length == 1);
|
|
631
|
+
// region Angular lifecycle hooks
|
|
632
|
+
ngOnInit() {
|
|
633
|
+
this.store = this.baseEntityListOptions().store;
|
|
634
|
+
}
|
|
635
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityStatusbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
636
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: BaseEntityStatusbarComponent, isStandalone: true, selector: "base-entity-statusbar", inputs: { baseEntityListOptions: { classPropertyName: "baseEntityListOptions", publicName: "baseEntityListOptions", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<mat-toolbar *ngIf=\"isVisible()\">\n <div>\n <span>{{entityTitle()}}</span>\n </div>\n</mat-toolbar>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: MatToolbar, selector: "mat-toolbar", inputs: ["color"], exportAs: ["matToolbar"] }] });
|
|
637
|
+
}
|
|
638
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityStatusbarComponent, decorators: [{
|
|
639
|
+
type: Component,
|
|
640
|
+
args: [{ selector: 'base-entity-statusbar', standalone: true, imports: [CommonModule, MatToolbar], template: "<mat-toolbar *ngIf=\"isVisible()\">\n <div>\n <span>{{entityTitle()}}</span>\n </div>\n</mat-toolbar>" }]
|
|
641
|
+
}] });
|
|
642
|
+
|
|
643
|
+
class BaseEntityTabsComponent {
|
|
644
|
+
store;
|
|
645
|
+
baseEntityListOptions = input.required();
|
|
646
|
+
selectedEntityId = computed(() => (this.store.currentId() ? this.store.currentId() : BaseUrlSegments.NewEntity));
|
|
647
|
+
detailsTabName = computed(() => this.baseEntityListOptions().entityName + ' - details');
|
|
648
|
+
listTabName = computed(() => this.baseEntityListOptions().entityName + ' - list');
|
|
649
|
+
constructor() {
|
|
650
|
+
this.registerEffects();
|
|
651
|
+
}
|
|
652
|
+
// region angular lifecycle hooks
|
|
653
|
+
ngOnDestroy() {
|
|
654
|
+
this.store.tabIsInactive(this.listTabName());
|
|
655
|
+
this.store.tabIsInactive(this.detailsTabName());
|
|
656
|
+
}
|
|
657
|
+
ngOnInit() {
|
|
658
|
+
this.store = this.baseEntityListOptions().store;
|
|
659
|
+
}
|
|
660
|
+
// endregion
|
|
661
|
+
// region event handlers
|
|
662
|
+
async onShowDetails() {
|
|
663
|
+
if (this.store.activeRouteSegment() != RouteSegments.DETAILS_ROUTE) {
|
|
664
|
+
const id = this.selectedEntityId() ? this.selectedEntityId() : BaseUrlSegments.NewEntity;
|
|
665
|
+
await this.store.navigateToDetails(id);
|
|
666
|
+
this.store.tabIsActive(this.detailsTabName());
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
async onShowList() {
|
|
670
|
+
if (this.store.activeRouteSegment() != RouteSegments.LIST_ROUTE) {
|
|
671
|
+
await this.store.navigateToList(this.baseEntityListOptions().entityName);
|
|
672
|
+
this.store.tabIsActive(this.listTabName());
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// endregion
|
|
676
|
+
// region protected, private helper methods
|
|
677
|
+
registerEffects() {
|
|
678
|
+
effect(() => {
|
|
679
|
+
if (this.store.activeRouteSegment() === RouteSegments.DETAILS_ROUTE) {
|
|
680
|
+
this.store.tabIsActive(this.detailsTabName());
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
this.store.tabIsActive(this.listTabName());
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityTabsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
688
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: BaseEntityTabsComponent, isStandalone: true, selector: "base-entity-tabs", inputs: { baseEntityListOptions: { classPropertyName: "baseEntityListOptions", publicName: "baseEntityListOptions", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: "<nav mat-tab-nav-bar [tabPanel]=\"tabPanel\">\n <a mat-tab-link (click)=\"onShowList()\" [active]=\"store.currentTab() === listTabName()\">{{listTabName()}}</a>\n <a mat-tab-link [disabled]=\"store.currentEntity() === undefined\" (click)=\"onShowDetails()\" [active]=\"store.currentTab() === detailsTabName()\">{{detailsTabName()}}</a>\n</nav>\n\n<mat-tab-nav-panel #tabPanel>\n <base-entity-statusbar [baseEntityListOptions]=\"baseEntityListOptions()\"/>\n <base-entity-toolbar [baseEntityListOptions]=\"baseEntityListOptions()\"/>\n <router-outlet [routerOutletData]=\"baseEntityListOptions()\"/>\n</mat-tab-nav-panel>", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: MatTabNav, selector: "[mat-tab-nav-bar]", inputs: ["fitInkBarToContent", "mat-stretch-tabs", "animationDuration", "backgroundColor", "disableRipple", "color", "tabPanel"], exportAs: ["matTabNavBar", "matTabNav"] }, { kind: "component", type: MatTabLink, selector: "[mat-tab-link], [matTabLink]", inputs: ["active", "disabled", "disableRipple", "tabIndex", "id"], exportAs: ["matTabLink"] }, { kind: "component", type: MatTabNavPanel, selector: "mat-tab-nav-panel", inputs: ["id"], exportAs: ["matTabNavPanel"] }, { kind: "directive", type: RouterOutlet, selector: "router-outlet", inputs: ["name", "routerOutletData"], outputs: ["activate", "deactivate", "attach", "detach"], exportAs: ["outlet"] }, { kind: "component", type: BaseEntityToolbarComponent, selector: "base-entity-toolbar", inputs: ["baseEntityListOptions"] }, { kind: "component", type: BaseEntityStatusbarComponent, selector: "base-entity-statusbar", inputs: ["baseEntityListOptions"] }] });
|
|
689
|
+
}
|
|
690
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityTabsComponent, decorators: [{
|
|
691
|
+
type: Component,
|
|
692
|
+
args: [{ selector: 'base-entity-tabs', standalone: true, imports: [CommonModule, MatTabNav, MatTabLink, MatTabNavPanel, RouterOutlet, BaseEntityToolbarComponent, BaseEntityStatusbarComponent], template: "<nav mat-tab-nav-bar [tabPanel]=\"tabPanel\">\n <a mat-tab-link (click)=\"onShowList()\" [active]=\"store.currentTab() === listTabName()\">{{listTabName()}}</a>\n <a mat-tab-link [disabled]=\"store.currentEntity() === undefined\" (click)=\"onShowDetails()\" [active]=\"store.currentTab() === detailsTabName()\">{{detailsTabName()}}</a>\n</nav>\n\n<mat-tab-nav-panel #tabPanel>\n <base-entity-statusbar [baseEntityListOptions]=\"baseEntityListOptions()\"/>\n <base-entity-toolbar [baseEntityListOptions]=\"baseEntityListOptions()\"/>\n <router-outlet [routerOutletData]=\"baseEntityListOptions()\"/>\n</mat-tab-nav-panel>" }]
|
|
693
|
+
}], ctorParameters: () => [] });
|
|
694
|
+
|
|
695
|
+
class BaseEntityContainerComponent {
|
|
696
|
+
baseEntityListOptions = input.required();
|
|
697
|
+
snackBar = inject(MatSnackBar);
|
|
698
|
+
store;
|
|
699
|
+
constructor() {
|
|
700
|
+
this.registerEffects();
|
|
701
|
+
}
|
|
702
|
+
// region Angular lifecycle hooks
|
|
703
|
+
ngOnDestroy() {
|
|
704
|
+
this.store.reset();
|
|
705
|
+
}
|
|
706
|
+
ngOnInit() {
|
|
707
|
+
this.store = this.baseEntityListOptions().store;
|
|
708
|
+
}
|
|
709
|
+
// endregion
|
|
710
|
+
// region protected, private helper methods
|
|
711
|
+
registerEffects() {
|
|
712
|
+
effect(() => {
|
|
713
|
+
if (this.store.error()) {
|
|
714
|
+
const errorMessage = this.store.error() ? this.store.error() : 'Undefined Error';
|
|
715
|
+
this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
720
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: BaseEntityContainerComponent, isStandalone: true, selector: "base-entity-container", inputs: { baseEntityListOptions: { classPropertyName: "baseEntityListOptions", publicName: "baseEntityListOptions", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `
|
|
721
|
+
<div>
|
|
722
|
+
<base-entity-tabs [baseEntityListOptions]="baseEntityListOptions()"></base-entity-tabs>
|
|
723
|
+
</div>
|
|
724
|
+
`, isInline: true, styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: BaseEntityTabsComponent, selector: "base-entity-tabs", inputs: ["baseEntityListOptions"] }] });
|
|
725
|
+
}
|
|
726
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: BaseEntityContainerComponent, decorators: [{
|
|
727
|
+
type: Component,
|
|
728
|
+
args: [{ selector: 'base-entity-container', standalone: true, imports: [CommonModule, BaseEntityTabsComponent], template: `
|
|
729
|
+
<div>
|
|
730
|
+
<base-entity-tabs [baseEntityListOptions]="baseEntityListOptions()"></base-entity-tabs>
|
|
731
|
+
</div>
|
|
732
|
+
` }]
|
|
733
|
+
}], ctorParameters: () => [] });
|
|
734
|
+
|
|
735
|
+
const BASE_ENTITY_SERVICE = new InjectionToken('BASE_ENTITY_SERVICE');
|
|
736
|
+
let BaseEntityService = class BaseEntityService {
|
|
737
|
+
entityMapper;
|
|
738
|
+
urlProperty;
|
|
739
|
+
resourceUrl;
|
|
740
|
+
runtimeConfiguration = inject(RUNTIME_CONFIGURATION);
|
|
741
|
+
baseUrl;
|
|
742
|
+
httpClient = inject(HttpClient);
|
|
743
|
+
headers = new HttpHeaders({
|
|
744
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
745
|
+
'Access-Control-Allow-Methods': 'GET, HEAD, PUT, PATCH, POST, DELETE',
|
|
746
|
+
'Access-Control-Allow-Origin-Credentials': 'true',
|
|
747
|
+
'Access-Control-Allow-Headers': 'Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, X-BRZ-User-ID',
|
|
748
|
+
'X-BRZ-User-ID': 'zsolt.zsuffa@extern.brz.gv.at',
|
|
749
|
+
});
|
|
750
|
+
constructor(entityMapper, urlProperty, resourceUrl) {
|
|
751
|
+
this.entityMapper = entityMapper;
|
|
752
|
+
this.urlProperty = urlProperty;
|
|
753
|
+
this.resourceUrl = resourceUrl;
|
|
754
|
+
this.baseUrl = Reflect.get(this.runtimeConfiguration, urlProperty);
|
|
755
|
+
}
|
|
756
|
+
// region public accessor and mutator methods
|
|
757
|
+
delete(id) {
|
|
758
|
+
return this.httpClient.delete(this.resourceUrl + `/${id}`, { headers: this.headers });
|
|
759
|
+
}
|
|
760
|
+
deleteAll() {
|
|
761
|
+
return this.httpClient.delete(this.resourceUrl, { headers: this.headers });
|
|
762
|
+
}
|
|
763
|
+
findAll(path, filter, page) {
|
|
764
|
+
const fullUrl = this.buildFullUrl(this.resourceUrl, path, filter, page);
|
|
765
|
+
if (fullUrl) {
|
|
766
|
+
return this.httpClient.get(fullUrl, { headers: this.headers }).pipe(map((httpResponse) => {
|
|
767
|
+
return page ? this.mapPagedResponse(httpResponse) : this.mapSimpleResponse(httpResponse);
|
|
768
|
+
}));
|
|
769
|
+
}
|
|
770
|
+
else
|
|
771
|
+
throw new Error('Could not determine the full url');
|
|
772
|
+
}
|
|
773
|
+
save(entity, id) {
|
|
774
|
+
const dto = this.entityMapper.toDto(entity);
|
|
775
|
+
const fullUrl = this.buildFullUrl(this.resourceUrl);
|
|
776
|
+
if (fullUrl) {
|
|
777
|
+
return this.httpClient.post(fullUrl, dto, { headers: this.headers }).pipe(map((response) => {
|
|
778
|
+
return this.entityMapper.fromDto(response, id);
|
|
779
|
+
}));
|
|
780
|
+
}
|
|
781
|
+
else
|
|
782
|
+
throw new Error('Could not determine the full url');
|
|
783
|
+
}
|
|
784
|
+
update(entity) {
|
|
785
|
+
const dto = this.entityMapper.toDto(entity);
|
|
786
|
+
const path = new Map([['id', String(entity.id)]]);
|
|
787
|
+
const filter = new Map([]);
|
|
788
|
+
const fullUrl = this.buildFullUrl(this.resourceUrl + '/%{id}', path, filter);
|
|
789
|
+
if (fullUrl) {
|
|
790
|
+
return this.httpClient.put(fullUrl, dto, { headers: this.headers }).pipe(map((response) => {
|
|
791
|
+
return this.entityMapper.fromDto(response);
|
|
792
|
+
}));
|
|
793
|
+
}
|
|
794
|
+
else
|
|
795
|
+
throw new Error('Could not determine the full url');
|
|
796
|
+
}
|
|
797
|
+
// endregion
|
|
798
|
+
// region protected, private helper methods
|
|
799
|
+
buildFullUrl(resourceUri, path, filter, page, hash) {
|
|
800
|
+
const pageParam = new Map(page ? [['page', page.toString()]] : []);
|
|
801
|
+
let queryParams;
|
|
802
|
+
if (filter !== undefined && filter.size != 0) {
|
|
803
|
+
queryParams = new Map([...Array.from(pageParam), ...Array.from(filter.entries())]);
|
|
804
|
+
}
|
|
805
|
+
else {
|
|
806
|
+
queryParams = new Map([...Array.from(pageParam)]);
|
|
807
|
+
}
|
|
808
|
+
let params = {};
|
|
809
|
+
if (queryParams.size > 0) {
|
|
810
|
+
for (const [key, value] of queryParams) {
|
|
811
|
+
params = { ...params, [key]: value };
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
else
|
|
815
|
+
params = null;
|
|
816
|
+
if (path !== undefined && path.size != 0) {
|
|
817
|
+
path.forEach((value, key) => {
|
|
818
|
+
const pathParam = '%{' + key + '}';
|
|
819
|
+
resourceUri = resourceUri.replace(pathParam, value);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
const urlOptions = {
|
|
823
|
+
path: resourceUri,
|
|
824
|
+
hash: hash,
|
|
825
|
+
queryParams: params,
|
|
826
|
+
};
|
|
827
|
+
return buildUrl(this.baseUrl, urlOptions);
|
|
828
|
+
}
|
|
829
|
+
mapPagedResponse(response) {
|
|
830
|
+
const subjectPage = response[0];
|
|
831
|
+
const content = subjectPage.content.map((dto, index) => {
|
|
832
|
+
return this.entityMapper.fromDto(dto, index);
|
|
833
|
+
});
|
|
834
|
+
return {
|
|
835
|
+
page: subjectPage.page,
|
|
836
|
+
pageSize: subjectPage.pageSize,
|
|
837
|
+
totalPageCount: subjectPage.totalPageCount,
|
|
838
|
+
content,
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
mapSimpleResponse(response) {
|
|
842
|
+
if (Object.prototype.toString.call(response) === '[object Array]') {
|
|
843
|
+
return response.map((dto, index) => {
|
|
844
|
+
return this.entityMapper.fromDto(dto, index);
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
else {
|
|
848
|
+
return new Array(this.entityMapper.fromDto(response));
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
BaseEntityService = __decorate([
|
|
853
|
+
__param(0, Inject('entityMapper')),
|
|
854
|
+
__metadata("design:paramtypes", [Object, String, String])
|
|
855
|
+
], BaseEntityService);
|
|
856
|
+
|
|
857
|
+
const INITIAL_TABS_STATE = {
|
|
858
|
+
activeTabs: [],
|
|
859
|
+
currentTab: undefined,
|
|
860
|
+
};
|
|
861
|
+
function BaseEntityTabsStore() {
|
|
862
|
+
return signalStoreFeature(withState(INITIAL_TABS_STATE), withMethods((store) => {
|
|
863
|
+
function reset() {
|
|
864
|
+
const activeTabs = [];
|
|
865
|
+
patchState(store, { activeTabs, currentTab: undefined });
|
|
866
|
+
}
|
|
867
|
+
function tabIsActive(tabName) {
|
|
868
|
+
let activeTabs;
|
|
869
|
+
if (store.activeTabs().indexOf(tabName) == -1) {
|
|
870
|
+
activeTabs = store.activeTabs().concat([tabName]);
|
|
871
|
+
}
|
|
872
|
+
else {
|
|
873
|
+
activeTabs = store.activeTabs();
|
|
874
|
+
}
|
|
875
|
+
patchState(store, { activeTabs, currentTab: tabName });
|
|
876
|
+
}
|
|
877
|
+
function tabIsInactive(tabName) {
|
|
878
|
+
const activeTabs = store.activeTabs().filter((tab) => tab !== tabName);
|
|
879
|
+
patchState(store, { activeTabs, currentTab: undefined });
|
|
880
|
+
}
|
|
881
|
+
return { reset, tabIsActive, tabIsInactive };
|
|
882
|
+
}));
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
const BASE_ENTITY_STORE = new InjectionToken('BASE_ENTITY_STORE');
|
|
886
|
+
function BaseEntityStore(entityType, repositoryType) {
|
|
887
|
+
return signalStoreFeature(withState({
|
|
888
|
+
entities: [],
|
|
889
|
+
page: 0,
|
|
890
|
+
pageSize: 5,
|
|
891
|
+
totalPageCount: 0,
|
|
892
|
+
currentEntity: undefined,
|
|
893
|
+
currentId: undefined,
|
|
894
|
+
isLoading: false,
|
|
895
|
+
error: undefined,
|
|
896
|
+
selectedEntities: [],
|
|
897
|
+
}), withMethods((store, repository = inject(repositoryType)) => ({
|
|
898
|
+
clearCurrentEntity: () => patchState(store, { currentEntity: undefined }),
|
|
899
|
+
createEntity: () => {
|
|
900
|
+
return new entityType();
|
|
901
|
+
},
|
|
902
|
+
delete: rxMethod(pipe(tap(() => patchState(store, { isLoading: true, error: undefined })), switchMap((id) => {
|
|
903
|
+
return repository.delete(id).pipe(tapResponse({
|
|
904
|
+
next: () => {
|
|
905
|
+
const remainingEntities = store.entities().filter((entity) => entity.id !== id);
|
|
906
|
+
patchState(store, { entities: remainingEntities, isLoading: false });
|
|
907
|
+
},
|
|
908
|
+
error: (error) => patchState(store, { error: error.message }),
|
|
909
|
+
finalize: () => patchState(store, { isLoading: false }),
|
|
910
|
+
}));
|
|
911
|
+
}))),
|
|
912
|
+
deleteAll: rxMethod(pipe(switchMap(() => {
|
|
913
|
+
patchState(store, { isLoading: true, error: undefined });
|
|
914
|
+
return repository.deleteAll().pipe(tapResponse({
|
|
915
|
+
next: () => patchState(store, { entities: [], isLoading: false }),
|
|
916
|
+
error: (error) => patchState(store, { error: error.message }),
|
|
917
|
+
finalize: () => patchState(store, { isLoading: false }),
|
|
918
|
+
}));
|
|
919
|
+
}))),
|
|
920
|
+
deselectAll: () => {
|
|
921
|
+
patchState(store, { selectedEntities: [] });
|
|
922
|
+
},
|
|
923
|
+
deselectEntity: (id) => {
|
|
924
|
+
const subjectEntity = store.selectedEntities().find((entity) => entity.id === id);
|
|
925
|
+
if (subjectEntity) {
|
|
926
|
+
const index = store.selectedEntities().indexOf(subjectEntity, 0);
|
|
927
|
+
if (index > -1) {
|
|
928
|
+
const selectedEntities = store.selectedEntities().concat([]);
|
|
929
|
+
selectedEntities.splice(index, 1);
|
|
930
|
+
patchState(store, { selectedEntities });
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
},
|
|
934
|
+
load: rxMethod(pipe(tap((parameters) => patchState(store, { page: parameters.page, isLoading: true, error: undefined })),
|
|
935
|
+
// debounceTime(1000),
|
|
936
|
+
// distinctUntilChanged(),
|
|
937
|
+
switchMap((parameters) => repository.findAll(parameters.path, parameters.filter, parameters.page).pipe(tapResponse({
|
|
938
|
+
next: (response) => {
|
|
939
|
+
if (Object.prototype.hasOwnProperty.call(response, 'content')) {
|
|
940
|
+
const baseEntityResponse = response;
|
|
941
|
+
patchState(store, {
|
|
942
|
+
entities: baseEntityResponse.content,
|
|
943
|
+
page: baseEntityResponse.page,
|
|
944
|
+
pageSize: baseEntityResponse.pageSize,
|
|
945
|
+
totalPageCount: baseEntityResponse.totalPageCount,
|
|
946
|
+
isLoading: false,
|
|
947
|
+
});
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
const entities = response.slice();
|
|
951
|
+
patchState(store, {
|
|
952
|
+
entities,
|
|
953
|
+
page: undefined,
|
|
954
|
+
pageSize: entities.length,
|
|
955
|
+
totalPageCount: undefined,
|
|
956
|
+
isLoading: false,
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
},
|
|
960
|
+
error: (error) => patchState(store, { error: error.message }),
|
|
961
|
+
finalize: () => patchState(store, { isLoading: false }),
|
|
962
|
+
}))))),
|
|
963
|
+
loadById: (id) => {
|
|
964
|
+
return store.entities().find((entity) => entity.id === id);
|
|
965
|
+
},
|
|
966
|
+
resetErrorState: () => patchState(store, { error: undefined }),
|
|
967
|
+
save: rxMethod(pipe(switchMap((entity) => {
|
|
968
|
+
patchState(store, { isLoading: true, error: undefined });
|
|
969
|
+
return repository.save(entity).pipe(tapResponse({
|
|
970
|
+
next: (savedEntity) => {
|
|
971
|
+
patchState(store, { entities: store.entities().concat([savedEntity]), isLoading: false });
|
|
972
|
+
},
|
|
973
|
+
error: (error) => patchState(store, { error: error.message }),
|
|
974
|
+
finalize: () => patchState(store, { isLoading: false }),
|
|
975
|
+
}));
|
|
976
|
+
}))),
|
|
977
|
+
selectEntity: (id) => {
|
|
978
|
+
const foundEntity = store.entities() && store.entities().length > 0 ? store.entities().filter((entity) => entity.id === id) : undefined;
|
|
979
|
+
if (foundEntity && foundEntity.length == 1 && store.selectedEntities().indexOf(foundEntity[0]) == -1) {
|
|
980
|
+
patchState(store, { selectedEntities: store.selectedEntities().concat(foundEntity) });
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
setCurrentEntity: (id) => {
|
|
984
|
+
const foundEntity = store.entities() && store.entities().length > 0 ? store.entities().filter((entity) => entity.id === id) : undefined;
|
|
985
|
+
if (foundEntity && foundEntity.length > 0) {
|
|
986
|
+
patchState(store, { currentEntity: foundEntity[0], currentId: foundEntity[0].id });
|
|
987
|
+
}
|
|
988
|
+
else
|
|
989
|
+
patchState(store, { currentEntity: undefined, currentId: undefined });
|
|
990
|
+
},
|
|
991
|
+
update: rxMethod(pipe(switchMap((entity) => {
|
|
992
|
+
patchState(store, { isLoading: true, error: undefined });
|
|
993
|
+
return repository.update(entity).pipe(tapResponse({
|
|
994
|
+
next: (updatedEntity) => {
|
|
995
|
+
const currentEntities = store.entities();
|
|
996
|
+
const indexToUpdate = currentEntities.findIndex((item) => item.id === entity.id);
|
|
997
|
+
currentEntities[indexToUpdate] = updatedEntity;
|
|
998
|
+
patchState(store, { entities: [...currentEntities], isLoading: false });
|
|
999
|
+
},
|
|
1000
|
+
error: (error) => patchState(store, { error: error.message }),
|
|
1001
|
+
finalize: () => patchState(store, { isLoading: false }),
|
|
1002
|
+
}));
|
|
1003
|
+
}))),
|
|
1004
|
+
})), withHooks((store) => ({
|
|
1005
|
+
onInit: () => {
|
|
1006
|
+
const path = new Map([]);
|
|
1007
|
+
const filter = new Map([]);
|
|
1008
|
+
store.load({ path, filter });
|
|
1009
|
+
},
|
|
1010
|
+
})), withComputed((store) => ({
|
|
1011
|
+
countOfEntities: computed(() => store.entities().length),
|
|
1012
|
+
matTableDataSource: computed(() => new MatTableDataSource(store.entities())),
|
|
1013
|
+
})));
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/*
|
|
1017
|
+
* Public API Surface of @processpuzzle/base-entity
|
|
1018
|
+
*/
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Generated bundle index. Do not edit.
|
|
1022
|
+
*/
|
|
1023
|
+
|
|
1024
|
+
export { BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorStore, FormControlType };
|
|
1025
|
+
//# sourceMappingURL=processpuzzle-base-entity.mjs.map
|