From 87b0da68709613727ab1ddfbba8c0af3911128ac Mon Sep 17 00:00:00 2001
From: "francois.grand" <francois.grand@irstea.fr>
Date: Tue, 19 Dec 2017 14:27:12 +0100
Subject: [PATCH] =?UTF-8?q?Ajout=20du=20contr=C3=B4le=20de=20validit=C3=A9?=
 =?UTF-8?q?=20des=20URLs=20concernant=20l'affichage=20des=20formulaires=20?=
 =?UTF-8?q?et=20retour=20=C3=A0=20la=20liste=20des=20calculettes=20en=20ca?=
 =?UTF-8?q?s=20de=20pb=20closes=20#22?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/app/app.component.ts                            |  8 ++++++++
 .../calculators/generic/calculator.component.html   |  8 ++++----
 src/app/calculators/generic/calculator.component.ts |  7 ++++++-
 .../calculator-results.component.ts                 | 13 ++++++++++---
 .../remous-results/remous-results.component.html    |  8 ++++----
 .../remous-results/remous-results.component.ts      | 12 ++++++++++++
 src/app/services/formulaire/formulaire.service.ts   |  7 ++++++-
 7 files changed, 50 insertions(+), 13 deletions(-)

diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 6938cf168..abc8c0c27 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -109,6 +109,10 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
             }
           );
           break;
+
+        case "invalidid":
+          this.toList();
+          break;
       }
     }
   }
@@ -125,6 +129,10 @@ export class AppComponent implements OnInit, OnDestroy, Observer {
 
   private newCalc() {
     this.closeNav();
+    this.toList();
+  }
+
+  private toList() {
     this.router.navigate(['/list']);
   }
 
diff --git a/src/app/calculators/generic/calculator.component.html b/src/app/calculators/generic/calculator.component.html
index c04760e66..0c875daeb 100644
--- a/src/app/calculators/generic/calculator.component.html
+++ b/src/app/calculators/generic/calculator.component.html
@@ -1,4 +1,4 @@
-<div class="row">
+<div *ngIf="hasData()" class="row">
     <div class="col">
         <h1>{{uitextTitre}}</h1>
     </div>
@@ -6,19 +6,19 @@
 <field-set *ngFor="let fs of fieldSets" [style.display]="getFieldsetStyleDisplay(fs.id)" [fieldSet]=fs (onRadio)=onRadioClick($event)
     (onSelectChange)=onSelectChanged($event)></field-set>
 
-<div class="row ">
+<div *ngIf="hasData()" class="row">
     <div class="col text-center">
         <p></p>
     </div>
 </div>
 
-<div class="row ">
+<div *ngIf="hasData()" class="row">
     <div class="col text-center">
         <button type="button" class="button_compute" name="Calculer" (click)="doCompute()">{{uitextCalculer}}</button>
     </div>
 </div>
 
-<div class="row ">
+<div *ngIf="hasData()" class="row">
     <div class="col text-center">
         <p></p>
     </div>
diff --git a/src/app/calculators/generic/calculator.component.ts b/src/app/calculators/generic/calculator.component.ts
index 228c1fe5a..5aa78c18d 100644
--- a/src/app/calculators/generic/calculator.component.ts
+++ b/src/app/calculators/generic/calculator.component.ts
@@ -47,6 +47,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, OnDestroy, O
         return this._formulaire.getFieldSets();
     }
 
+    private hasData() {
+        return this._formulaire != undefined;
+    }
+
     private get uitextTitre() {
         switch (this._formulaire.calculatorType) {
             case CalculatorType.ConduiteDistributrice:
@@ -102,7 +106,8 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, OnDestroy, O
 
             this._formulaire = this.formulaireService.getFormulaireFromId(uid);
             this.resultsComponent.formulaire = this._formulaire;
-            this._formulaire.updateNodeType();
+            if (this._formulaire != undefined)
+                this._formulaire.updateNodeType();
         });
     }
 
diff --git a/src/app/components/calculator-results/calculator-results.component.ts b/src/app/components/calculator-results/calculator-results.component.ts
index 9cb97804f..45ae5825c 100644
--- a/src/app/components/calculator-results/calculator-results.component.ts
+++ b/src/app/components/calculator-results/calculator-results.component.ts
@@ -32,9 +32,16 @@ export class CalculatorResultsComponent {
 
     public set formulaire(f: FormulaireDefinition) {
         this._formulaire = f;
-        this.fixedVarResultsComponent.results = f.fixVarResults;
-        this.sectionResultsComponent.results = f.sectionResults;
-        this.remousResultsComponent.results = f.remousResults;
+        if (this._formulaire == undefined) {
+            this.fixedVarResultsComponent.results = undefined;
+            this.sectionResultsComponent.results = undefined;
+            this.remousResultsComponent.results = undefined;
+        }
+        else {
+            this.fixedVarResultsComponent.results = f.fixVarResults;
+            this.sectionResultsComponent.results = f.sectionResults;
+            this.remousResultsComponent.results = f.remousResults;
+        }
     }
 
     public updateView() {
diff --git a/src/app/components/remous-results/remous-results.component.html b/src/app/components/remous-results/remous-results.component.html
index 6dd379021..4c1e92509 100644
--- a/src/app/components/remous-results/remous-results.component.html
+++ b/src/app/components/remous-results/remous-results.component.html
@@ -5,7 +5,7 @@
 </div>
 <div class="row">
     <div class="col-10 mx-auto">
-        <chart *ngIf="_results.extraGraph" [type]="graph2_type" [data]="graph2_data" [options]="graph2_options"></chart>
+        <chart *ngIf="extraGraph" [type]="graph2_type" [data]="graph2_data" [options]="graph2_options"></chart>
     </div>
 </div>
 
@@ -31,12 +31,12 @@
                 <tr>
                     <th>{{uitextAbscisse}}</th>
                     <th>{{uitextTirant}}</th>
-                    <th>{{_results.extraParamLabel}}</th>
+                    <th>{{extraParamLabel}}</th>
                     <th>{{uitextTirant}}</th>
-                    <th>{{_results.extraParamLabel}}</th>
+                    <th>{{extraParamLabel}}</th>
                 </tr>
             </thead>
-            <tr *ngFor="let r of _results.series; let i=index" [class]="getResultClass(i)">
+            <tr *ngFor="let r of series; let i=index" [class]="getResultClass(i)">
                 <td>{{r.abs}}</td>
                 <td>{{r.flu}}</td>
                 <td>{{r.extraFlu}}</td>
diff --git a/src/app/components/remous-results/remous-results.component.ts b/src/app/components/remous-results/remous-results.component.ts
index 49fd4c59e..c0c574ca7 100644
--- a/src/app/components/remous-results/remous-results.component.ts
+++ b/src/app/components/remous-results/remous-results.component.ts
@@ -88,6 +88,18 @@ export class RemousResultsComponent {
         return this.intlService.localizeText("INFO_REMOUSRESULTS_TIRANTCRITIQUE")
     }
 
+    private get extraGraph(): boolean {
+        return this._results == undefined ? false : this._results.extraGraph;
+    }
+
+    private get series(): Object[] {
+        return this._results == undefined ? [] : this._results.series;
+    }
+
+    private get extraParamLabel(): string {
+        return this._results == undefined ? undefined : this._results.extraParamLabel;
+    }
+
     public set results(r: RemousResults) {
         this._results = r;
         this.updateView();
diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts
index 270d1c0e8..d83991a8e 100644
--- a/src/app/services/formulaire/formulaire.service.ts
+++ b/src/app/services/formulaire/formulaire.service.ts
@@ -116,7 +116,12 @@ export class FormulaireService extends Observable {
             if (f.uid == uid)
                 return f;
 
-        throw "FormulaireService.getFormulaire() : unkown form id " + uid;
+        this.notifyObservers({
+            "action": "invalidid",
+            "formid": uid
+        });
+
+        return undefined;
     }
 
     public getInputField(formId: number, elemId: string): InputField {
-- 
GitLab