SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
authorEdouard Tisserant
Fri, 06 May 2022 11:04:17 +0200
changeset 3469 97622e9560b5
parent 3468 3725487d5468
child 3475 ee665dca07fa
SVGHMI: fix widget's update frequency forcing : syntax checking was enforcing unit and js code was using undefined variables
svghmi/parse_labels.ysl2
svghmi/widgets_common.ysl2
--- a/svghmi/parse_labels.ysl2	Fri May 06 11:02:03 2022 +0200
+++ b/svghmi/parse_labels.ysl2	Fri May 06 11:04:17 2022 +0200
@@ -15,7 +15,7 @@
 //
 const "pathregex",!"'^([^\[,]+)(\[[^\]]+\])?([\d,]*)$'"!;
 
-template "*", mode="parselabel" 
+template "*", mode="parselabel"
 {
     const "label","@inkscape:label";
     const "id","@id";
@@ -45,7 +45,7 @@
         attrib "id" > «$id»
         attrib "type" > «$type»
         if "$freq" {
-            if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]'))" {
+            if "not(regexp:test($freq,'^[0-9]*(\.[0-9]+)?[smh]?'))" {
                 error > Widget id:«$id» label:«$label» has wrong syntax of frequency forcing «$freq»
             }
             attrib "freq" > «$freq»
--- a/svghmi/widgets_common.ysl2	Fri May 06 11:02:03 2022 +0200
+++ b/svghmi/widgets_common.ysl2	Fri May 06 11:04:17 2022 +0200
@@ -187,23 +187,23 @@
         }
 
         do_init(){
-            if(widget.forced_frequency !== undefined){
-                let s = widget.forced_frequency;
+            let forced = this.forced_frequency;
+            if(forced !== undefined){
                 /*
                 once every 10 seconds : 10s
                 once per minute : 1m
                 once per hour : 1h
                 once per day : 1d
                 */
-                let unit = s.slice(-1);
+                let unit = forced.slice(-1);
                 let factor = {
                     "s":1,
                     "m":60,
                     "h":3600,
                     "d":86400}[unit];
 
-                widget.frequency = factor ? 1/(factor * Number(s.slice(0,-1)))
-                                          : Number(s);
+                this.frequency = factor ? 1/(factor * Number(forced.slice(0,-1)))
+                                          : Number(forced);
             }
 
             let init = this.init;