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 3473 1202b47e7e63
parent 3472 2fb9849c6721
child 3474 3ba74350237d
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;