@processpuzzle/base-entity 0.8.2 → 0.9.1
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,9 +1,9 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal,
|
|
2
|
+
import { inject, Injectable, input, computed, Component, effect, InjectionToken, Inject, Directive, Injector, signal, HostBinding, EventEmitter, Output, ViewChild, DestroyRef, untracked, runInInjectionContext, provideAppInitializer } from '@angular/core';
|
|
3
3
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
|
4
4
|
import * as i1 from '@angular/common';
|
|
5
5
|
import { CommonModule, NgClass, NgStyle, NgTemplateOutlet, SlicePipe } from '@angular/common';
|
|
6
|
-
import {
|
|
6
|
+
import { Router, RouteConfigLoadEnd, NavigationEnd, ActivatedRoute, RouterOutlet, ROUTER_OUTLET_DATA } from '@angular/router';
|
|
7
7
|
import { MatTabNav, MatTabLink, MatTabNavPanel } from '@angular/material/tabs';
|
|
8
8
|
import * as i2 from '@angular/material/toolbar';
|
|
9
9
|
import { MatToolbarModule, MatToolbar } from '@angular/material/toolbar';
|
|
@@ -85,6 +85,60 @@ var BaseUrlSegments;
|
|
|
85
85
|
BaseUrlSegments["UnknownEntity"] = "unknown";
|
|
86
86
|
})(BaseUrlSegments || (BaseUrlSegments = {}));
|
|
87
87
|
|
|
88
|
+
const ENTITY_NAME_ROUTE_DATA_KEY = 'entityName';
|
|
89
|
+
class EntityRouteRegistry {
|
|
90
|
+
router = inject(Router);
|
|
91
|
+
basePaths = new Map();
|
|
92
|
+
scan() {
|
|
93
|
+
this.basePaths.clear();
|
|
94
|
+
this.walk(this.router.config, '');
|
|
95
|
+
}
|
|
96
|
+
observeLazyLoads() {
|
|
97
|
+
this.router.events.subscribe((event) => {
|
|
98
|
+
if (event instanceof RouteConfigLoadEnd)
|
|
99
|
+
this.scan();
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
basePath(entityName) {
|
|
103
|
+
return this.basePaths.get(entityName);
|
|
104
|
+
}
|
|
105
|
+
listPath(entityName) {
|
|
106
|
+
const base = this.basePaths.get(entityName);
|
|
107
|
+
return base ? `${base}/list` : undefined;
|
|
108
|
+
}
|
|
109
|
+
detailsPath(entityName, id) {
|
|
110
|
+
const base = this.basePaths.get(entityName);
|
|
111
|
+
return base ? `${base}/${id}/details` : undefined;
|
|
112
|
+
}
|
|
113
|
+
registeredEntities() {
|
|
114
|
+
return [...this.basePaths.keys()];
|
|
115
|
+
}
|
|
116
|
+
walk(routes, prefix) {
|
|
117
|
+
if (!routes)
|
|
118
|
+
return;
|
|
119
|
+
for (const route of routes) {
|
|
120
|
+
const segment = this.append(prefix, route.path);
|
|
121
|
+
const entityName = route.data?.[ENTITY_NAME_ROUTE_DATA_KEY];
|
|
122
|
+
if (typeof entityName === 'string' && entityName.length > 0) {
|
|
123
|
+
this.basePaths.set(entityName, segment);
|
|
124
|
+
}
|
|
125
|
+
this.walk(route.children, segment);
|
|
126
|
+
this.walk(route._loadedRoutes, segment);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
append(prefix, path) {
|
|
130
|
+
if (!path)
|
|
131
|
+
return prefix;
|
|
132
|
+
return `${prefix}/${path}`;
|
|
133
|
+
}
|
|
134
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
135
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, providedIn: 'root' });
|
|
136
|
+
}
|
|
137
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImport: i0, type: EntityRouteRegistry, decorators: [{
|
|
138
|
+
type: Injectable,
|
|
139
|
+
args: [{ providedIn: 'root' }]
|
|
140
|
+
}] });
|
|
141
|
+
|
|
88
142
|
var RouteSegments;
|
|
89
143
|
(function (RouteSegments) {
|
|
90
144
|
RouteSegments["LIST_ROUTE"] = "LIST_ROUTE";
|
|
@@ -130,7 +184,7 @@ function lastKeyOf(target) {
|
|
|
130
184
|
last = key;
|
|
131
185
|
return last;
|
|
132
186
|
}
|
|
133
|
-
const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, withState(INITIAL_NAVIGATION_STATE), withDevtools('Base Form Navigator'), withMethods((store, router = inject(Router), route = inject(ActivatedRoute)) => {
|
|
187
|
+
const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, withState(INITIAL_NAVIGATION_STATE), withDevtools('Base Form Navigator'), withMethods((store, router = inject(Router), route = inject(ActivatedRoute), entityRouteRegistry = inject(EntityRouteRegistry)) => {
|
|
134
188
|
let pendingNavigatorUrl;
|
|
135
189
|
let routerEventsSubscription;
|
|
136
190
|
function clearPayloadStacks() {
|
|
@@ -236,6 +290,11 @@ const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, with
|
|
|
236
290
|
async function navigateToRelated(relatedTypeName, id, returnTo, payload) {
|
|
237
291
|
patchState(store, { entityName: relatedTypeName });
|
|
238
292
|
pushPayload(payload);
|
|
293
|
+
const registeredPath = entityRouteRegistry.detailsPath(relatedTypeName, id);
|
|
294
|
+
if (registeredPath) {
|
|
295
|
+
await navigateToUrl(registeredPath, returnTo);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
239
298
|
const snakeCaseEntityName = snakeCaseName(relatedTypeName);
|
|
240
299
|
const baseUrl = determineBaseUrl();
|
|
241
300
|
const detailsFormPath = baseUrl + '/' + snakeCaseEntityName + '/' + id + '/details';
|
|
@@ -244,6 +303,11 @@ const BaseFormNavigatorSingletonStore = signalStore({ providedIn: 'root' }, with
|
|
|
244
303
|
async function navigateToRelatedList(relatedTypeName, returnTo, payload) {
|
|
245
304
|
patchState(store, { entityName: relatedTypeName });
|
|
246
305
|
pushPayload(payload);
|
|
306
|
+
const registeredPath = entityRouteRegistry.listPath(relatedTypeName);
|
|
307
|
+
if (registeredPath) {
|
|
308
|
+
await navigateToUrl(registeredPath, returnTo);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
247
311
|
const snakeCaseEntityName = snakeCaseName(relatedTypeName);
|
|
248
312
|
const baseUrl = determineBaseUrl();
|
|
249
313
|
const listPath = baseUrl + '/' + snakeCaseEntityName + '/list';
|
|
@@ -1010,6 +1074,7 @@ const BASE_ENTITY_FACADE_REGISTRY = new InjectionToken('BASE_ENTITY_FACADE_REGIS
|
|
|
1010
1074
|
class EntityRegistryComponent {
|
|
1011
1075
|
registry = inject(BASE_ENTITY_FACADE_REGISTRY);
|
|
1012
1076
|
injector = inject(Injector);
|
|
1077
|
+
entityRouteRegistry = inject(EntityRouteRegistry);
|
|
1013
1078
|
queryParams = toSignal(inject(ActivatedRoute).queryParamMap, { initialValue: null });
|
|
1014
1079
|
descriptors = signal(this.buildDescriptors(), /* @ts-ignore */
|
|
1015
1080
|
...(ngDevMode ? [{ debugName: "descriptors" }] : /* istanbul ignore next */ []));
|
|
@@ -1029,6 +1094,7 @@ class EntityRegistryComponent {
|
|
|
1029
1094
|
entityTitle,
|
|
1030
1095
|
isAbstract: descriptor.isAbstract,
|
|
1031
1096
|
parentEntityName: descriptor.parentEntity,
|
|
1097
|
+
route: this.entityRouteRegistry.basePath(descriptor.entityName),
|
|
1032
1098
|
attrDescriptors: attrDescriptors.map((attr) => this.serializeAttr(attr)),
|
|
1033
1099
|
};
|
|
1034
1100
|
});
|
|
@@ -2478,7 +2544,8 @@ class BaseEntityDescriptor {
|
|
|
2478
2544
|
extraFormActionsTemplate;
|
|
2479
2545
|
parentEntity;
|
|
2480
2546
|
isAbstract;
|
|
2481
|
-
|
|
2547
|
+
route;
|
|
2548
|
+
constructor({ store, attrDescriptors, entityName, entityTitle, extraFormActionsTemplate, isAbstract, parentEntity, route }) {
|
|
2482
2549
|
this.store = store;
|
|
2483
2550
|
this.attrDescriptors = attrDescriptors;
|
|
2484
2551
|
this.entityName = entityName;
|
|
@@ -2486,6 +2553,7 @@ class BaseEntityDescriptor {
|
|
|
2486
2553
|
this.extraFormActionsTemplate = extraFormActionsTemplate;
|
|
2487
2554
|
this.isAbstract = isAbstract ?? false;
|
|
2488
2555
|
this.parentEntity = parentEntity;
|
|
2556
|
+
this.route = route;
|
|
2489
2557
|
}
|
|
2490
2558
|
createTestId(suffix) {
|
|
2491
2559
|
return createTestId(this.entityName, suffix);
|
|
@@ -3068,6 +3136,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.5", ngImpor
|
|
|
3068
3136
|
|
|
3069
3137
|
const BASE_ENTITY_SERVICE = new InjectionToken('BASE_ENTITY_SERVICE');
|
|
3070
3138
|
|
|
3139
|
+
function provideEntityRouteRegistry() {
|
|
3140
|
+
return provideAppInitializer(() => {
|
|
3141
|
+
const registry = inject(EntityRouteRegistry);
|
|
3142
|
+
registry.scan();
|
|
3143
|
+
registry.observeLazyLoads();
|
|
3144
|
+
});
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3071
3147
|
// Symbol to store entity options on instance
|
|
3072
3148
|
const ENTITY_OPTIONS_KEY = Symbol('entityOptions');
|
|
3073
3149
|
// Metadata key for storing ID properties
|
|
@@ -3156,5 +3232,5 @@ const BASE_ENTITY_ROUTES = [
|
|
|
3156
3232
|
* Generated bundle index. Do not edit.
|
|
3157
3233
|
*/
|
|
3158
3234
|
|
|
3159
|
-
export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityDescriptorRegistry, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, Entity, EntityRegistryComponent, FlexDirection, FlexboxDescriptor, FormControlType, Id, NavigatorCommand, OrderByDirection, RULE_ENGINE, RouteSegments, RuleViolationsSingletonStore, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey };
|
|
3235
|
+
export { ACTIVE_ENTITY_FACADE, AbstractAttrDescriptor, BASE_ENTITY_FACADE_REGISTRY, BASE_ENTITY_ROUTES, BASE_ENTITY_SERVICE, BASE_ENTITY_STORE, BASE_LIST_DESCRIPTORS, BaseEntityAttrDescriptor, BaseEntityContainerComponent, BaseEntityContainerStore, BaseEntityDescriptor, BaseEntityDescriptorRegistry, BaseEntityFacade, BaseEntityFirestoreService, BaseEntityFormComponent, BaseEntityListComponent, BaseEntityRestService, BaseEntityStore, BaseEntityTabsStore, BaseFormHostDirective, BaseFormNavigatorSingletonStore, BaseFormNavigatorStore, ENTITY_NAME_ROUTE_DATA_KEY, Entity, EntityRegistryComponent, EntityRouteRegistry, FlexDirection, FlexboxDescriptor, FormControlType, Id, NavigatorCommand, OrderByDirection, RULE_ENGINE, RouteSegments, RuleViolationsSingletonStore, SimpleEntityMapper, getEntityIds, getEntityOptions, getEnumKeyByValue, getEnumValueByKey, provideEntityRouteRegistry };
|
|
3160
3236
|
//# sourceMappingURL=processpuzzle-base-entity.mjs.map
|