@processpuzzle/base-entity 0.3.4 → 0.3.5

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,20 +1,29 @@
1
- import { signalStoreFeature, withState, withMethods, patchState, withHooks, withComputed } from '@ngrx/signals';
2
1
  import * as i0 from '@angular/core';
3
- import { Directive, input, computed, Component, ViewChild, signal, Injectable, inject, effect, untracked, InjectionToken, Inject } from '@angular/core';
2
+ import { inject, input, Component, computed, effect, Inject, Directive, ViewChild, signal, Injectable, untracked, InjectionToken } from '@angular/core';
3
+ import { MatSnackBar } from '@angular/material/snack-bar';
4
+ import * as i1 from '@angular/common';
5
+ import { CommonModule, NgIf, NgStyle, NgClass, NgForOf } from '@angular/common';
6
+ import { Router, ActivatedRoute, RouterOutlet, ROUTER_OUTLET_DATA } from '@angular/router';
7
+ import { MatTabNav, MatTabLink, MatTabNavPanel } from '@angular/material/tabs';
8
+ import { MatToolbar } from '@angular/material/toolbar';
9
+ import { MatIcon } from '@angular/material/icon';
10
+ import { MatButton } from '@angular/material/button';
11
+ import * as i3 from '@angular/material/form-field';
12
+ import { MatFormField, MatFormFieldModule, MatLabel, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
13
+ import * as i4 from '@angular/material/input';
14
+ import { MatInput, MatInputModule } from '@angular/material/input';
15
+ import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu';
16
+ import { signalStoreFeature, withState, withMethods, patchState, withHooks, withComputed } from '@ngrx/signals';
17
+ import { LayoutService, RUNTIME_CONFIGURATION } from '@processpuzzle/util';
18
+ import { __decorate, __param } from 'tslib';
19
+ import { map, pipe, switchMap, tap, from, of } from 'rxjs';
20
+ import { HttpClient, HttpHeaders } from '@angular/common/http';
21
+ import { buildUrl } from 'build-url-ts';
4
22
  import * as i1$1 from '@angular/forms';
5
23
  import { ReactiveFormsModule, FormsModule, FormControl, Validators, FormBuilder } from '@angular/forms';
6
- import { ROUTER_OUTLET_DATA, Router, ActivatedRoute } from '@angular/router';
7
24
  import { MatCard, MatCardContent, MatCardActions } from '@angular/material/card';
8
- import * as i3 from '@angular/material/form-field';
9
- import { MatFormFieldModule, MatLabel, MatFormField, MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
10
- import { MatButton } from '@angular/material/button';
11
- import * as i1 from '@angular/common';
12
- import { NgIf, NgStyle, CommonModule, NgClass, NgForOf } from '@angular/common';
13
25
  import * as i5 from '@angular/material/datepicker';
14
26
  import { MatDatepickerModule } from '@angular/material/datepicker';
15
- import * as i4 from '@angular/material/input';
16
- import { MatInputModule, MatInput } from '@angular/material/input';
17
- import { MatIcon } from '@angular/material/icon';
18
27
  import * as i2 from '@angular/material/select';
19
28
  import { MatSelectModule } from '@angular/material/select';
20
29
  import { MatCheckbox } from '@angular/material/checkbox';
@@ -25,8 +34,6 @@ import { MatProgressBar } from '@angular/material/progress-bar';
25
34
  import { SelectionModel } from '@angular/cdk/collections';
26
35
  import { tapResponse } from '@ngrx/operators';
27
36
  import { rxMethod } from '@ngrx/signals/rxjs-interop';
28
- import { pipe, switchMap, tap, from, of, map } from 'rxjs';
29
- import { __decorate, __param } from 'tslib';
30
37
  import { Firestore, collection, doc, deleteDoc, getDoc, setDoc, orderBy, where, query, limit, getDocs, updateDoc } from '@angular/fire/firestore';
31
38
  import 'reflect-metadata';
32
39
 
@@ -54,6 +61,271 @@ class AbstractAttrDescriptor {
54
61
  }
55
62
  }
56
63
 
64
+ var BaseUrlSegments;
65
+ (function (BaseUrlSegments) {
66
+ BaseUrlSegments["DetailsForm"] = "details";
67
+ BaseUrlSegments["Feed"] = "feed";
68
+ BaseUrlSegments["ListForm"] = "list";
69
+ BaseUrlSegments["NewEntity"] = "new";
70
+ BaseUrlSegments["UnknownEntity"] = "unknown";
71
+ })(BaseUrlSegments || (BaseUrlSegments = {}));
72
+
73
+ var RouteSegments;
74
+ (function (RouteSegments) {
75
+ RouteSegments["LIST_ROUTE"] = "LIST_ROUTE";
76
+ RouteSegments["DETAILS_ROUTE"] = "DETAILS_ROUTE";
77
+ })(RouteSegments || (RouteSegments = {}));
78
+ const INITIAL_NAVIGATION_STATE = {
79
+ activeRouteSegment: RouteSegments.LIST_ROUTE,
80
+ entityName: '',
81
+ navigationError: undefined,
82
+ navigateTo: '',
83
+ returnTo: '',
84
+ };
85
+ function snakeCaseName(entityName) {
86
+ return entityName
87
+ .split(/(?=[A-Z])/)
88
+ .join('-')
89
+ .toLowerCase();
90
+ }
91
+ function BaseFormNavigatorStore(entityName) {
92
+ return signalStoreFeature(withState(INITIAL_NAVIGATION_STATE), withMethods((store, router = inject(Router), route = inject(ActivatedRoute)) => {
93
+ function determineActiveRouteSegment() {
94
+ const currentUrl = Reflect.get(route, '_routerState').snapshot.url;
95
+ if (currentUrl.endsWith(BaseUrlSegments.ListForm)) {
96
+ patchState(store, { activeRouteSegment: RouteSegments.LIST_ROUTE });
97
+ }
98
+ else if (currentUrl.endsWith(BaseUrlSegments.DetailsForm)) {
99
+ patchState(store, { activeRouteSegment: RouteSegments.DETAILS_ROUTE });
100
+ }
101
+ else {
102
+ patchState(store, { activeRouteSegment: undefined });
103
+ }
104
+ }
105
+ function determineBaseUrl() {
106
+ determineActiveRouteSegment();
107
+ const currentUrl = determineCurrentUrl();
108
+ return store.activeRouteSegment() === RouteSegments.DETAILS_ROUTE ? levelUpUrl(levelUpUrl(levelUpUrl(currentUrl))) : levelUpUrl(levelUpUrl(currentUrl));
109
+ }
110
+ function determineCurrentUrl() {
111
+ return Reflect.get(route, '_routerState').snapshot.url;
112
+ }
113
+ function levelUpUrl(currentUrl) {
114
+ return currentUrl.substring(0, currentUrl.lastIndexOf('/'));
115
+ }
116
+ async function navigateBack(defaultUrl) {
117
+ const goTo = store.returnTo() ? store.returnTo() : defaultUrl;
118
+ patchState(store, { returnTo: '' });
119
+ if (goTo) {
120
+ await router
121
+ .navigateByUrl(goTo)
122
+ .then()
123
+ .catch((error) => patchState(store, { navigationError: error.message }));
124
+ }
125
+ else
126
+ await navigateToList();
127
+ }
128
+ async function navigateToDetails(id, returnTo) {
129
+ if (store.activeRouteSegment() != RouteSegments.DETAILS_ROUTE) {
130
+ const snakeCaseEntityName = snakeCaseName(entityName);
131
+ const baseUrl = determineBaseUrl();
132
+ const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
133
+ await navigateToUrl(detailsFormPath, returnTo);
134
+ }
135
+ }
136
+ async function navigateToList(returnTo) {
137
+ const snakeCaseEntityName = snakeCaseName(entityName);
138
+ const baseUrl = determineBaseUrl();
139
+ const goToUrl = baseUrl + '/' + snakeCaseEntityName + '/list';
140
+ if (store.activeRouteSegment() != RouteSegments.LIST_ROUTE) {
141
+ await navigateToUrl(goToUrl, returnTo);
142
+ }
143
+ }
144
+ async function navigateToRelated(relatedTypeName, id, returnTo) {
145
+ const snakeCaseEntityName = snakeCaseName(relatedTypeName);
146
+ const baseUrl = determineBaseUrl();
147
+ const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
148
+ await navigateToUrl(detailsFormPath, returnTo);
149
+ }
150
+ async function navigateToUrl(url, returnTo) {
151
+ if (returnTo) {
152
+ patchState(store, { returnTo });
153
+ }
154
+ else {
155
+ patchState(store, { returnTo: router.url });
156
+ }
157
+ patchState(store, { navigateTo: url });
158
+ await router
159
+ .navigateByUrl(url)
160
+ .then(() => determineActiveRouteSegment())
161
+ .catch((error) => patchState(store, { navigationError: error.message }));
162
+ }
163
+ return { determineCurrentUrl, determineActiveRouteSegment, navigateBack, navigateToDetails, navigateToList, navigateToRelated, navigateToUrl };
164
+ }), withHooks((store) => ({
165
+ onInit: () => {
166
+ store.determineActiveRouteSegment();
167
+ },
168
+ })));
169
+ }
170
+
171
+ class BaseEntityToolbarComponent {
172
+ baseEntityListOptions = input.required(...(ngDevMode ? [{ debugName: "baseEntityListOptions" }] : /* istanbul ignore next */ []));
173
+ layoutService = inject(LayoutService);
174
+ store;
175
+ // region Angular lifecycle hooks
176
+ ngOnInit() {
177
+ this.store = this.baseEntityListOptions().store;
178
+ }
179
+ // endregion
180
+ // event handling methods
181
+ onAddEntity() {
182
+ this.store.navigateToDetails(BaseUrlSegments.NewEntity);
183
+ }
184
+ onDeleteEntities() {
185
+ this.store.selectedEntities().forEach((entity) => this.store.delete(entity.id));
186
+ }
187
+ onDoFilter($event) {
188
+ const filterValue = $event.target.value;
189
+ this.store.doFilter(filterValue);
190
+ }
191
+ // endregion
192
+ // public queries and mutators
193
+ isSmallDevice() {
194
+ return this.layoutService.isSmallDevice();
195
+ }
196
+ // endregion
197
+ // protected, private helper methods
198
+ RouteSegments = RouteSegments;
199
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityToolbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
200
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.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.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.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[matButton], a[matButton], button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button], a[mat-button], a[mat-raised-button], a[mat-flat-button], a[mat-stroked-button] ", inputs: ["matButton"], exportAs: ["matButton", "matAnchor"] }, { 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"] }] });
201
+ }
202
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityToolbarComponent, decorators: [{
203
+ type: Component,
204
+ 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>" }]
205
+ }], propDecorators: { baseEntityListOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "baseEntityListOptions", required: true }] }] } });
206
+
207
+ class BaseEntityStatusbarComponent {
208
+ store;
209
+ baseEntityListOptions = input.required(...(ngDevMode ? [{ debugName: "baseEntityListOptions" }] : /* istanbul ignore next */ []));
210
+ entityTitle = computed(() => this.evaluateEntityTitle(this.baseEntityListOptions().entityTitle), ...(ngDevMode ? [{ debugName: "entityTitle" }] : /* istanbul ignore next */ []));
211
+ isVisible = computed(() => this.store.currentEntity() != undefined || this.store.selectedEntities().length == 1, ...(ngDevMode ? [{ debugName: "isVisible" }] : /* istanbul ignore next */ []));
212
+ // region Angular lifecycle hooks
213
+ ngOnInit() {
214
+ this.store = this.baseEntityListOptions().store;
215
+ }
216
+ // endregion
217
+ // event handling methods
218
+ // endregion
219
+ // protected, private helper methods
220
+ evaluateEntityTitle(title) {
221
+ const fn = new Function('ctx', 'return ' + title.replace(/this\./g, 'ctx.'));
222
+ return fn(this);
223
+ }
224
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityStatusbarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
225
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.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.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: MatToolbar, selector: "mat-toolbar", inputs: ["color"], exportAs: ["matToolbar"] }] });
226
+ }
227
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityStatusbarComponent, decorators: [{
228
+ type: Component,
229
+ 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>" }]
230
+ }], propDecorators: { baseEntityListOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "baseEntityListOptions", required: true }] }] } });
231
+
232
+ class BaseEntityTabsComponent {
233
+ store;
234
+ baseEntityListOptions = input.required(...(ngDevMode ? [{ debugName: "baseEntityListOptions" }] : /* istanbul ignore next */ []));
235
+ selectedEntityId = computed(() => (this.store.currentId() ? this.store.currentId() : BaseUrlSegments.NewEntity), ...(ngDevMode ? [{ debugName: "selectedEntityId" }] : /* istanbul ignore next */ []));
236
+ detailsTabName = computed(() => this.baseEntityListOptions().entityName + ' - details', ...(ngDevMode ? [{ debugName: "detailsTabName" }] : /* istanbul ignore next */ []));
237
+ listTabName = computed(() => this.baseEntityListOptions().entityName + ' - list', ...(ngDevMode ? [{ debugName: "listTabName" }] : /* istanbul ignore next */ []));
238
+ constructor() {
239
+ this.registerEffects();
240
+ }
241
+ // region angular lifecycle hooks
242
+ ngOnDestroy() {
243
+ this.store.tabIsInactive(this.listTabName());
244
+ this.store.tabIsInactive(this.detailsTabName());
245
+ }
246
+ ngOnInit() {
247
+ this.store = this.baseEntityListOptions().store;
248
+ }
249
+ // endregion
250
+ // region event handlers
251
+ async onShowDetails() {
252
+ if (this.store.activeRouteSegment() != RouteSegments.DETAILS_ROUTE) {
253
+ const id = this.selectedEntityId() ? this.selectedEntityId() : BaseUrlSegments.NewEntity;
254
+ await this.store.navigateToDetails(id);
255
+ this.store.tabIsActive(this.detailsTabName());
256
+ }
257
+ }
258
+ async onShowList() {
259
+ if (this.store.activeRouteSegment() != RouteSegments.LIST_ROUTE) {
260
+ await this.store.navigateToList(this.baseEntityListOptions().entityName);
261
+ this.store.tabIsActive(this.listTabName());
262
+ }
263
+ }
264
+ // endregion
265
+ // region protected, private helper methods
266
+ registerEffects() {
267
+ effect(() => {
268
+ if (this.store.activeRouteSegment() === RouteSegments.DETAILS_ROUTE) {
269
+ this.store.tabIsActive(this.detailsTabName());
270
+ }
271
+ else {
272
+ this.store.tabIsActive(this.listTabName());
273
+ }
274
+ });
275
+ }
276
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityTabsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
277
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.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"] }] });
278
+ }
279
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityTabsComponent, decorators: [{
280
+ type: Component,
281
+ 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>" }]
282
+ }], ctorParameters: () => [], propDecorators: { baseEntityListOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "baseEntityListOptions", required: true }] }] } });
283
+
284
+ class BaseEntityContainerComponent {
285
+ baseEntityListOptions = input.required(...(ngDevMode ? [{ debugName: "baseEntityListOptions" }] : /* istanbul ignore next */ []));
286
+ snackBar = inject(MatSnackBar);
287
+ store;
288
+ constructor() {
289
+ this.registerEffects();
290
+ }
291
+ // region Angular lifecycle hooks
292
+ ngOnDestroy() {
293
+ this.store.reset();
294
+ }
295
+ ngOnInit() {
296
+ this.store = this.baseEntityListOptions().store;
297
+ }
298
+ // endregion
299
+ // region protected, private helper methods
300
+ registerEffects() {
301
+ effect(() => {
302
+ if (this.store.error()) {
303
+ const errorMessage = this.store.error() ? this.store.error() : 'Undefined Error';
304
+ this.snackBar.open(errorMessage, 'Close', { duration: 5000 });
305
+ }
306
+ });
307
+ }
308
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
309
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.4", type: BaseEntityContainerComponent, isStandalone: true, selector: "base-entity-container", inputs: { baseEntityListOptions: { classPropertyName: "baseEntityListOptions", publicName: "baseEntityListOptions", isSignal: true, isRequired: true, transformFunction: null } }, ngImport: i0, template: `
310
+ <div>
311
+ <base-entity-tabs [baseEntityListOptions]="baseEntityListOptions()"></base-entity-tabs>
312
+ </div>
313
+ `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: BaseEntityTabsComponent, selector: "base-entity-tabs", inputs: ["baseEntityListOptions"] }] });
314
+ }
315
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImport: i0, type: BaseEntityContainerComponent, decorators: [{
316
+ type: Component,
317
+ args: [{
318
+ selector: 'base-entity-container',
319
+ standalone: true,
320
+ imports: [CommonModule, BaseEntityTabsComponent],
321
+ template: `
322
+ <div>
323
+ <base-entity-tabs [baseEntityListOptions]="baseEntityListOptions()"></base-entity-tabs>
324
+ </div>
325
+ `,
326
+ }]
327
+ }], ctorParameters: () => [], propDecorators: { baseEntityListOptions: [{ type: i0.Input, args: [{ isSignal: true, alias: "baseEntityListOptions", required: true }] }] } });
328
+
57
329
  const INITIAL_CONTAINER_STATE = {
58
330
  filterKey: undefined,
59
331
  };
@@ -66,6 +338,137 @@ function BaseEntityContainerStore() {
66
338
  }));
67
339
  }
68
340
 
341
+ let BaseEntityRestService = class BaseEntityRestService {
342
+ entityMapper;
343
+ urlProperty;
344
+ resourceUrl;
345
+ runtimeConfiguration = inject(RUNTIME_CONFIGURATION);
346
+ baseUrl;
347
+ httpClient = inject(HttpClient);
348
+ headers = new HttpHeaders({
349
+ 'Content-Type': 'application/json; charset=utf-8',
350
+ 'Access-Control-Allow-Methods': 'GET, HEAD, PUT, PATCH, POST, DELETE',
351
+ 'Access-Control-Allow-Origin-Credentials': 'true',
352
+ 'Access-Control-Allow-Headers': 'Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers',
353
+ });
354
+ constructor(entityMapper, urlProperty, resourceUrl) {
355
+ this.entityMapper = entityMapper;
356
+ this.urlProperty = urlProperty;
357
+ this.resourceUrl = resourceUrl;
358
+ const baseConf = Reflect.get(this.runtimeConfiguration, 'BASE_CONFIGURATION');
359
+ this.baseUrl = Reflect.get(baseConf, urlProperty);
360
+ }
361
+ // region public accessor and mutator methods
362
+ delete(id) {
363
+ return this.httpClient.delete(this.resourceUrl + `/${id}`, { headers: this.headers });
364
+ }
365
+ deleteAll() {
366
+ return this.httpClient.delete(this.resourceUrl, { headers: this.headers });
367
+ }
368
+ findAll(page) {
369
+ return this.findByQuery({ page });
370
+ }
371
+ findByQuery(queryCondition) {
372
+ const fullUrl = this.buildFullUrl(this.resourceUrl, queryCondition);
373
+ if (fullUrl) {
374
+ return this.httpClient.get(fullUrl, { headers: this.headers }).pipe(map((httpResponse) => {
375
+ return queryCondition.page ? this.mapPagedResponse(httpResponse) : this.mapSimpleResponse(httpResponse);
376
+ }));
377
+ }
378
+ else
379
+ throw new Error('Could not determine the full url');
380
+ }
381
+ findById(id) {
382
+ const queryCondition = { pathParams: new Map([['id', id]]) };
383
+ const fullUrl = this.buildFullUrl(this.resourceUrl, queryCondition);
384
+ if (fullUrl) {
385
+ return this.httpClient.get(fullUrl, { headers: this.headers }).pipe(map((httpResponse) => {
386
+ return this.mapSimpleResponse(httpResponse);
387
+ }));
388
+ }
389
+ else
390
+ throw new Error('Could not determine the full url');
391
+ }
392
+ add(entity, id) {
393
+ const dto = this.entityMapper.toDto(entity);
394
+ const fullUrl = this.buildFullUrl(this.resourceUrl, {});
395
+ if (fullUrl) {
396
+ return this.httpClient.post(fullUrl, dto, { headers: this.headers }).pipe(map((response) => {
397
+ return this.entityMapper.fromDto(response, id);
398
+ }));
399
+ }
400
+ else
401
+ throw new Error('Could not determine the full url');
402
+ }
403
+ update(entity) {
404
+ const dto = this.entityMapper.toDto(entity);
405
+ const pathParams = new Map([['id', String(entity.id)]]);
406
+ const fullUrl = this.buildFullUrl(this.resourceUrl + '/%{id}', { pathParams });
407
+ if (fullUrl) {
408
+ return this.httpClient.put(fullUrl, dto, { headers: this.headers }).pipe(map((response) => {
409
+ return this.entityMapper.fromDto(response);
410
+ }));
411
+ }
412
+ else
413
+ throw new Error('Could not determine the full url');
414
+ }
415
+ // endregion
416
+ // region protected, private helper methods
417
+ buildFullUrl(resourceUri, queryCondition) {
418
+ const queryParams = new Map();
419
+ if (queryCondition.page)
420
+ queryParams.set('page', queryCondition.page.toString());
421
+ if (queryCondition.filters !== undefined && queryCondition.filters.length != 0) {
422
+ queryCondition.filters.forEach((filter) => queryParams.set(filter.property, filter.value));
423
+ }
424
+ let params = {};
425
+ if (queryParams.size > 0) {
426
+ for (const [key, value] of queryParams) {
427
+ params = { ...params, [key]: value };
428
+ }
429
+ }
430
+ else
431
+ params = null;
432
+ if (queryCondition.pathParams !== undefined && queryCondition.pathParams.size != 0) {
433
+ queryCondition.pathParams.forEach((value, key) => {
434
+ const pathParam = '%{' + key + '}';
435
+ resourceUri = resourceUri.replace(pathParam, value);
436
+ });
437
+ }
438
+ const urlOptions = {
439
+ path: resourceUri,
440
+ hash: queryCondition.hash,
441
+ queryParams: params,
442
+ };
443
+ return buildUrl(this.baseUrl, urlOptions);
444
+ }
445
+ mapPagedResponse(response) {
446
+ const subjectPage = response[0];
447
+ const content = subjectPage.content.map((dto, index) => {
448
+ return this.entityMapper.fromDto(dto, index);
449
+ });
450
+ return {
451
+ page: subjectPage.page,
452
+ pageSize: subjectPage.pageSize,
453
+ totalPageCount: subjectPage.totalPageCount,
454
+ content,
455
+ };
456
+ }
457
+ mapSimpleResponse(response) {
458
+ if (Object.prototype.toString.call(response) === '[object Array]') {
459
+ return response.map((dto, index) => {
460
+ return this.entityMapper.fromDto(dto, index);
461
+ });
462
+ }
463
+ else {
464
+ return new Array(this.entityMapper.fromDto(response));
465
+ }
466
+ }
467
+ };
468
+ BaseEntityRestService = __decorate([
469
+ __param(0, Inject('entityMapper'))
470
+ ], BaseEntityRestService);
471
+
69
472
  class BaseEntityAttrDescriptor extends AbstractAttrDescriptor {
70
473
  description;
71
474
  styleClass = '';
@@ -119,15 +522,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
119
522
  }]
120
523
  }], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
121
524
 
122
- var BaseUrlSegments;
123
- (function (BaseUrlSegments) {
124
- BaseUrlSegments["DetailsForm"] = "details";
125
- BaseUrlSegments["Feed"] = "feed";
126
- BaseUrlSegments["ListForm"] = "list";
127
- BaseUrlSegments["NewEntity"] = "new";
128
- BaseUrlSegments["UnknownEntity"] = "unknown";
129
- })(BaseUrlSegments || (BaseUrlSegments = {}));
130
-
131
525
  class BaseFormControlComponent {
132
526
  config = input.required(...(ngDevMode ? [{ debugName: "config" }] : /* istanbul ignore next */ []));
133
527
  entity = input.required(...(ngDevMode ? [{ debugName: "entity" }] : /* istanbul ignore next */ []));
@@ -734,104 +1128,6 @@ function BaseEntityStore(entityType, repositoryType) {
734
1128
  })));
735
1129
  }
736
1130
 
737
- var RouteSegments;
738
- (function (RouteSegments) {
739
- RouteSegments["LIST_ROUTE"] = "LIST_ROUTE";
740
- RouteSegments["DETAILS_ROUTE"] = "DETAILS_ROUTE";
741
- })(RouteSegments || (RouteSegments = {}));
742
- const INITIAL_NAVIGATION_STATE = {
743
- activeRouteSegment: RouteSegments.LIST_ROUTE,
744
- entityName: '',
745
- navigationError: undefined,
746
- navigateTo: '',
747
- returnTo: '',
748
- };
749
- function snakeCaseName(entityName) {
750
- return entityName
751
- .split(/(?=[A-Z])/)
752
- .join('-')
753
- .toLowerCase();
754
- }
755
- function BaseFormNavigatorStore(entityName) {
756
- return signalStoreFeature(withState(INITIAL_NAVIGATION_STATE), withMethods((store, router = inject(Router), route = inject(ActivatedRoute)) => {
757
- function determineActiveRouteSegment() {
758
- const currentUrl = Reflect.get(route, '_routerState').snapshot.url;
759
- if (currentUrl.endsWith(BaseUrlSegments.ListForm)) {
760
- patchState(store, { activeRouteSegment: RouteSegments.LIST_ROUTE });
761
- }
762
- else if (currentUrl.endsWith(BaseUrlSegments.DetailsForm)) {
763
- patchState(store, { activeRouteSegment: RouteSegments.DETAILS_ROUTE });
764
- }
765
- else {
766
- patchState(store, { activeRouteSegment: undefined });
767
- }
768
- }
769
- function determineBaseUrl() {
770
- determineActiveRouteSegment();
771
- const currentUrl = determineCurrentUrl();
772
- return store.activeRouteSegment() === RouteSegments.DETAILS_ROUTE ? levelUpUrl(levelUpUrl(levelUpUrl(currentUrl))) : levelUpUrl(levelUpUrl(currentUrl));
773
- }
774
- function determineCurrentUrl() {
775
- return Reflect.get(route, '_routerState').snapshot.url;
776
- }
777
- function levelUpUrl(currentUrl) {
778
- return currentUrl.substring(0, currentUrl.lastIndexOf('/'));
779
- }
780
- async function navigateBack(defaultUrl) {
781
- const goTo = store.returnTo() ? store.returnTo() : defaultUrl;
782
- patchState(store, { returnTo: '' });
783
- if (goTo) {
784
- await router
785
- .navigateByUrl(goTo)
786
- .then()
787
- .catch((error) => patchState(store, { navigationError: error.message }));
788
- }
789
- else
790
- await navigateToList();
791
- }
792
- async function navigateToDetails(id, returnTo) {
793
- if (store.activeRouteSegment() != RouteSegments.DETAILS_ROUTE) {
794
- const snakeCaseEntityName = snakeCaseName(entityName);
795
- const baseUrl = determineBaseUrl();
796
- const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
797
- await navigateToUrl(detailsFormPath, returnTo);
798
- }
799
- }
800
- async function navigateToList(returnTo) {
801
- const snakeCaseEntityName = snakeCaseName(entityName);
802
- const baseUrl = determineBaseUrl();
803
- const goToUrl = baseUrl + '/' + snakeCaseEntityName + '/list';
804
- if (store.activeRouteSegment() != RouteSegments.LIST_ROUTE) {
805
- await navigateToUrl(goToUrl, returnTo);
806
- }
807
- }
808
- async function navigateToRelated(relatedTypeName, id, returnTo) {
809
- const snakeCaseEntityName = snakeCaseName(relatedTypeName);
810
- const baseUrl = determineBaseUrl();
811
- const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
812
- await navigateToUrl(detailsFormPath, returnTo);
813
- }
814
- async function navigateToUrl(url, returnTo) {
815
- if (returnTo) {
816
- patchState(store, { returnTo });
817
- }
818
- else {
819
- patchState(store, { returnTo: router.url });
820
- }
821
- patchState(store, { navigateTo: url });
822
- await router
823
- .navigateByUrl(url)
824
- .then(() => determineActiveRouteSegment())
825
- .catch((error) => patchState(store, { navigationError: error.message }));
826
- }
827
- return { determineCurrentUrl, determineActiveRouteSegment, navigateBack, navigateToDetails, navigateToList, navigateToRelated, navigateToUrl };
828
- }), withHooks((store) => ({
829
- onInit: () => {
830
- store.determineActiveRouteSegment();
831
- },
832
- })));
833
- }
834
-
835
1131
  let BaseEntityFirestoreService = class BaseEntityFirestoreService {
836
1132
  entityMapper;
837
1133
  collectionName;
@@ -1029,5 +1325,5 @@ const BASE_ENTITY_ROUTES = [
1029
1325
  * Generated bundle index. Do not edit.
1030
1326
  */
1031
1327
 
1032
- export { AbstractAttrDescriptor, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerStore, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorStore, Entity, FlexDirection, FlexboxDescriptor, FormControlType, Id, OrderByDirection, RouteSegments, getEntityIds, getEntityOptions };
1328
+ export { AbstractAttrDescriptor, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorStore, Entity, FlexDirection, FlexboxDescriptor, FormControlType, Id, OrderByDirection, RouteSegments, getEntityIds, getEntityOptions };
1033
1329
  //# sourceMappingURL=processpuzzle-base-entity.mjs.map