From 30a930e25d38ecaff6914020b12c17ad79a3dfef Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Tue, 24 Sep 2019 16:58:16 +0200
Subject: [PATCH] Calculator page: list other calculators using the current
 one, below title

---
 .../calculator.component.html                 |  9 +++++++++
 .../calculator.component.scss                 | 10 ++++++++++
 .../calculator.component.ts                   | 20 +++++++++++++++++++
 src/locale/messages.en.json                   |  1 +
 src/locale/messages.fr.json                   |  1 +
 5 files changed, 41 insertions(+)

diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html
index 7770790c0..2cde586a4 100644
--- a/src/app/components/generic-calculator/calculator.component.html
+++ b/src/app/components/generic-calculator/calculator.component.html
@@ -25,6 +25,15 @@
         <!-- on utilise [innerHTML] pour que les codes HTML comme &nbsp; soient interprétés correctement -->
         <mat-card-title>
             <h1 [innerHTML]="uitextTitre"></h1>
+            <div id="calculator-used-by" *ngIf="calculatorsUsingThisOne.length > 0">
+                {{ uitextUsedBy }}
+                <span *ngFor="let c of calculatorsUsingThisOne; let i = index" >
+                    <a class="used-by-item" (click)="toCalc(c.uid)">
+                        {{ c.label }}
+                    </a>
+                    <span *ngIf="i < calculatorsUsingThisOne.length - 1">, </span>
+                </span>
+            </div>
         </mat-card-title>
 
     </mat-card-header>
diff --git a/src/app/components/generic-calculator/calculator.component.scss b/src/app/components/generic-calculator/calculator.component.scss
index e10f32233..b520db9c9 100644
--- a/src/app/components/generic-calculator/calculator.component.scss
+++ b/src/app/components/generic-calculator/calculator.component.scss
@@ -77,6 +77,16 @@ mat-card {
         mat-card-title {
             font-size: 16px;
             margin-bottom: 8px;
+
+            #calculator-used-by {
+                font-weight: normal;
+                margin-top: -8px;
+                font-size: .9em;
+
+                a.used-by-item {
+                    cursor: pointer;
+                }
+            }
         }
     }
 
diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 1d28af12b..4bdf8c675 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -211,6 +211,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
         return this.intlService.localizeText("INFO_CALCULATOR_CLOSE");
     }
 
+    public get uitextUsedBy() {
+        return this.intlService.localizeText("INFO_CALCULATOR_USED_BY");
+    }
+
     public get quicknavItems() {
         const elts = [ "input", "results" ];
         if (this.isWide && this.hasResults) {
@@ -294,6 +298,22 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
         }
     }
 
+    /** open calculator identified by given UID */
+    public toCalc(id: string) {
+        this.appComponent.toCalc(id);
+    }
+
+    /** list of calculators having a link pointing to the current calculator */
+    public get calculatorsUsingThisOne(): any {
+        const sources = Session.getInstance().getDependingNubs(this._formulaire.currentNub.uid, undefined, true);
+        return sources.map((s) => {
+            return {
+                label: this.formulaireService.getFormulaireFromNubId(s.uid).calculatorName,
+                uid: s.uid
+            };
+        });
+    }
+
     /**
      * Moves the view to the start of the "Results" section
      */
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index 9dc8aff16..2a5fbddb0 100644
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -59,6 +59,7 @@
     "INFO_CALCULATOR_RESULTS_GENERATE_PAB": "Generate a fish ladder",
     "INFO_CALCULATOR_RESULTS_TITLE": "Results",
     "INFO_CALCULATOR_SAVE": "Save",
+    "INFO_CALCULATOR_USED_BY": "Used by",
     "INFO_CALCULATOR_VALEURS": "Values",
     "INFO_CLOISONS_TITRE_COURT": "Cross walls",
     "INFO_CLOISONS_TITRE": "Fish ladder: Cross walls",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index d4ed07a70..a9211fb76 100644
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -59,6 +59,7 @@
     "INFO_CALCULATOR_RESULTS_GENERATE_PAB": "Générer une passe à bassins",
     "INFO_CALCULATOR_RESULTS_TITLE": "Résultats",
     "INFO_CALCULATOR_SAVE": "Enregistrer",
+    "INFO_CALCULATOR_USED_BY": "Utilisé par",
     "INFO_CALCULATOR_VALEURS": "Valeurs",
     "INFO_CLOISONS_TITRE_COURT": "Cloisons",
     "INFO_CLOISONS_TITRE": "Passe à bassins&nbsp;: Cloisons",
-- 
GitLab