From 027bec851947805a1928bffbd2ab085e0ed3e747 Mon Sep 17 00:00:00 2001
From: Jean-Pascal <jean-pascal.aubry@inrae.fr>
Date: Fri, 8 Dec 2023 10:45:24 +0000
Subject: [PATCH] feat: add MacroRugoRemous calculator definition

refs #609
---
 .../formulaire/definition/form-definition.ts  |  5 ++-
 .../definition/form-macrorugo-remous.ts       | 33 +++++++++++++++++--
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts
index 23f9d2d98..d5ebca4f2 100644
--- a/src/app/formulaire/definition/form-definition.ts
+++ b/src/app/formulaire/definition/form-definition.ts
@@ -478,16 +478,19 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
     //  interface Observer
 
     public update(sender: any, data: any) {
+        console.log("test")
         if (sender instanceof Nub) {
             switch (data.action) {
                 case "resultUpdated":
+                    console.log("test 1");
                     // forward Nub results update notification to FormCompute objects
                     this.reaffectResultComponents();
                     break;
             }
         }
         else if (sender instanceof SessionSettings) {
-            // reset results if a session setting (max iterations, compute precision) has been modified
+            console.log("test 2");
+            // reset results if a session setting (max iterations, compute precision) has bsseen modified
             this.reset();
         }
     }
diff --git a/src/app/formulaire/definition/form-macrorugo-remous.ts b/src/app/formulaire/definition/form-macrorugo-remous.ts
index 28c2308ea..6eb5a1c43 100644
--- a/src/app/formulaire/definition/form-macrorugo-remous.ts
+++ b/src/app/formulaire/definition/form-macrorugo-remous.ts
@@ -1,7 +1,8 @@
 import { RemousResults } from "app/results/remous-results";
 import { acSection, CourbeRemous, CourbeRemousParams, MacroRugo, MacrorugoRemous, Props, Result, Session } from "jalhyd";
-import { MacrorugoRemousParams} from "jalhyd/build/internal_modules";
+import { IObservable, MacrorugoRemousParams, Nub, Verificateur} from "jalhyd/build/internal_modules";
 import { FormulaireFixedVar } from "./form-fixedvar";
+import { SelectField } from "../elements/select/select-field";
 
 export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
     public initNub(props?: Props) {
@@ -14,8 +15,7 @@ export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
             }
         }
         if (pam !== undefined) {
-            // props.setPropValue(MacrorugoRemous.nubMacroRugo, pam.uid);
-            props.setPropValue("Q", pam.prms.Q.V);
+            props.setPropValue("nubMacroRugo", pam.uid);
         }
         return super.initNub(props);
     }
@@ -79,6 +79,33 @@ export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
         }
     }
 
+    // interface Observer
+
+    // public update(sender: IObservable, data: any) {
+    //     // copied from FormDefinition, to avoid calling super.update() that would trigger an unwanted this.refreshFieldsets();
+    //     if (sender instanceof Nub) {
+    //         switch (data.action) {
+    //             case "resultUpdated":
+    //                 // forward Nub results update notification to FormCompute objects
+    //                 this.reaffectResultComponents();
+    //                 break;
+    //         }
+    //     }
+    //     // copied from FormFixedVar, to avoid calling super.update()
+    //     if (data.action === "propertyChange") {
+    //         this.reset();
+    //     }
+
+    //     if (sender instanceof SelectField) {
+    //         this.reset(); // reset results
+    //         console.log("update", data.action)
+    //         if (sender.id === "select_target_pam" && data.action === "select") {
+    //             // update Verificateur property: Pass to check
+    //             this._currentNub.setPropValue("nubToVerify", data.value ? data.value.value : undefined);
+    //         } 
+    //     }
+    // }
+
     public resetFormResults() {
         this._remousResults.reset();
         this.updateCalcResults();
-- 
GitLab