Skip to content
Snippets Groups Projects
Commit 3643040b authored by mathias.chouet's avatar mathias.chouet
Browse files

Rotueur : redirection vers la liste si le module demandé n'existe pas

parent 4f4cf17c
No related branches found
No related tags found
No related merge requests found
......@@ -88,7 +88,12 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
const path = event.snapshot.url[0].path;
if (path === "calculator") {
const calcUid = event.snapshot.params.uid;
this.setActiveCalc(calcUid);
if (this.calculatorExists(calcUid)) {
this.setActiveCalc(calcUid);
} else {
// if required calculator does not exist, redirect to list page
this.toList();
}
} else {
this.setActiveCalc(null);
}
......@@ -264,6 +269,14 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
}
}
/**
* Returns true if a form having "formUid" as UID exists
* @param formId UID to look for
*/
private calculatorExists(formId: string): boolean {
return (this.getCalculatorIndexFromId(formId) > -1);
}
private getCalculatorIndexFromId(formId: string) {
const index = this._calculators.reduce((resultIndex, calc, currIndex) => {
if (resultIndex === -1 && calc["uid"] === formId) {
......
......@@ -183,7 +183,9 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit,
}
private unsubscribeRouter() {
this._subscription.unsubscribe();
if (this._subscription) {
this._subscription.unsubscribe();
}
}
/*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment