@coolon/angular-ui-powerups 14.9.1 → 14.10.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/esm2020/lib/place/guards/place.guard.mjs +39 -7
- package/esm2020/lib/place/place-definition.mjs +3 -2
- package/esm2020/lib/place/place.decorator.mjs +2 -2
- package/esm2020/lib/place/url-snapshot.mjs +5 -2
- package/fesm2015/coolon-angular-ui-powerups.mjs +45 -10
- package/fesm2015/coolon-angular-ui-powerups.mjs.map +1 -1
- package/fesm2020/coolon-angular-ui-powerups.mjs +44 -9
- package/fesm2020/coolon-angular-ui-powerups.mjs.map +1 -1
- package/lib/place/place-definition.d.ts +2 -1
- package/lib/place/place.decorator.d.ts +4 -0
- package/lib/place/url-snapshot.d.ts +1 -0
- package/package.json +2 -2
- package/schematics/place-routes/index.js +1 -0
- package/schematics/place-routes/index.js.map +1 -1
- package/schematics/place-routes/place-class-scanner.d.ts +1 -0
- package/schematics/place-routes/place-class-scanner.js +10 -2
- package/schematics/place-routes/place-class-scanner.js.map +1 -1
- package/schematics/place-routes/place-def.d.ts +3 -1
- package/schematics/place-routes/place-def.js +3 -2
- package/schematics/place-routes/place-def.js.map +1 -1
|
@@ -39,11 +39,11 @@ import { MatTableModule } from '@angular/material/table';
|
|
|
39
39
|
import * as i4 from '@angular/material/tooltip';
|
|
40
40
|
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
41
41
|
import * as i1$3 from '@coolon/pectin';
|
|
42
|
-
import { GarbageCollector, DelegatingValueModel, assert, UnaryCommand, lang, Dsl, Logger, TrackExternal, ValueModel, StoreInValueModel, Command, MutableListModel, StoreInListModel, Disposable, DelegatingListModel, MutableValueModel, FocusManager, EventListenerList, Form, Guard, Binding, DebugContext, ListModel, Functions, SelectionModel, HasDelegate, MultipleSelectionModel, AbstractComputedListModel, DelegatingSelectionModel, DelegateProxyHandler, DirtyTrackingForm, PagedListModel, PageController, ComputedListModel, Deferred } from '@coolon/pectin';
|
|
42
|
+
import { GarbageCollector, DelegatingValueModel, assert, UnaryCommand, lang, Dsl, Logger, TrackExternal, ValueModel, StoreInValueModel, Command, MutableListModel, StoreInListModel, Disposable, DelegatingListModel, MutableValueModel, FocusManager, EventListenerList, Form, Guard, Binding, DebugContext, ListModel, Functions, SelectionModel, HasDelegate, MultipleSelectionModel, AbstractComputedListModel, DelegatingSelectionModel, DelegateProxyHandler, DirtyTrackingForm, PagedListModel, PageController, ComputedListModel, Deferred, Trace } from '@coolon/pectin';
|
|
43
43
|
import { __decorate, __param, __metadata } from 'tslib';
|
|
44
44
|
import * as i1 from '@angular/platform-browser';
|
|
45
45
|
import escapeStringRegexp from 'escape-string-regexp';
|
|
46
|
-
import { isEmpty, isString, isFunction, isNil, isInteger, isEqual, first, uniq, isObject, isNumber, isNaN as isNaN$1 } from 'lodash';
|
|
46
|
+
import { isEmpty, isString, isFunction, isNil, isInteger, isEqual, first, uniq, last, isObject, isNumber, isNaN as isNaN$1 } from 'lodash';
|
|
47
47
|
import { marked } from 'marked';
|
|
48
48
|
import { Memoize } from '@typescript-plus/fast-memoize-decorator';
|
|
49
49
|
import { Enum } from 'typescript-string-enums';
|
|
@@ -59,7 +59,7 @@ import { FlexModule, GridModule } from '@angular/flex-layout';
|
|
|
59
59
|
import * as i1$6 from '@angular/material/dialog';
|
|
60
60
|
import { MatDialogModule, MAT_DIALOG_DEFAULT_OPTIONS } from '@angular/material/dialog';
|
|
61
61
|
import * as i1$4 from '@angular/router';
|
|
62
|
-
import { UrlSegment, NavigationStart, NavigationEnd, NavigationError, NavigationCancel, RouterModule, ActivatedRouteSnapshot } from '@angular/router';
|
|
62
|
+
import { UrlSegment, NavigationStart, NavigationEnd, NavigationError, NavigationCancel, RouterModule, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
|
|
63
63
|
import * as i1$5 from '@angular/cdk/overlay';
|
|
64
64
|
import * as i3$2 from '@angular/material/list';
|
|
65
65
|
import { MatListModule } from '@angular/material/list';
|
|
@@ -6752,6 +6752,9 @@ class UrlSnapshot {
|
|
|
6752
6752
|
includesPathOf(placeDef) {
|
|
6753
6753
|
return this.getPrimarySegments().find(s => s.path === placeDef.path);
|
|
6754
6754
|
}
|
|
6755
|
+
isLastPlaceInUrl(placeDef) {
|
|
6756
|
+
return last(this.getPrimarySegments()).path === placeDef.path;
|
|
6757
|
+
}
|
|
6755
6758
|
createVisitFor(placeDef) {
|
|
6756
6759
|
return new Visit(placeDef, new ConsolidatedParameterMap(this.getPrimarySegments()));
|
|
6757
6760
|
}
|
|
@@ -8976,7 +8979,7 @@ class ParameterDefinition {
|
|
|
8976
8979
|
})(ParameterDefinition || (ParameterDefinition = {}));
|
|
8977
8980
|
|
|
8978
8981
|
class PlaceDefinition {
|
|
8979
|
-
constructor(component, path, authenticate, role, data, routeParameters, children) {
|
|
8982
|
+
constructor(component, path, authenticate, role, data, routeParameters, children, redirectToFirstChild) {
|
|
8980
8983
|
this.component = component;
|
|
8981
8984
|
this.path = path;
|
|
8982
8985
|
this.authenticate = authenticate;
|
|
@@ -8984,6 +8987,7 @@ class PlaceDefinition {
|
|
|
8984
8987
|
this.data = data;
|
|
8985
8988
|
this.routeParameters = routeParameters;
|
|
8986
8989
|
this.children = children;
|
|
8990
|
+
this.redirectToFirstChild = redirectToFirstChild;
|
|
8987
8991
|
}
|
|
8988
8992
|
hasRouteId() {
|
|
8989
8993
|
return !!this.getRouteIdParameterDef();
|
|
@@ -10057,7 +10061,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImpor
|
|
|
10057
10061
|
function Place(options) {
|
|
10058
10062
|
return (target) => {
|
|
10059
10063
|
if (PlaceComponent.isPlaceComponentConstructor(target)) {
|
|
10060
|
-
PlaceComponent.injectDefinition(target, new PlaceDefinition(target, options.path, isNil(options.authenticate) ? true : options.authenticate, options.role ?? options.roles, options.data, PlaceComponent.getRouteParameters(target), (options.children || []).map(c => PlaceComponent.getDefinition(c))));
|
|
10064
|
+
PlaceComponent.injectDefinition(target, new PlaceDefinition(target, options.path, isNil(options.authenticate) ? true : options.authenticate, options.role ?? options.roles, options.data, PlaceComponent.getRouteParameters(target), (options.children || []).map(c => PlaceComponent.getDefinition(c)), options.redirectToFirstChild ?? false));
|
|
10061
10065
|
if (options.roles) {
|
|
10062
10066
|
console.warn(`${target.name} @Place({roles: string[]}) is deprecated. Use @Place({role:any}) instead`);
|
|
10063
10067
|
}
|
|
@@ -10134,12 +10138,13 @@ class PlaceGuard {
|
|
|
10134
10138
|
this.interactionService = interactionService;
|
|
10135
10139
|
this.injector = injector;
|
|
10136
10140
|
}
|
|
10137
|
-
// @Trace()
|
|
10138
10141
|
async canActivate(activatedRoute, state) {
|
|
10139
10142
|
if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {
|
|
10140
10143
|
const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);
|
|
10144
|
+
const accessGuard = this.placeRouter.accessGuard.value;
|
|
10141
10145
|
if (placeDefinition.authenticate) {
|
|
10142
|
-
|
|
10146
|
+
const authenticated = await accessGuard.isAuthenticated();
|
|
10147
|
+
if (!authenticated || !accessGuard.isAuthorised(placeDefinition)) {
|
|
10143
10148
|
const redirectLocation = this.placeRouter.getAuthenticationFailureRedirect(activatedRoute, state);
|
|
10144
10149
|
const nextPlaceDef = this.getPlaceDefinition(redirectLocation);
|
|
10145
10150
|
if (nextPlaceDef.authenticate) {
|
|
@@ -10159,13 +10164,37 @@ class PlaceGuard {
|
|
|
10159
10164
|
const sanitisedVisit = await sanitiser.sanitise(initialVisit.mergeRouteParameters(parsedParams));
|
|
10160
10165
|
// Save the visit with any updated parameters. We need to save it so we remember any non route parameters
|
|
10161
10166
|
navigationSession.storeVisit(sanitisedVisit);
|
|
10167
|
+
const destUrlSnapshot = this.urlService.parseUrl(state.url);
|
|
10162
10168
|
if (initialVisit.hasRoutingChangedFrom(sanitisedVisit)) {
|
|
10163
10169
|
// Regenerate the url
|
|
10164
|
-
const urlSnapshot =
|
|
10170
|
+
const urlSnapshot = destUrlSnapshot.updateVisitSegments(sanitisedVisit);
|
|
10165
10171
|
// console.log('##### Place Guard Redirect', urlSnapshot);
|
|
10166
10172
|
return urlSnapshot;
|
|
10167
10173
|
}
|
|
10168
10174
|
else {
|
|
10175
|
+
// Our visit parameters are all sorted, now check if we should redirect to our child.
|
|
10176
|
+
// debugger;
|
|
10177
|
+
if (placeDefinition.redirectToFirstChild) {
|
|
10178
|
+
if (placeDefinition.children.length < 1) {
|
|
10179
|
+
lang.illegalState(`redirectToFirstChild set to true, but there were no children `);
|
|
10180
|
+
}
|
|
10181
|
+
for (let child of placeDefinition.children) {
|
|
10182
|
+
if (!child.authenticate || accessGuard.isAuthorised(child)) {
|
|
10183
|
+
console.log(state.url);
|
|
10184
|
+
if (destUrlSnapshot.isLastPlaceInUrl(placeDefinition)) {
|
|
10185
|
+
return this.urlService.createUrlSnapshot(sanitisedVisit, new Visit(child));
|
|
10186
|
+
}
|
|
10187
|
+
return true;
|
|
10188
|
+
// if (destUrlSnapshot.includesPathOf(child)) {
|
|
10189
|
+
// return true; // continue with the current url
|
|
10190
|
+
// } else {
|
|
10191
|
+
//
|
|
10192
|
+
// }
|
|
10193
|
+
}
|
|
10194
|
+
}
|
|
10195
|
+
// hmm, what should I do here, we didn't have an authorised child
|
|
10196
|
+
lang.illegalState(`redirectToFirstChild set to true, but there were no authenticated children`);
|
|
10197
|
+
}
|
|
10169
10198
|
return true;
|
|
10170
10199
|
}
|
|
10171
10200
|
});
|
|
@@ -10211,10 +10240,16 @@ class PlaceGuard {
|
|
|
10211
10240
|
}
|
|
10212
10241
|
PlaceGuard.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: PlaceGuard, deps: [{ token: i1$4.Router }, { token: UrlService }, { token: PlaceRouter }, { token: PlaceHistory }, { token: InteractionService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
10213
10242
|
PlaceGuard.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: PlaceGuard, providedIn: 'root' });
|
|
10243
|
+
__decorate([
|
|
10244
|
+
Trace(),
|
|
10245
|
+
__metadata("design:type", Function),
|
|
10246
|
+
__metadata("design:paramtypes", [ActivatedRouteSnapshot, RouterStateSnapshot]),
|
|
10247
|
+
__metadata("design:returntype", Promise)
|
|
10248
|
+
], PlaceGuard.prototype, "canActivate", null);
|
|
10214
10249
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: PlaceGuard, decorators: [{
|
|
10215
10250
|
type: Injectable,
|
|
10216
10251
|
args: [{ providedIn: 'root' }]
|
|
10217
|
-
}], ctorParameters: function () { return [{ type: i1$4.Router }, { type: UrlService }, { type: PlaceRouter }, { type: PlaceHistory }, { type: InteractionService }, { type: i0.Injector }]; } });
|
|
10252
|
+
}], ctorParameters: function () { return [{ type: i1$4.Router }, { type: UrlService }, { type: PlaceRouter }, { type: PlaceHistory }, { type: InteractionService }, { type: i0.Injector }]; }, propDecorators: { canActivate: [] } });
|
|
10218
10253
|
|
|
10219
10254
|
var Formatter;
|
|
10220
10255
|
(function (Formatter) {
|