@coolon/angular-ui-powerups 3.7.0-alpha.2 → 3.7.0-alpha.4

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.
@@ -4,15 +4,18 @@ import { Router, RouterOutlet } from '@angular/router';
4
4
  import { DebugContext, Dsl, lang, ListModel, MutableValueModel, StoreInListModel, StoreInValueModel, Trace, TrackExternal, ValueModel } from '@coolon/pectin';
5
5
  import * as _ from 'lodash';
6
6
  import { DisposableComponent } from '../../../components/disposable-component';
7
+ import { PLACE_AUTH_SERVICE } from '../../place-auth-service';
7
8
  import { PlaceComponent } from '../../place-component';
8
9
  import { AUP_PLACE_CONFIG } from '../../place-config';
9
10
  import { PlaceRouter } from '../../place-router';
11
+ import { Visit } from '../../visit';
10
12
  import { LEFT_RIGHT_PLACE_ANIMATION } from './route-animations';
11
13
  export class PlaceOutletComponent extends DisposableComponent {
12
- constructor(router, placeRouter, placeConfig, parentOutlet) {
14
+ constructor(router, placeRouter, placeAuthService, placeConfig, parentOutlet) {
13
15
  super();
14
16
  this.router = router;
15
17
  this.placeRouter = placeRouter;
18
+ this.placeAuthService = placeAuthService;
16
19
  this.placeConfig = placeConfig;
17
20
  this.placeChanged = new EventEmitter();
18
21
  this.outletActivated = new MutableValueModel(false);
@@ -57,6 +60,13 @@ export class PlaceOutletComponent extends DisposableComponent {
57
60
  chain(this._activePlaceModel)
58
61
  .postponeWhile(this.navigationInProgress)
59
62
  .subscribe(place => this.placeChanged.emit(place));
63
+ when(placeAuthService.authoriserModel).changes(isAuthorised => {
64
+ const activePlace = this._activePlaceModel.value;
65
+ if (activePlace && !isAuthorised(activePlace.placeDefinition)) {
66
+ const visitOrPlace = placeAuthService.handleNotAuthorised(this._activatedRouteModel.value.snapshot, this.router.routerState.snapshot);
67
+ this.placeRouter.navigate(visitOrPlace instanceof Visit ? visitOrPlace : new Visit(PlaceComponent.getDefinition(visitOrPlace)));
68
+ }
69
+ });
60
70
  }
61
71
  // @Trace()
62
72
  ngOnInit() {
@@ -178,6 +188,7 @@ PlaceOutletComponent.decorators = [
178
188
  PlaceOutletComponent.ctorParameters = () => [
179
189
  { type: Router },
180
190
  { type: PlaceRouter },
191
+ { type: undefined, decorators: [{ type: Inject, args: [PLACE_AUTH_SERVICE,] }] },
181
192
  { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [AUP_PLACE_CONFIG,] }] },
182
193
  { type: PlaceOutletComponent, decorators: [{ type: SkipSelf }, { type: Optional }] }
183
194
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"place-outlet.component.js","sourceRoot":"","sources":["../../../../../../../../libs/angular-ui-powerups/src/lib/place/components/place-outlet/place-outlet.component.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAU,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtH,OAAO,EAAkB,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAGL,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAAE,KAAK,EACxB,aAAa,EACb,UAAU,EAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAiBhE,MAAM,OAAO,oBAAqB,SAAQ,mBAAmB;IA2C3D,YAA6B,MAAc,EACd,WAAwB,EACM,WAAwB,EAC/C,YAAkC;QACpE,KAAK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+DAKP","sourcesContent":["import { Component, EventEmitter, Inject, Input, OnInit, Optional, Output, SkipSelf, ViewChild } from '@angular/core';\nimport { ActivatedRoute, Router, RouterOutlet } from '@angular/router';\nimport {\n BooleanValueModelChain,\n Constructable,\n DebugContext,\n Dsl,\n lang,\n ListModel, ListModelChain,\n MutableValueModel,\n StoreInListModel,\n StoreInValueModel, Trace,\n TrackExternal,\n ValueModel,\n ValueModelChain\n} from '@coolon/pectin';\nimport * as _ from 'lodash';\nimport { DisposableComponent } from '../../../components/disposable-component';\nimport { PlaceComponent } from '../../place-component';\nimport { AUP_PLACE_CONFIG, PlaceConfig } from '../../place-config';\nimport { PlaceDefinition } from '../../place-definition';\nimport { PlaceRouter } from '../../place-router';\n\nimport { Visit } from '../../visit';\nimport { LEFT_RIGHT_PLACE_ANIMATION } from './route-animations';\n\n// Quick hack to avoid circular references between this and PlaceComponents.\ninterface PlaceRef {\n readonly placeDefinition: PlaceDefinition\n\n initialiseBindings(param: ValueModel<Visit>): void;\n\n onPlaceReady(): void;\n}\n\n@Component({\n selector: 'aup-place-outlet',\n templateUrl: './place-outlet.component.html',\n styleUrls: ['./place-outlet.component.scss'],\n animations: [LEFT_RIGHT_PLACE_ANIMATION]\n})\nexport class PlaceOutletComponent extends DisposableComponent implements OnInit {\n\n @Input() @StoreInValueModel('animateModel')\n animate: boolean;\n\n @Input() @TrackExternal({ defaultValue: true })\n animateModel: ValueModel<boolean>;\n\n // tslint:disable-next-line:no-input-rename\n @Input('placeAnimationOrderModel') @TrackExternal()\n customPlaceAnimationOrderModel: ListModel<Constructable<PlaceComponent>>;\n\n // tslint:disable-next-line:no-input-rename\n @Input('placeAnimationOrder') @StoreInListModel('customPlaceAnimationOrderModel')\n customPlaceAnimationOrder: Constructable<PlaceComponent>[];\n\n @Output()\n readonly placeChanged = new EventEmitter<PlaceComponent>();\n\n @ViewChild('routeOutlet', { static: true })\n routerOut: RouterOutlet;\n\n private onAnimationFinishedJob: () => void;\n\n\n private outletActivated = new MutableValueModel(false);\n private readonly _activatedRouteModel = new MutableValueModel<ActivatedRoute>();\n private readonly _activePlaceModel = new MutableValueModel<PlaceComponent>();\n private readonly _activePlaceDefinition: ValueModelChain<PlaceDefinition>;\n\n private parentOutletModel: MutableValueModel<PlaceOutletComponent>;\n public readonly activePlaceAnimationPosition: ValueModelChain<number>;\n\n private initialPlaceIndex: number = null;\n private routerVisitModel: ValueModelChain<Visit>;\n private _isPushingVisitToRoute = new MutableValueModel<boolean>(false);\n private navigationInProgress: ValueModelChain<boolean>;\n\n private isVeryFirstLoad = true;\n private placesInAnimationOrder: ListModelChain<Constructable<PlaceComponent>>;\n private animationSupported: BooleanValueModelChain;\n readonly animationEnabled: BooleanValueModelChain;\n\n constructor(private readonly router: Router,\n private readonly placeRouter: PlaceRouter,\n @Optional() @Inject(AUP_PLACE_CONFIG) readonly placeConfig: PlaceConfig,\n @SkipSelf() @Optional() parentOutlet: PlaceOutletComponent) {\n super();\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);\n\n this.parentOutletModel = new MutableValueModel(parentOutlet);\n\n const defaultPlaceAnimationOrder = chain(this.parentOutletModel)\n .pullValueModel(o => o.activePlaceModel)\n .pluck('placeDefinition')\n .pluckList('children')\n .pluck('component');\n\n const activatePlaceType = chain(this.activePlaceModel).map(p => p.constructor as Constructable<PlaceComponent>);\n\n this.placesInAnimationOrder = chain(this.customPlaceAnimationOrderModel)\n .otherwise(defaultPlaceAnimationOrder);\n\n this.activePlaceAnimationPosition = this.placesInAnimationOrder\n .reduce((placesInOrder) => {\n let placeIndex = 0;\n if (activatePlaceType.value) {\n placeIndex = placesInOrder.indexOf(activatePlaceType.value);\n if (_.isNil(this.initialPlaceIndex)) {\n this.initialPlaceIndex = placeIndex;\n }\n }\n return _.isNil(this.initialPlaceIndex) ? 0 : placeIndex - this.initialPlaceIndex;\n }, { dependsOn: activatePlaceType });\n\n this.animationSupported = this.placesInAnimationOrder.count().isGreaterThan(0);\n this.animationEnabled = valueOf.all(\n this.animateModel,\n this.animationSupported\n ).areTruthy();\n\n // Extract our visit model from the place router.\n this._activePlaceDefinition = chain(this._activePlaceModel).pluck('placeDefinition');\n this.routerVisitModel = this._activePlaceDefinition.findIn(chain(placeRouter.activeVisitsByPlaceDefinition));\n\n this.navigationInProgress = chain(this.placeRouter.navigationInProgress);\n\n when(this.navigationInProgress).becomesFalsey(() => {\n this.checkStateAndInitialise();\n });\n when(this.outletActivated).becomesTruthy(() => {\n this.checkStateAndInitialise();\n });\n\n chain(this._activePlaceModel)\n .postponeWhile(this.navigationInProgress)\n .subscribe(place => this.placeChanged.emit(place));\n\n }\n\n // @Trace()\n ngOnInit() {\n }\n\n // @Trace()\n getAnimationOrder() {\n return this.activePlaceAnimationPosition.value;\n }\n\n get animationDuration() {\n return this.placeConfig && this.placeConfig.animationDuration ? this.placeConfig.animationDuration : '500ms';\n }\n\n // @Trace()\n navigate(visit: Visit) {\n // const place = this.placesInAnimationOrder.query().findMatching(p => visit.placeDefinition.component === p);\n // if (!place) {\n // lang.illegalState()\n // }\n this.placeRouter.navigate(visit, {\n relativeTo: this.parentOutlet ? this.parentOutlet.activatedRouteModel.value : null\n });\n }\n\n get parentOutlet(): PlaceOutletComponent {\n return this.parentOutletModel.value;\n }\n\n\n get activePlaceModel(): ValueModel<PlaceComponent> {\n return this._activePlaceModel.readonly;\n }\n\n get activatedRouteModel(): ValueModel<ActivatedRoute> {\n return this._activatedRouteModel.readonly;\n }\n\n @Trace()\n onOutletActivated(routerOutlet: RouterOutlet, place: PlaceComponent) {\n this._activatedRouteModel.value = routerOutlet.activatedRoute;\n this._activePlaceModel.value = place;\n this.validateAnimationState(place);\n this.outletActivated.value = true;\n this.checkStateAndInitialise();\n }\n\n private validateAnimationState(place: PlaceComponent) {\n if (this.animateModel.value) {\n if (this.placesInAnimationOrder.length < 1) {\n console.error('PlaceOutlet.animate === true but placeAnimationOrder has not been set. Animation is disabled.');\n } else {\n if (!this.placesInAnimationOrder.query().includes(place.placeDefinition.component)) {\n console.error(`PlaceOutlet.animate === true but placeAnimationOrder doesn't contain ${place.placeDefinition.component.name}.`);\n }\n }\n }\n }\n\n @Trace()\n onOutletDeactivated() {\n this.outletActivated.value = false;\n this._activePlaceModel.value = null;\n this._activatedRouteModel.value = null;\n }\n\n // @Trace()\n private checkStateAndInitialise() {\n const routerVisit = this.routerVisitModel.value;\n const activePlace = this.activePlaceModel.value;\n if (routerVisit && activePlace && !activePlace.isInitialised()) {\n if (routerVisit.placeDefinition !== activePlace.placeDefinition) {\n lang.illegalState('wrong visit!!!');\n }\n this.initialisePlace(routerVisit, activePlace);\n }\n }\n\n private initialisePlace(routerVisit: Visit, activePlace: PlaceComponent) {\n const visitModel = new MutableValueModel<Visit>(routerVisit);\n DebugContext.tag(visitModel, `PlaceOutletComponent[${activePlace.constructor.name})].visitModel`);\n activePlace.initialiseVisit(routerVisit, (current, previous) => {\n this.pushVisitChangeToRoute(previous, current);\n });\n const finishPlaceLoad = () => {\n this._activePlaceModel.value._notifyActive(true);\n }\n if (!this.animationEnabled.value || this.isVeryFirstLoad) {\n // if animation is disabled or this is the very first load then\n // we won't get our animation done callback so we finish the\n // process here and now.\n this.isVeryFirstLoad = false;\n finishPlaceLoad()\n } else {\n this.onAnimationFinishedJob = finishPlaceLoad;\n }\n const { when, chain, valueOf } = Dsl.disposeWith(activePlace);\n when(this.routerVisitModel)\n .changes(visit => {\n activePlace.updateVisit(visit);\n }, {\n unless: valueOf.any(\n this._isPushingVisitToRoute,\n this.routerVisitModel.isNil()\n ).areTruthy()\n });\n }\n\n private pushVisitChangeToRoute(previous: Visit, current: Visit) {\n this._isPushingVisitToRoute.value = true;\n this.placeRouter.pushVisitChangesToRoute(previous, current).finally(() => {\n this._isPushingVisitToRoute.value = false;\n });\n }\n\n// @Trace()\n animationStarted() {\n // console.log({ activePlace: this._activePlaceModel.value });\n }\n\n // @Trace()\n animationDone() {\n if (this.onAnimationFinishedJob) {\n this.onAnimationFinishedJob();\n this.onAnimationFinishedJob = undefined;\n }\n }\n\n}\n"]}
1
+ {"version":3,"file":"place-outlet.component.js","sourceRoot":"","sources":["../../../../../../../../libs/angular-ui-powerups/src/lib/place/components/place-outlet/place-outlet.component.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAU,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACtH,OAAO,EAAkB,MAAM,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAGL,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAAE,KAAK,EACxB,aAAa,EACb,UAAU,EAEX,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAoB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAe,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAiBhE,MAAM,OAAO,oBAAqB,SAAQ,mBAAmB;IA2C3D,YAA6B,MAAc,EACd,WAAwB,EACI,gBAAkC,EAChC,WAAwB,EAC/C,YAAkC;QACpE,KAAK,EAAE,CAAC;QALmB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAa;QACI,qBAAgB,GAAhB,gBAAgB,CAAkB;QAChC,gBAAW,GAAX,WAAW,CAAa;QA7B1E,iBAAY,GAAG,IAAI,YAAY,EAAkB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K;2BAGL,KAAK;6CAIL,KAAK,SAAC,0BAA0B;wCAIhC,KAAK,SAAC,qBAAqB;2BAG3B,MAAM;wBAGN,SAAS,SAAC,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;;AAhB1C;IADU,iBAAiB,CAAC,cAAc,CAAC;;qDAC1B;AAGjB;IADU,aAAa,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;8BACjC,UAAU;0DAAU;AAIlC;IADoC,aAAa,EAAE;8BACnB,SAAS;4EAAgC;AAIzE;IAD+B,gBAAgB,CAAC,gCAAgC,CAAC;;uEACtB;AAqI3D;IADC,KAAK,EAAE;;qCACwB,YAAY,EAAS,cAAc;;6DAMlE;AAeD;IADC,KAAK,EAAE;;;;+DAKP","sourcesContent":["import { Component, EventEmitter, Inject, Input, OnInit, Optional, Output, SkipSelf, ViewChild } from '@angular/core';\nimport { ActivatedRoute, Router, RouterOutlet } from '@angular/router';\nimport {\n BooleanValueModelChain,\n Constructable,\n DebugContext,\n Dsl,\n lang,\n ListModel, ListModelChain,\n MutableValueModel,\n StoreInListModel,\n StoreInValueModel, Trace,\n TrackExternal,\n ValueModel,\n ValueModelChain\n} from '@coolon/pectin';\nimport * as _ from 'lodash';\nimport { DisposableComponent } from '../../../components/disposable-component';\nimport { PLACE_AUTH_SERVICE, PlaceAuthService } from '../../place-auth-service';\nimport { PlaceComponent } from '../../place-component';\nimport { AUP_PLACE_CONFIG, PlaceConfig } from '../../place-config';\nimport { PlaceDefinition } from '../../place-definition';\nimport { PlaceRouter } from '../../place-router';\n\nimport { Visit } from '../../visit';\nimport { LEFT_RIGHT_PLACE_ANIMATION } from './route-animations';\n\n// Quick hack to avoid circular references between this and PlaceComponents.\ninterface PlaceRef {\n readonly placeDefinition: PlaceDefinition\n\n initialiseBindings(param: ValueModel<Visit>): void;\n\n onPlaceReady(): void;\n}\n\n@Component({\n selector: 'aup-place-outlet',\n templateUrl: './place-outlet.component.html',\n styleUrls: ['./place-outlet.component.scss'],\n animations: [LEFT_RIGHT_PLACE_ANIMATION]\n})\nexport class PlaceOutletComponent extends DisposableComponent implements OnInit {\n\n @Input() @StoreInValueModel('animateModel')\n animate: boolean;\n\n @Input() @TrackExternal({ defaultValue: true })\n animateModel: ValueModel<boolean>;\n\n // tslint:disable-next-line:no-input-rename\n @Input('placeAnimationOrderModel') @TrackExternal()\n customPlaceAnimationOrderModel: ListModel<Constructable<PlaceComponent>>;\n\n // tslint:disable-next-line:no-input-rename\n @Input('placeAnimationOrder') @StoreInListModel('customPlaceAnimationOrderModel')\n customPlaceAnimationOrder: Constructable<PlaceComponent>[];\n\n @Output()\n readonly placeChanged = new EventEmitter<PlaceComponent>();\n\n @ViewChild('routeOutlet', { static: true })\n routerOut: RouterOutlet;\n\n private onAnimationFinishedJob: () => void;\n\n\n private outletActivated = new MutableValueModel(false);\n private readonly _activatedRouteModel = new MutableValueModel<ActivatedRoute>();\n private readonly _activePlaceModel = new MutableValueModel<PlaceComponent>();\n private readonly _activePlaceDefinition: ValueModelChain<PlaceDefinition>;\n\n private parentOutletModel: MutableValueModel<PlaceOutletComponent>;\n public readonly activePlaceAnimationPosition: ValueModelChain<number>;\n\n private initialPlaceIndex: number = null;\n private routerVisitModel: ValueModelChain<Visit>;\n private _isPushingVisitToRoute = new MutableValueModel<boolean>(false);\n private navigationInProgress: ValueModelChain<boolean>;\n\n private isVeryFirstLoad = true;\n private placesInAnimationOrder: ListModelChain<Constructable<PlaceComponent>>;\n private animationSupported: BooleanValueModelChain;\n readonly animationEnabled: BooleanValueModelChain;\n\n constructor(private readonly router: Router,\n private readonly placeRouter: PlaceRouter,\n @Inject(PLACE_AUTH_SERVICE) private readonly placeAuthService: PlaceAuthService,\n @Optional() @Inject(AUP_PLACE_CONFIG) readonly placeConfig: PlaceConfig,\n @SkipSelf() @Optional() parentOutlet: PlaceOutletComponent) {\n super();\n const { chain, valueOf, before, when, after, observe, switchOn } = Dsl.disposeWith(this);\n\n this.parentOutletModel = new MutableValueModel(parentOutlet);\n\n const defaultPlaceAnimationOrder = chain(this.parentOutletModel)\n .pullValueModel(o => o.activePlaceModel)\n .pluck('placeDefinition')\n .pluckList('children')\n .pluck('component');\n\n const activatePlaceType = chain(this.activePlaceModel).map(p => p.constructor as Constructable<PlaceComponent>);\n\n this.placesInAnimationOrder = chain(this.customPlaceAnimationOrderModel)\n .otherwise(defaultPlaceAnimationOrder);\n\n this.activePlaceAnimationPosition = this.placesInAnimationOrder\n .reduce((placesInOrder) => {\n let placeIndex = 0;\n if (activatePlaceType.value) {\n placeIndex = placesInOrder.indexOf(activatePlaceType.value);\n if (_.isNil(this.initialPlaceIndex)) {\n this.initialPlaceIndex = placeIndex;\n }\n }\n return _.isNil(this.initialPlaceIndex) ? 0 : placeIndex - this.initialPlaceIndex;\n }, { dependsOn: activatePlaceType });\n\n this.animationSupported = this.placesInAnimationOrder.count().isGreaterThan(0);\n this.animationEnabled = valueOf.all(\n this.animateModel,\n this.animationSupported\n ).areTruthy();\n\n // Extract our visit model from the place router.\n this._activePlaceDefinition = chain(this._activePlaceModel).pluck('placeDefinition');\n this.routerVisitModel = this._activePlaceDefinition.findIn(chain(placeRouter.activeVisitsByPlaceDefinition));\n\n this.navigationInProgress = chain(this.placeRouter.navigationInProgress);\n\n when(this.navigationInProgress).becomesFalsey(() => {\n this.checkStateAndInitialise();\n });\n when(this.outletActivated).becomesTruthy(() => {\n this.checkStateAndInitialise();\n });\n\n chain(this._activePlaceModel)\n .postponeWhile(this.navigationInProgress)\n .subscribe(place => this.placeChanged.emit(place));\n\n when(placeAuthService.authoriserModel).changes(isAuthorised => {\n const activePlace = this._activePlaceModel.value;\n if (activePlace && !isAuthorised(activePlace.placeDefinition)) {\n const visitOrPlace = placeAuthService.handleNotAuthorised(this._activatedRouteModel.value.snapshot, this.router.routerState.snapshot);\n this.placeRouter.navigate(visitOrPlace instanceof Visit ? visitOrPlace : new Visit(PlaceComponent.getDefinition(visitOrPlace)))\n }\n });\n\n }\n\n // @Trace()\n ngOnInit() {\n }\n\n // @Trace()\n getAnimationOrder() {\n return this.activePlaceAnimationPosition.value;\n }\n\n get animationDuration() {\n return this.placeConfig && this.placeConfig.animationDuration ? this.placeConfig.animationDuration : '500ms';\n }\n\n // @Trace()\n navigate(visit: Visit) {\n // const place = this.placesInAnimationOrder.query().findMatching(p => visit.placeDefinition.component === p);\n // if (!place) {\n // lang.illegalState()\n // }\n this.placeRouter.navigate(visit, {\n relativeTo: this.parentOutlet ? this.parentOutlet.activatedRouteModel.value : null\n });\n }\n\n get parentOutlet(): PlaceOutletComponent {\n return this.parentOutletModel.value;\n }\n\n\n get activePlaceModel(): ValueModel<PlaceComponent> {\n return this._activePlaceModel.readonly;\n }\n\n get activatedRouteModel(): ValueModel<ActivatedRoute> {\n return this._activatedRouteModel.readonly;\n }\n\n @Trace()\n onOutletActivated(routerOutlet: RouterOutlet, place: PlaceComponent) {\n this._activatedRouteModel.value = routerOutlet.activatedRoute;\n this._activePlaceModel.value = place;\n this.validateAnimationState(place);\n this.outletActivated.value = true;\n this.checkStateAndInitialise();\n }\n\n private validateAnimationState(place: PlaceComponent) {\n if (this.animateModel.value) {\n if (this.placesInAnimationOrder.length < 1) {\n console.error('PlaceOutlet.animate === true but placeAnimationOrder has not been set. Animation is disabled.');\n } else {\n if (!this.placesInAnimationOrder.query().includes(place.placeDefinition.component)) {\n console.error(`PlaceOutlet.animate === true but placeAnimationOrder doesn't contain ${place.placeDefinition.component.name}.`);\n }\n }\n }\n }\n\n @Trace()\n onOutletDeactivated() {\n this.outletActivated.value = false;\n this._activePlaceModel.value = null;\n this._activatedRouteModel.value = null;\n }\n\n // @Trace()\n private checkStateAndInitialise() {\n const routerVisit = this.routerVisitModel.value;\n const activePlace = this.activePlaceModel.value;\n if (routerVisit && activePlace && !activePlace.isInitialised()) {\n if (routerVisit.placeDefinition !== activePlace.placeDefinition) {\n lang.illegalState('wrong visit!!!');\n }\n this.initialisePlace(routerVisit, activePlace);\n }\n }\n\n private initialisePlace(routerVisit: Visit, activePlace: PlaceComponent) {\n const visitModel = new MutableValueModel<Visit>(routerVisit);\n DebugContext.tag(visitModel, `PlaceOutletComponent[${activePlace.constructor.name})].visitModel`);\n activePlace.initialiseVisit(routerVisit, (current, previous) => {\n this.pushVisitChangeToRoute(previous, current);\n });\n const finishPlaceLoad = () => {\n this._activePlaceModel.value._notifyActive(true);\n }\n if (!this.animationEnabled.value || this.isVeryFirstLoad) {\n // if animation is disabled or this is the very first load then\n // we won't get our animation done callback so we finish the\n // process here and now.\n this.isVeryFirstLoad = false;\n finishPlaceLoad()\n } else {\n this.onAnimationFinishedJob = finishPlaceLoad;\n }\n const { when, chain, valueOf } = Dsl.disposeWith(activePlace);\n when(this.routerVisitModel)\n .changes(visit => {\n activePlace.updateVisit(visit);\n }, {\n unless: valueOf.any(\n this._isPushingVisitToRoute,\n this.routerVisitModel.isNil()\n ).areTruthy()\n });\n }\n\n private pushVisitChangeToRoute(previous: Visit, current: Visit) {\n this._isPushingVisitToRoute.value = true;\n this.placeRouter.pushVisitChangesToRoute(previous, current).finally(() => {\n this._isPushingVisitToRoute.value = false;\n });\n }\n\n// @Trace()\n animationStarted() {\n // console.log({ activePlace: this._activePlaceModel.value });\n }\n\n // @Trace()\n animationDone() {\n if (this.onAnimationFinishedJob) {\n this.onAnimationFinishedJob();\n this.onAnimationFinishedJob = undefined;\n }\n }\n\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"PlaceOutletComponent":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"../../../components/disposable-component","name":"DisposableComponent","line":41,"character":42},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":35,"character":1},"arguments":[{"selector":"aup-place-outlet","animations":[{"__symbolic":"reference","module":"./route-animations","name":"LEFT_RIGHT_PLACE_ANIMATION","line":39,"character":15}],"template":"<ng-container *ngIf=\"animationEnabled.value\">\n <div class=\"router-outlet-container\" cdkScrollable\n [@routeAnimations]=\"{value: getAnimationOrder(), params:{duration: animationDuration}}\"\n (@routeAnimations.start)=\"animationStarted()\"\n (@routeAnimations.done)=\"animationDone()\"\n >\n <router-outlet #routerOutlet=\"outlet\"\n (activate)=\"onOutletActivated(routerOutlet, $event)\"\n (deactivate)=\"onOutletDeactivated()\">\n </router-outlet>\n </div>\n</ng-container>\n\n<ng-container *ngIf=\"!animationEnabled.value\">\n <div class=\"router-outlet-container\" cdkScrollable>\n <router-outlet #routerOutlet=\"outlet\"\n (activate)=\"onOutletActivated(routerOutlet, $event)\"\n (deactivate)=\"onOutletDeactivated()\">\n </router-outlet>\n </div>\n</ng-container>\n\n","styles":[":host{display:flex;flex-direction:column;min-height:0}.router-outlet-container{display:block;flex:1;min-height:0;overflow-x:hidden;overflow-y:scroll;position:relative}router-outlet{display:none}"]}]}],"members":{"animate":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":43,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInValueModel","line":43,"character":12},"arguments":["animateModel"]}]}],"animateModel":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":46,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":46,"character":12},"arguments":[{"defaultValue":true}]}]}],"customPlaceAnimationOrderModel":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":50,"character":3},"arguments":["placeAnimationOrderModel"]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":50,"character":38}}]}],"customPlaceAnimationOrder":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":54,"character":3},"arguments":["placeAnimationOrder"]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInListModel","line":54,"character":33},"arguments":["customPlaceAnimationOrderModel"]}]}],"placeChanged":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":57,"character":3}}]}],"routerOut":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":60,"character":3},"arguments":["routeOutlet",{"static":true}]}]}],"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":86,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":86,"character":27},"arguments":[{"__symbolic":"reference","module":"../../place-config","name":"AUP_PLACE_CONFIG","line":86,"character":34}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":87,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":87,"character":27}}]],"parameters":[{"__symbolic":"reference","module":"@angular/router","name":"Router","line":84,"character":39},{"__symbolic":"reference","module":"../../place-router","name":"PlaceRouter","line":85,"character":44},{"__symbolic":"reference","module":"../../place-config","name":"PlaceConfig","line":86,"character":74},{"__symbolic":"reference","name":"PlaceOutletComponent"}]}],"ngOnInit":[{"__symbolic":"method"}],"getAnimationOrder":[{"__symbolic":"method"}],"navigate":[{"__symbolic":"method"}],"onOutletActivated":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":178,"character":3}}]}],"validateAnimationState":[{"__symbolic":"method"}],"onOutletDeactivated":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":199,"character":3}}]}],"checkStateAndInitialise":[{"__symbolic":"method"}],"initialisePlace":[{"__symbolic":"method"}],"pushVisitChangeToRoute":[{"__symbolic":"method"}],"animationStarted":[{"__symbolic":"method"}],"animationDone":[{"__symbolic":"method"}]}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"PlaceOutletComponent":{"__symbolic":"class","extends":{"__symbolic":"reference","module":"../../../components/disposable-component","name":"DisposableComponent","line":42,"character":42},"decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":36,"character":1},"arguments":[{"selector":"aup-place-outlet","animations":[{"__symbolic":"reference","module":"./route-animations","name":"LEFT_RIGHT_PLACE_ANIMATION","line":40,"character":15}],"template":"<ng-container *ngIf=\"animationEnabled.value\">\n <div class=\"router-outlet-container\" cdkScrollable\n [@routeAnimations]=\"{value: getAnimationOrder(), params:{duration: animationDuration}}\"\n (@routeAnimations.start)=\"animationStarted()\"\n (@routeAnimations.done)=\"animationDone()\"\n >\n <router-outlet #routerOutlet=\"outlet\"\n (activate)=\"onOutletActivated(routerOutlet, $event)\"\n (deactivate)=\"onOutletDeactivated()\">\n </router-outlet>\n </div>\n</ng-container>\n\n<ng-container *ngIf=\"!animationEnabled.value\">\n <div class=\"router-outlet-container\" cdkScrollable>\n <router-outlet #routerOutlet=\"outlet\"\n (activate)=\"onOutletActivated(routerOutlet, $event)\"\n (deactivate)=\"onOutletDeactivated()\">\n </router-outlet>\n </div>\n</ng-container>\n\n","styles":[":host{display:flex;flex-direction:column;min-height:0}.router-outlet-container{display:block;flex:1;min-height:0;overflow-x:hidden;overflow-y:scroll;position:relative}router-outlet{display:none}"]}]}],"members":{"animate":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":44,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInValueModel","line":44,"character":12},"arguments":["animateModel"]}]}],"animateModel":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":47,"character":3}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":47,"character":12},"arguments":[{"defaultValue":true}]}]}],"customPlaceAnimationOrderModel":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":51,"character":3},"arguments":["placeAnimationOrderModel"]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"TrackExternal","line":51,"character":38}}]}],"customPlaceAnimationOrder":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":55,"character":3},"arguments":["placeAnimationOrder"]},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"StoreInListModel","line":55,"character":33},"arguments":["customPlaceAnimationOrderModel"]}]}],"placeChanged":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":58,"character":3}}]}],"routerOut":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"ViewChild","line":61,"character":3},"arguments":["routeOutlet",{"static":true}]}]}],"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":87,"character":15},"arguments":[{"__symbolic":"reference","module":"../../place-auth-service","name":"PLACE_AUTH_SERVICE","line":87,"character":22}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":88,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":88,"character":27},"arguments":[{"__symbolic":"reference","module":"../../place-config","name":"AUP_PLACE_CONFIG","line":88,"character":34}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"SkipSelf","line":89,"character":15}},{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Optional","line":89,"character":27}}]],"parameters":[{"__symbolic":"reference","module":"@angular/router","name":"Router","line":85,"character":39},{"__symbolic":"reference","module":"../../place-router","name":"PlaceRouter","line":86,"character":44},{"__symbolic":"reference","module":"../../place-auth-service","name":"PlaceAuthService","line":87,"character":77},{"__symbolic":"reference","module":"../../place-config","name":"PlaceConfig","line":88,"character":74},{"__symbolic":"reference","name":"PlaceOutletComponent"}]}],"ngOnInit":[{"__symbolic":"method"}],"getAnimationOrder":[{"__symbolic":"method"}],"navigate":[{"__symbolic":"method"}],"onOutletActivated":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":188,"character":3}}]}],"validateAnimationState":[{"__symbolic":"method"}],"onOutletDeactivated":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":209,"character":3}}]}],"checkStateAndInitialise":[{"__symbolic":"method"}],"initialisePlace":[{"__symbolic":"method"}],"pushVisitChangeToRoute":[{"__symbolic":"method"}],"animationStarted":[{"__symbolic":"method"}],"animationDone":[{"__symbolic":"method"}]}}}}]
@@ -1,7 +1,7 @@
1
- import { __awaiter, __decorate, __metadata } from "tslib";
1
+ import { __awaiter } from "tslib";
2
2
  import { Inject, Injectable, Injector } from '@angular/core';
3
- import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
4
- import { lang, Trace } from '@coolon/pectin';
3
+ import { Router } from '@angular/router';
4
+ import { lang } from '@coolon/pectin';
5
5
  import { InteractionService } from '../../interaction/services/interaction.service';
6
6
  import { PLACE_AUTH_SERVICE } from '../place-auth-service';
7
7
  import { PlaceComponent } from '../place-component';
@@ -29,17 +29,28 @@ export class PlaceGuard {
29
29
  this.interactionService = interactionService;
30
30
  this.injector = injector;
31
31
  }
32
+ // @Trace()
32
33
  canActivate(activatedRoute, state) {
33
34
  return __awaiter(this, void 0, void 0, function* () {
34
35
  if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {
35
36
  const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);
36
- const needsAuth = placeDefinition.authenticate;
37
- const proceed = !needsAuth || (yield this.placeAuthService.isAuthenticated());
38
- if (!proceed) {
39
- return this.handleGuardResult(this.placeAuthService.handleNotAuthenticated(activatedRoute, state));
40
- }
41
- if (!this.placeAuthService.isAuthorised(placeDefinition)) {
42
- return this.handleGuardResult(this.placeAuthService.handleNotAuthorised(activatedRoute, state));
37
+ if (placeDefinition.authenticate) {
38
+ if (!(yield this.placeAuthService.isAuthenticated())) {
39
+ const redirectLocation = this.placeAuthService.handleNotAuthenticated(activatedRoute, state);
40
+ const nextPlaceDef = this.getPlaceDefinition(redirectLocation);
41
+ if (nextPlaceDef.authenticate) {
42
+ lang.illegalState(`handleNotAuthenticated hook returned place ${nextPlaceDef.component.name} that requires authentication.`);
43
+ }
44
+ return this.createUrlTree(redirectLocation);
45
+ }
46
+ if (!this.placeAuthService.isAuthorised(placeDefinition)) {
47
+ const redirectLocation = this.placeAuthService.handleNotAuthorised(activatedRoute, state);
48
+ const nextPlaceDef = this.getPlaceDefinition(redirectLocation);
49
+ if (!this.placeAuthService.isAuthorised(nextPlaceDef)) {
50
+ lang.illegalState(`handleNotAuthorised hook returned place ${nextPlaceDef.component.name} that is not authorised for the current user.`);
51
+ }
52
+ return this.createUrlTree(redirectLocation);
53
+ }
43
54
  }
44
55
  const result = yield this.cleanInteractionState(activatedRoute, state, () => __awaiter(this, void 0, void 0, function* () {
45
56
  // Parse our route params.
@@ -68,6 +79,7 @@ export class PlaceGuard {
68
79
  }
69
80
  });
70
81
  }
82
+ // @Trace()
71
83
  canDeactivate(component, currentRoute, currentState, nextState) {
72
84
  return __awaiter(this, void 0, void 0, function* () {
73
85
  const currentUrl = this.urlService.parseUrl(currentState.url);
@@ -76,13 +88,14 @@ export class PlaceGuard {
76
88
  return result instanceof UrlSnapshot ? result.urlTree : result;
77
89
  });
78
90
  }
79
- handleGuardResult(result) {
80
- if (result instanceof UrlSnapshot) {
81
- return result.urlTree;
82
- }
83
- else {
84
- return this.urlService.createUrlSnapshot(result).urlTree;
85
- }
91
+ getPlaceDefinition(result) {
92
+ return result instanceof Visit ?
93
+ result.placeDefinition :
94
+ PlaceComponent.getDefinition(result);
95
+ }
96
+ createUrlTree(result) {
97
+ const visit = result instanceof Visit ? result : new Visit(PlaceComponent.getDefinition(result), {});
98
+ return this.urlService.createUrlSnapshot(visit).urlTree;
86
99
  }
87
100
  // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {
88
101
  // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;
@@ -105,6 +118,7 @@ export class PlaceGuard {
105
118
  // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;
106
119
  // }
107
120
  // abstract getAuthGuard(injector: Injector): CanActivate;
121
+ // @Trace()
108
122
  cleanInteractionState(route, state, next) {
109
123
  return __awaiter(this, void 0, void 0, function* () {
110
124
  const url = this.urlService.parseUrl(state.url);
@@ -132,28 +146,4 @@ PlaceGuard.ctorParameters = () => [
132
146
  { type: InteractionService },
133
147
  { type: Injector }
134
148
  ];
135
- __decorate([
136
- Trace(),
137
- __metadata("design:type", Function),
138
- __metadata("design:paramtypes", [ActivatedRouteSnapshot, RouterStateSnapshot]),
139
- __metadata("design:returntype", Promise)
140
- ], PlaceGuard.prototype, "canActivate", null);
141
- __decorate([
142
- Trace(),
143
- __metadata("design:type", Function),
144
- __metadata("design:paramtypes", [PlaceComponent, ActivatedRouteSnapshot, RouterStateSnapshot, RouterStateSnapshot]),
145
- __metadata("design:returntype", Promise)
146
- ], PlaceGuard.prototype, "canDeactivate", null);
147
- __decorate([
148
- Trace(),
149
- __metadata("design:type", Function),
150
- __metadata("design:paramtypes", [Object]),
151
- __metadata("design:returntype", void 0)
152
- ], PlaceGuard.prototype, "handleGuardResult", null);
153
- __decorate([
154
- Trace(),
155
- __metadata("design:type", Function),
156
- __metadata("design:paramtypes", [ActivatedRouteSnapshot, RouterStateSnapshot, Function]),
157
- __metadata("design:returntype", Promise)
158
- ], PlaceGuard.prototype, "cleanInteractionState", null);
159
149
  //# sourceMappingURL=place.guard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"place.guard.js","sourceRoot":"","sources":["../../../../../../../libs/angular-ui-powerups/src/lib/place/guards/place.guard.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,sBAAsB,EAGtB,MAAM,EACN,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAoB,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;;;;;;;;AAGpE,MAAM,OAAO,UAAU;IAGrB,YAA6B,MAAc,EACvB,UAAsB,EACb,WAAwB,EACxB,YAA0B,EACE,gBAAkC,EAC9D,kBAAsC,EACtC,QAAkB;QANlB,WAAM,GAAN,MAAM,CAAQ;QACvB,eAAU,GAAV,UAAU,CAAY;QACb,gBAAW,GAAX,WAAW,CAAa;QACxB,iBAAY,GAAZ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KAAK,EAAE;;qCAC0B,sBAAsB,EAAS,mBAAmB;;6CA0CnF;AAGD;IADC,KAAK,EAAE;;qCACuB,cAAc,EAAgB,sBAAsB,EAAgB,mBAAmB,EAAc,mBAAmB;;+CAKtJ;AAGD;IADC,KAAK,EAAE;;;;mDAOP;AA2BD;IADC,KAAK,EAAE;;qCAC2B,sBAAsB,EAAS,mBAAmB;;uDASpF","sourcesContent":["import { Inject, Injectable, Injector } from '@angular/core';\nimport {\n ActivatedRouteSnapshot,\n CanActivate,\n CanDeactivate,\n Router,\n RouterStateSnapshot,\n UrlTree\n} from '@angular/router';\nimport { lang, Trace } from '@coolon/pectin';\nimport { InteractionService } from '../../interaction/services/interaction.service';\nimport { PLACE_AUTH_SERVICE, PlaceAuthService } from '../place-auth-service';\nimport { PlaceComponent } from '../place-component';\nimport { PlaceHistory } from '../place-history';\nimport { PlaceRouter } from '../place-router';\nimport { VisitSanitiser } from '../route/visit-sanitiser';\nimport { UrlService } from '../url-service';\nimport { UrlSnapshot } from '../url-snapshot';\nimport { Visit } from '../visit';\nimport { ConsolidatedParameterMap } from './consolidated-param-map';\n\n@Injectable({ providedIn: 'root' })\nexport class PlaceGuard implements CanActivate, CanDeactivate<PlaceComponent> {\n\n\n constructor(private readonly router: Router,\n private urlService: UrlService,\n private readonly placeRouter: PlaceRouter,\n private readonly placeHistory: PlaceHistory,\n @Inject(PLACE_AUTH_SERVICE) private readonly placeAuthService: PlaceAuthService,\n private readonly interactionService: InteractionService,\n private readonly injector: Injector) {\n }\n\n @Trace()\n async canActivate(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {\n\n if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {\n const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);\n\n const needsAuth = placeDefinition.authenticate;\n\n const proceed = !needsAuth || await this.placeAuthService.isAuthenticated();\n if (!proceed) {\n return this.handleGuardResult(this.placeAuthService.handleNotAuthenticated(activatedRoute, state));\n }\n\n if (!this.placeAuthService.isAuthorised(placeDefinition)) {\n return this.handleGuardResult(this.placeAuthService.handleNotAuthorised(activatedRoute, state));\n }\n\n const result = await this.cleanInteractionState(activatedRoute, state, async () => {\n // Parse our route params.\n const params = new ConsolidatedParameterMap(activatedRoute.paramMap, activatedRoute.url);\n const parsedParams = placeDefinition.parseRouteParams(params);\n\n const navigationSession = this.placeRouter.navigationSession;\n const initialVisit = navigationSession.getVisitFor(placeDefinition) || new Visit(placeDefinition, parsedParams);\n const sanitiser = new VisitSanitiser(navigationSession, activatedRoute, this.router, this.placeHistory, this.injector);\n const sanitisedVisit = await sanitiser.sanitise(initialVisit.mergeRouteParameters(parsedParams));\n\n // Save the visit with any updated parameters. We need to save it so we remember any non route parameters\n navigationSession.storeVisit(sanitisedVisit);\n if (initialVisit.hasRoutingChangedFrom(sanitisedVisit)) {\n // Regenerate the url\n const urlSnapshot = this.urlService.parseUrl(state.url).updateVisitSegments(sanitisedVisit);\n // console.log('##### Place Guard Redirect', urlSnapshot);\n return urlSnapshot;\n } else {\n return true;\n }\n });\n return result instanceof UrlSnapshot ? result.urlTree : result;\n\n } else {\n return lang.illegalState(`expected component to be an instance of PlaceComponent, got ${activatedRoute.component}`);\n }\n }\n\n @Trace()\n async canDeactivate(component: PlaceComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Promise<boolean | UrlTree> {\n const currentUrl = this.urlService.parseUrl(currentState.url);\n const nextUrl = this.urlService.parseUrl(nextState.url);\n const result = await this.placeRouter.navigationSession.canDeactivatePlace(component, currentUrl, nextUrl);\n return result instanceof UrlSnapshot ? result.urlTree : result;\n }\n\n @Trace()\n private handleGuardResult(result: UrlSnapshot | Visit) {\n if (result instanceof UrlSnapshot) {\n return result.urlTree;\n } else {\n return this.urlService.createUrlSnapshot(result).urlTree\n }\n }\n\n // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {\n // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;\n // if (authoriseResult === true) {\n // // we're authorised, now run the place guards.\n // return next(placeDefinition);\n // } else {\n // console.log('not authorised result', authoriseResult);\n // return authoriseResult;\n // }\n // }\n //\n // // @Trace()\n // protected async ensureAuthorisedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {\n //\n // }\n\n // @Trace()\n // async isAuthorised(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {\n // const authorised = this.getAuthGuard(this.injector).canActivate(activatedRoute, state);\n // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;\n // }\n\n // abstract getAuthGuard(injector: Injector): CanActivate;\n\n @Trace()\n async cleanInteractionState(route: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: () => Promise<boolean | UrlSnapshot>): Promise<boolean | UrlSnapshot> {\n const url = this.urlService.parseUrl(state.url);\n if (!this.interactionService.isActive() && url.hasInteractions()) {\n // This happens if we reload the page or the url was pasted as the route should only be activated\n // after the interaction context has become active.\n return url.removeInteractionIds();\n } else {\n return next();\n }\n }\n\n}\n"]}
1
+ {"version":3,"file":"place.guard.js","sourceRoot":"","sources":["../../../../../../../libs/angular-ui-powerups/src/lib/place/guards/place.guard.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAIL,MAAM,EAGP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAiB,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gDAAgD,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAoB,MAAM,uBAAuB,CAAC;AAC7E,OAAO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AAU,SAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;YAjBhC,MAAM;YAYC,UAAU;YAFV,WAAW;YADX,YAAY;4CAgBN,MAAM,SAAC,kBAAkB;YApB/B,kBAAkB;YAVE,QAAQ","sourcesContent":["import { Inject, Injectable, Injector } from '@angular/core';\nimport {\n ActivatedRouteSnapshot,\n CanActivate,\n CanDeactivate,\n Router,\n RouterStateSnapshot,\n UrlTree\n} from '@angular/router';\nimport { Constructable, lang } from '@coolon/pectin';\nimport { InteractionService } from '../../interaction/services/interaction.service';\nimport { PLACE_AUTH_SERVICE, PlaceAuthService } from '../place-auth-service';\nimport { PlaceComponent } from '../place-component';\nimport { PlaceDefinition } from '../place-definition';\nimport { PlaceHistory } from '../place-history';\nimport { PlaceRouter } from '../place-router';\nimport { VisitSanitiser } from '../route/visit-sanitiser';\nimport { UrlService } from '../url-service';\nimport { UrlSnapshot } from '../url-snapshot';\nimport { Visit } from '../visit';\nimport { ConsolidatedParameterMap } from './consolidated-param-map';\n\n@Injectable({ providedIn: 'root' })\nexport class PlaceGuard implements CanActivate, CanDeactivate<PlaceComponent> {\n\n\n constructor(private readonly router: Router,\n private urlService: UrlService,\n private readonly placeRouter: PlaceRouter,\n private readonly placeHistory: PlaceHistory,\n @Inject(PLACE_AUTH_SERVICE) private readonly placeAuthService: PlaceAuthService,\n private readonly interactionService: InteractionService,\n private readonly injector: Injector) {\n }\n\n // @Trace()\n async canActivate(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {\n\n if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {\n const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);\n\n if (placeDefinition.authenticate) {\n\n if (!await this.placeAuthService.isAuthenticated()) {\n const redirectLocation = this.placeAuthService.handleNotAuthenticated(activatedRoute, state);\n const nextPlaceDef = this.getPlaceDefinition(redirectLocation);\n if (nextPlaceDef.authenticate) {\n lang.illegalState(`handleNotAuthenticated hook returned place ${nextPlaceDef.component.name} that requires authentication.`);\n }\n return this.createUrlTree(redirectLocation);\n }\n\n if (!this.placeAuthService.isAuthorised(placeDefinition)) {\n const redirectLocation = this.placeAuthService.handleNotAuthorised(activatedRoute, state);\n const nextPlaceDef = this.getPlaceDefinition(redirectLocation);\n if (!this.placeAuthService.isAuthorised(nextPlaceDef)) {\n lang.illegalState(`handleNotAuthorised hook returned place ${nextPlaceDef.component.name} that is not authorised for the current user.`);\n }\n return this.createUrlTree(redirectLocation);\n }\n }\n\n const result = await this.cleanInteractionState(activatedRoute, state, async () => {\n // Parse our route params.\n const params = new ConsolidatedParameterMap(activatedRoute.paramMap, activatedRoute.url);\n const parsedParams = placeDefinition.parseRouteParams(params);\n\n const navigationSession = this.placeRouter.navigationSession;\n const initialVisit = navigationSession.getVisitFor(placeDefinition) || new Visit(placeDefinition, parsedParams);\n const sanitiser = new VisitSanitiser(navigationSession, activatedRoute, this.router, this.placeHistory, this.injector);\n const sanitisedVisit = await sanitiser.sanitise(initialVisit.mergeRouteParameters(parsedParams));\n\n // Save the visit with any updated parameters. We need to save it so we remember any non route parameters\n navigationSession.storeVisit(sanitisedVisit);\n if (initialVisit.hasRoutingChangedFrom(sanitisedVisit)) {\n // Regenerate the url\n const urlSnapshot = this.urlService.parseUrl(state.url).updateVisitSegments(sanitisedVisit);\n // console.log('##### Place Guard Redirect', urlSnapshot);\n return urlSnapshot;\n } else {\n return true;\n }\n });\n return result instanceof UrlSnapshot ? result.urlTree : result;\n\n } else {\n return lang.illegalState(`expected component to be an instance of PlaceComponent, got ${activatedRoute.component}`);\n }\n }\n\n // @Trace()\n async canDeactivate(component: PlaceComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Promise<boolean | UrlTree> {\n const currentUrl = this.urlService.parseUrl(currentState.url);\n const nextUrl = this.urlService.parseUrl(nextState.url);\n const result = await this.placeRouter.navigationSession.canDeactivatePlace(component, currentUrl, nextUrl);\n return result instanceof UrlSnapshot ? result.urlTree : result;\n }\n\n private getPlaceDefinition(result: Constructable<PlaceComponent> | Visit): PlaceDefinition {\n return result instanceof Visit ?\n result.placeDefinition :\n PlaceComponent.getDefinition(result);\n }\n\n private createUrlTree(result: Constructable<PlaceComponent> | Visit) {\n const visit = result instanceof Visit ? result : new Visit(PlaceComponent.getDefinition(result), {});\n return this.urlService.createUrlSnapshot(visit).urlTree;\n }\n\n // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {\n // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;\n // if (authoriseResult === true) {\n // // we're authorised, now run the place guards.\n // return next(placeDefinition);\n // } else {\n // console.log('not authorised result', authoriseResult);\n // return authoriseResult;\n // }\n // }\n //\n // // @Trace()\n // protected async ensureAuthorisedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {\n //\n // }\n\n // @Trace()\n // async isAuthorised(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {\n // const authorised = this.getAuthGuard(this.injector).canActivate(activatedRoute, state);\n // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;\n // }\n\n // abstract getAuthGuard(injector: Injector): CanActivate;\n\n // @Trace()\n async cleanInteractionState(route: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: () => Promise<boolean | UrlSnapshot>): Promise<boolean | UrlSnapshot> {\n const url = this.urlService.parseUrl(state.url);\n if (!this.interactionService.isActive() && url.hasInteractions()) {\n // This happens if we reload the page or the url was pasted as the route should only be activated\n // after the interaction context has become active.\n return url.removeInteractionIds();\n } else {\n return next();\n }\n }\n\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"PlaceGuard":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":21,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":29,"character":15},"arguments":[{"__symbolic":"reference","module":"../place-auth-service","name":"PLACE_AUTH_SERVICE","line":29,"character":22}]}],null,null],"parameters":[{"__symbolic":"reference","module":"@angular/router","name":"Router","line":25,"character":39},{"__symbolic":"reference","module":"../url-service","name":"UrlService","line":26,"character":34},{"__symbolic":"reference","module":"../place-router","name":"PlaceRouter","line":27,"character":44},{"__symbolic":"reference","module":"../place-history","name":"PlaceHistory","line":28,"character":45},{"__symbolic":"reference","module":"../place-auth-service","name":"PlaceAuthService","line":29,"character":77},{"__symbolic":"reference","module":"../../interaction/services/interaction.service","name":"InteractionService","line":30,"character":51},{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":31,"character":41}]}],"canActivate":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":34,"character":3}}]}],"canDeactivate":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":79,"character":3}}]}],"handleGuardResult":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":87,"character":3}}]}],"cleanInteractionState":[{"__symbolic":"method","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@coolon/pectin","name":"Trace","line":120,"character":3}}]}]},"statics":{"ɵprov":{}}}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"PlaceGuard":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":22,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[null,null,null,null,[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":30,"character":15},"arguments":[{"__symbolic":"reference","module":"../place-auth-service","name":"PLACE_AUTH_SERVICE","line":30,"character":22}]}],null,null],"parameters":[{"__symbolic":"reference","module":"@angular/router","name":"Router","line":26,"character":39},{"__symbolic":"reference","module":"../url-service","name":"UrlService","line":27,"character":34},{"__symbolic":"reference","module":"../place-router","name":"PlaceRouter","line":28,"character":44},{"__symbolic":"reference","module":"../place-history","name":"PlaceHistory","line":29,"character":45},{"__symbolic":"reference","module":"../place-auth-service","name":"PlaceAuthService","line":30,"character":77},{"__symbolic":"reference","module":"../../interaction/services/interaction.service","name":"InteractionService","line":31,"character":51},{"__symbolic":"reference","module":"@angular/core","name":"Injector","line":32,"character":41}]}],"canActivate":[{"__symbolic":"method"}],"canDeactivate":[{"__symbolic":"method"}],"getPlaceDefinition":[{"__symbolic":"method"}],"createUrlTree":[{"__symbolic":"method"}],"cleanInteractionState":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}}}}]
@@ -1 +1 @@
1
- {"version":3,"file":"place-auth-service.js","sourceRoot":"","sources":["../../../../../../libs/angular-ui-powerups/src/lib/place/place-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,cAAc,CAAmB,kBAAkB,CAAC,CAAA","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\nimport { ValueModel } from '@coolon/pectin';\nimport { PlaceDefinition } from './place-definition';\nimport { UrlSnapshot } from './url-snapshot';\nimport { Visit } from './visit';\n\nexport const PLACE_AUTH_SERVICE = new InjectionToken<PlaceAuthService>(\"PlaceAuthService\")\n\n\n/**\n * This interface provides auth services to the routing layer and splits authn and authz into two\n * separate calls so that authentication can be promised based where as authorisation is not. This\n * allows components to check authorisation without having to deal with the promised based nature\n * of authentication.\n */\nexport interface PlaceAuthService {\n\n /**\n * An observable model containing the authoriser function. This allows places to react to changes\n * in permissions when any underlying auth logic changes, e.g. a role being removed from a user.\n */\n readonly authoriserModel: ValueModel<PlaceAuthService.AuthoriserCallback>;\n\n /**\n * Checks if the current user is authenticated. If true the router will proceed to\n * check if the user is authorised. Otherwise it will invoke #handleAuthenticatedFailure.\n */\n isAuthenticated(): boolean | Promise<boolean>;\n\n /**\n * Checks if the current user is authorised. If true the router will proceed to route sanitisation\n * and view loading, otherwise it will invoke #handleAuthorisationFailure.\n * @param placeDefinition\n */\n isAuthorised(placeDefinition: PlaceDefinition): boolean;\n\n handleNotAuthenticated(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): UrlSnapshot | Visit;\n\n handleNotAuthorised(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): UrlSnapshot | Visit;\n}\n\nexport namespace PlaceAuthService {\n export type AuthoriserCallback = (placeDef: PlaceDefinition) => boolean;\n}\n"]}
1
+ {"version":3,"file":"place-auth-service.js","sourceRoot":"","sources":["../../../../../../libs/angular-ui-powerups/src/lib/place/place-auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAQ/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,cAAc,CAAmB,kBAAkB,CAAC,CAAA","sourcesContent":["import { InjectionToken } from '@angular/core';\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\nimport { Constructable, ValueModel } from '@coolon/pectin';\nimport { PlaceComponent } from './place-component';\nimport { PlaceDefinition } from './place-definition';\nimport { UrlSnapshot } from './url-snapshot';\nimport { Visit } from './visit';\n\nexport const PLACE_AUTH_SERVICE = new InjectionToken<PlaceAuthService>(\"PlaceAuthService\")\n\n\n/**\n * This interface provides auth services to the routing layer and splits authn and authz into two\n * separate calls so that authentication can be promised based where as authorisation is not. This\n * allows components to check authorisation without having to deal with the promised based nature\n * of authentication.\n */\nexport interface PlaceAuthService {\n\n /**\n * An observable model containing the authoriser function. This allows places to react to changes\n * in permissions when any underlying auth logic changes, e.g. a role being removed from a user.\n */\n readonly authoriserModel: ValueModel<PlaceAuthService.AuthoriserCallback>;\n\n /**\n * Checks if the current user is authenticated. If true the router will proceed to\n * check if the user is authorised. Otherwise it will invoke #handleAuthenticatedFailure.\n */\n isAuthenticated(): boolean | Promise<boolean>;\n\n /**\n * Checks if the current user is authorised. If true the router will proceed to route sanitisation\n * and view loading, otherwise it will invoke #handleAuthorisationFailure.\n * @param placeDefinition\n */\n isAuthorised(placeDefinition: PlaceDefinition): boolean;\n\n handleNotAuthenticated(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Constructable<PlaceComponent> | Visit;\n\n handleNotAuthorised(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): Constructable<PlaceComponent> | Visit;\n}\n\nexport namespace PlaceAuthService {\n export type AuthoriserCallback = (placeDef: PlaceDefinition) => boolean;\n}\n"]}
@@ -1 +1 @@
1
- [{"__symbolic":"module","version":4,"metadata":{"PLACE_AUTH_SERVICE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":7,"character":38},"arguments":["PlaceAuthService"]},"PlaceAuthService":{"__symbolic":"interface"}}}]
1
+ [{"__symbolic":"module","version":4,"metadata":{"PLACE_AUTH_SERVICE":{"__symbolic":"new","expression":{"__symbolic":"reference","module":"@angular/core","name":"InjectionToken","line":8,"character":38},"arguments":["PlaceAuthService"]},"PlaceAuthService":{"__symbolic":"interface"}}}]
@@ -27,7 +27,7 @@ import { assert as assert$1, Opts, lang as lang$1, Klass } from '@coolon/typescr
27
27
  import produce from 'immer';
28
28
  import { FlexModule, GridModule } from '@angular/flex-layout';
29
29
  import { MatDialogModule, MatDialog, MAT_DIALOG_DEFAULT_OPTIONS, MatDialogConfig } from '@angular/material/dialog';
30
- import { RouterModule, ActivatedRouteSnapshot, NavigationStart, NavigationCancel, UrlSegment, Router, UrlSerializer, NavigationEnd, NavigationError, RouterOutlet, RouterStateSnapshot } from '@angular/router';
30
+ import { RouterModule, ActivatedRouteSnapshot, NavigationStart, NavigationCancel, UrlSegment, Router, UrlSerializer, NavigationEnd, NavigationError, RouterOutlet } from '@angular/router';
31
31
  import { Overlay, CdkScrollable } from '@angular/cdk/overlay';
32
32
  import ResizeObserver from 'resize-observer-polyfill';
33
33
  import { MatListModule } from '@angular/material/list';
@@ -6156,10 +6156,11 @@ function leftRightPlaceAnimation(duration) {
6156
6156
  const LEFT_RIGHT_PLACE_ANIMATION = leftRightPlaceAnimation('0.3s');
6157
6157
 
6158
6158
  class PlaceOutletComponent extends DisposableComponent {
6159
- constructor(router, placeRouter, placeConfig, parentOutlet) {
6159
+ constructor(router, placeRouter, placeAuthService, placeConfig, parentOutlet) {
6160
6160
  super();
6161
6161
  this.router = router;
6162
6162
  this.placeRouter = placeRouter;
6163
+ this.placeAuthService = placeAuthService;
6163
6164
  this.placeConfig = placeConfig;
6164
6165
  this.placeChanged = new EventEmitter();
6165
6166
  this.outletActivated = new MutableValueModel(false);
@@ -6204,6 +6205,13 @@ class PlaceOutletComponent extends DisposableComponent {
6204
6205
  chain(this._activePlaceModel)
6205
6206
  .postponeWhile(this.navigationInProgress)
6206
6207
  .subscribe(place => this.placeChanged.emit(place));
6208
+ when(placeAuthService.authoriserModel).changes(isAuthorised => {
6209
+ const activePlace = this._activePlaceModel.value;
6210
+ if (activePlace && !isAuthorised(activePlace.placeDefinition)) {
6211
+ const visitOrPlace = placeAuthService.handleNotAuthorised(this._activatedRouteModel.value.snapshot, this.router.routerState.snapshot);
6212
+ this.placeRouter.navigate(visitOrPlace instanceof Visit ? visitOrPlace : new Visit(PlaceComponent.getDefinition(visitOrPlace)));
6213
+ }
6214
+ });
6207
6215
  }
6208
6216
  // @Trace()
6209
6217
  ngOnInit() {
@@ -6325,6 +6333,7 @@ PlaceOutletComponent.decorators = [
6325
6333
  PlaceOutletComponent.ctorParameters = () => [
6326
6334
  { type: Router },
6327
6335
  { type: PlaceRouter },
6336
+ { type: undefined, decorators: [{ type: Inject, args: [PLACE_AUTH_SERVICE,] }] },
6328
6337
  { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [AUP_PLACE_CONFIG,] }] },
6329
6338
  { type: PlaceOutletComponent, decorators: [{ type: SkipSelf }, { type: Optional }] }
6330
6339
  ];
@@ -6903,17 +6912,28 @@ class PlaceGuard {
6903
6912
  this.interactionService = interactionService;
6904
6913
  this.injector = injector;
6905
6914
  }
6915
+ // @Trace()
6906
6916
  canActivate(activatedRoute, state) {
6907
6917
  return __awaiter(this, void 0, void 0, function* () {
6908
6918
  if (PlaceComponent.isPlaceComponentConstructor(activatedRoute.component)) {
6909
6919
  const placeDefinition = PlaceComponent.getDefinition(activatedRoute.component);
6910
- const needsAuth = placeDefinition.authenticate;
6911
- const proceed = !needsAuth || (yield this.placeAuthService.isAuthenticated());
6912
- if (!proceed) {
6913
- return this.handleGuardResult(this.placeAuthService.handleNotAuthenticated(activatedRoute, state));
6914
- }
6915
- if (!this.placeAuthService.isAuthorised(placeDefinition)) {
6916
- return this.handleGuardResult(this.placeAuthService.handleNotAuthorised(activatedRoute, state));
6920
+ if (placeDefinition.authenticate) {
6921
+ if (!(yield this.placeAuthService.isAuthenticated())) {
6922
+ const redirectLocation = this.placeAuthService.handleNotAuthenticated(activatedRoute, state);
6923
+ const nextPlaceDef = this.getPlaceDefinition(redirectLocation);
6924
+ if (nextPlaceDef.authenticate) {
6925
+ lang.illegalState(`handleNotAuthenticated hook returned place ${nextPlaceDef.component.name} that requires authentication.`);
6926
+ }
6927
+ return this.createUrlTree(redirectLocation);
6928
+ }
6929
+ if (!this.placeAuthService.isAuthorised(placeDefinition)) {
6930
+ const redirectLocation = this.placeAuthService.handleNotAuthorised(activatedRoute, state);
6931
+ const nextPlaceDef = this.getPlaceDefinition(redirectLocation);
6932
+ if (!this.placeAuthService.isAuthorised(nextPlaceDef)) {
6933
+ lang.illegalState(`handleNotAuthorised hook returned place ${nextPlaceDef.component.name} that is not authorised for the current user.`);
6934
+ }
6935
+ return this.createUrlTree(redirectLocation);
6936
+ }
6917
6937
  }
6918
6938
  const result = yield this.cleanInteractionState(activatedRoute, state, () => __awaiter(this, void 0, void 0, function* () {
6919
6939
  // Parse our route params.
@@ -6942,6 +6962,7 @@ class PlaceGuard {
6942
6962
  }
6943
6963
  });
6944
6964
  }
6965
+ // @Trace()
6945
6966
  canDeactivate(component, currentRoute, currentState, nextState) {
6946
6967
  return __awaiter(this, void 0, void 0, function* () {
6947
6968
  const currentUrl = this.urlService.parseUrl(currentState.url);
@@ -6950,13 +6971,14 @@ class PlaceGuard {
6950
6971
  return result instanceof UrlSnapshot ? result.urlTree : result;
6951
6972
  });
6952
6973
  }
6953
- handleGuardResult(result) {
6954
- if (result instanceof UrlSnapshot) {
6955
- return result.urlTree;
6956
- }
6957
- else {
6958
- return this.urlService.createUrlSnapshot(result).urlTree;
6959
- }
6974
+ getPlaceDefinition(result) {
6975
+ return result instanceof Visit ?
6976
+ result.placeDefinition :
6977
+ PlaceComponent.getDefinition(result);
6978
+ }
6979
+ createUrlTree(result) {
6980
+ const visit = result instanceof Visit ? result : new Visit(PlaceComponent.getDefinition(result), {});
6981
+ return this.urlService.createUrlSnapshot(visit).urlTree;
6960
6982
  }
6961
6983
  // protected async ensureAuthenticatedThen(activatedRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot, next: (placeDefinition: PlaceDefinition) => Promise<boolean | UrlTree>): Promise<boolean | UrlTree> {
6962
6984
  // const authoriseResult = placeDefinition.authenticate ? await this.isAuthorised(activatedRoute, state) : true;
@@ -6979,6 +7001,7 @@ class PlaceGuard {
6979
7001
  // return (authorised instanceof Observable) ? authorised.toPromise() : authorised;
6980
7002
  // }
6981
7003
  // abstract getAuthGuard(injector: Injector): CanActivate;
7004
+ // @Trace()
6982
7005
  cleanInteractionState(route, state, next) {
6983
7006
  return __awaiter(this, void 0, void 0, function* () {
6984
7007
  const url = this.urlService.parseUrl(state.url);
@@ -7006,30 +7029,6 @@ PlaceGuard.ctorParameters = () => [
7006
7029
  { type: InteractionService },
7007
7030
  { type: Injector }
7008
7031
  ];
7009
- __decorate([
7010
- Trace(),
7011
- __metadata("design:type", Function),
7012
- __metadata("design:paramtypes", [ActivatedRouteSnapshot, RouterStateSnapshot]),
7013
- __metadata("design:returntype", Promise)
7014
- ], PlaceGuard.prototype, "canActivate", null);
7015
- __decorate([
7016
- Trace(),
7017
- __metadata("design:type", Function),
7018
- __metadata("design:paramtypes", [PlaceComponent, ActivatedRouteSnapshot, RouterStateSnapshot, RouterStateSnapshot]),
7019
- __metadata("design:returntype", Promise)
7020
- ], PlaceGuard.prototype, "canDeactivate", null);
7021
- __decorate([
7022
- Trace(),
7023
- __metadata("design:type", Function),
7024
- __metadata("design:paramtypes", [Object]),
7025
- __metadata("design:returntype", void 0)
7026
- ], PlaceGuard.prototype, "handleGuardResult", null);
7027
- __decorate([
7028
- Trace(),
7029
- __metadata("design:type", Function),
7030
- __metadata("design:paramtypes", [ActivatedRouteSnapshot, RouterStateSnapshot, Function]),
7031
- __metadata("design:returntype", Promise)
7032
- ], PlaceGuard.prototype, "cleanInteractionState", null);
7033
7032
 
7034
7033
  var Formatter;
7035
7034
  (function (Formatter) {