SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons. svghmi
authorEdouard Tisserant
Thu, 04 Jun 2020 11:14:21 +0200
branchsvghmi
changeset 2980 2a21d6060d64
parent 2979 9442f6a6449e
child 2981 a0932a52e53b
SVGHMI: add "unsubscribable" property to widgets in order to generalize what already happens for jump buttons.
In most cases jump buttons do not really subscribe to pointed HMI variable, path is given as a relative page jump path. When widget.unsubscribable is set to true, no subscription is made on page switch, but still offset is updated.
This fixes bug happening on relative jump buttons without "disabled" element where offset did not change on relative page switch.
svghmi/gen_index_xhtml.xslt
svghmi/widget_jump.ysl2
svghmi/widgets_common.ysl2
--- a/svghmi/gen_index_xhtml.xslt	Wed Jun 03 13:31:55 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Thu Jun 04 11:14:21 2020 +0200
@@ -912,6 +912,8 @@
 </xsl:text>
     <xsl:text>    frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
 </xsl:text>
+    <xsl:text>    unsubscribable = false;
+</xsl:text>
     <xsl:text>    constructor(elt_id,args,indexes,members){
 </xsl:text>
     <xsl:text>        this.element_id = elt_id;
@@ -932,7 +934,7 @@
 </xsl:text>
     <xsl:text>        /* remove subsribers */
 </xsl:text>
-    <xsl:text>        for(let index of this.indexes){
+    <xsl:text>        if(!this.unsubscribable) for(let index of this.indexes){
 </xsl:text>
     <xsl:text>            let idx = index + this.offset;
 </xsl:text>
@@ -954,7 +956,7 @@
 </xsl:text>
     <xsl:text>        /* add this's subsribers */
 </xsl:text>
-    <xsl:text>        for(let index of this.indexes){
+    <xsl:text>        if(!this.unsubscribable) for(let index of this.indexes){
 </xsl:text>
     <xsl:text>            subscribers[index + new_offset].add(this);
 </xsl:text>
@@ -968,7 +970,7 @@
 </xsl:text>
     <xsl:text>    apply_cache() {
 </xsl:text>
-    <xsl:text>        for(let index of this.indexes){
+    <xsl:text>        if(!this.unsubscribable) for(let index of this.indexes){
 </xsl:text>
     <xsl:text>            /* dispatch current cache in newly opened page widgets */
 </xsl:text>
@@ -2292,11 +2294,7 @@
 </xsl:text>
       </xsl:when>
       <xsl:otherwise>
-        <xsl:text>        this.sub = function(){};
-</xsl:text>
-        <xsl:text>        this.unsub = function(){};
-</xsl:text>
-        <xsl:text>        this.apply_cache = function(){};
+        <xsl:text>        this.unsubscribable = true;
 </xsl:text>
       </xsl:otherwise>
     </xsl:choose>
--- a/svghmi/widget_jump.ysl2	Wed Jun 03 13:31:55 2020 +0200
+++ b/svghmi/widget_jump.ysl2	Thu Jun 04 11:14:21 2020 +0200
@@ -86,9 +86,7 @@
     |         this.disabled_elt_style = this.disabled_elt.getAttribute("style");
         }
         otherwise {
-    |         this.sub = function(){};
-    |         this.unsub = function(){};
-    |         this.apply_cache = function(){};
+    |         this.unsubscribable = true;
         }
     }
     |     },
--- a/svghmi/widgets_common.ysl2	Wed Jun 03 13:31:55 2020 +0200
+++ b/svghmi/widgets_common.ysl2	Thu Jun 04 11:14:21 2020 +0200
@@ -67,6 +67,7 @@
     class Widget {
         offset = 0;
         frequency = 10; /* FIXME arbitrary default max freq. Obtain from config ? */
+        unsubscribable = false;
         constructor(elt_id,args,indexes,members){
             this.element_id = elt_id;
             this.element = id(elt_id);
@@ -77,7 +78,7 @@
 
         unsub(){
             /* remove subsribers */
-            for(let index of this.indexes){
+            if(!this.unsubscribable) for(let index of this.indexes){
                 let idx = index + this.offset;
                 subscribers[idx].delete(this);
             }
@@ -88,14 +89,14 @@
             /* set the offset because relative */
             this.offset = new_offset;
             /* add this's subsribers */
-            for(let index of this.indexes){
+            if(!this.unsubscribable) for(let index of this.indexes){
                 subscribers[index + new_offset].add(this);
             }
             need_cache_apply.push(this); 
         }
 
         apply_cache() {
-            for(let index of this.indexes){
+            if(!this.unsubscribable) for(let index of this.indexes){
                 /* dispatch current cache in newly opened page widgets */
                 let realindex = index+this.offset;
                 let cached_val = cache[realindex];