Skip to content

Commit

Permalink
Adding the ability to have a hidden reset for the resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Jul 14, 2024
1 parent 89b34c7 commit d713652
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion projects/angular-formio/resource/src/resource.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class FormioResourceComponent implements OnInit, OnDestroy {
}

init() {
return this.service.init(this.route).then(() =>
return this.service.init(this.route, this.router).then(() =>
this.auth.ready.then(() =>
this.service.formFormio.userPermissions(
this.auth.user,
Expand Down
15 changes: 12 additions & 3 deletions projects/angular-formio/resource/src/resource.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventEmitter, Injectable, Optional } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { FormioResourceConfig } from './resource.config';
import { FormioResources } from './resources.service';
import { FormioPromiseService } from '@formio/angular';
Expand Down Expand Up @@ -84,9 +84,18 @@ export class FormioResourceService {
this.resource = { data: {} };
}

init(route: ActivatedRoute) {
init(route: ActivatedRoute, router: Router = null) {
const snapshot = route.snapshot;
const reset = snapshot.queryParams?.hasOwnProperty('reset') ? snapshot.queryParams.reset : false;
let reset = false;
if (snapshot.queryParams.hasOwnProperty('reset')) {
reset = snapshot.queryParams.reset;
}
else if (router) {
const navigation = router.getCurrentNavigation();
if (navigation?.extras.state && navigation.extras.state.hasOwnProperty('reset')) {
reset = navigation.extras.state['reset'];
}
}
const resourceId = snapshot.params['id'];
if (resourceId && (resourceId === this.resourceId) && !reset) {
return this.ready;
Expand Down

0 comments on commit d713652

Please sign in to comment.