Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Wed, 28 Oct 2020 18:21:12 +0200
branchsvghmi
changeset 3069 a9b03c2634c5
parent 3068 81758c94f3df
child 3070 013374b6cdb9
Arbitrary variables added to JsonTable subscription are now passed as 'extra' field in json query. As an example added JsonTable filtering in tests/svghmi
svghmi/gen_index_xhtml.xslt
svghmi/widget_jsontable.ysl2
tests/svghmi/plc.xml
tests/svghmi/py_ext_0@py_ext/pyfile.xml
tests/svghmi/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/gen_index_xhtml.xslt	Thu Oct 22 22:44:29 2020 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Wed Oct 28 18:21:12 2020 +0200
@@ -3826,7 +3826,9 @@
   <xsl:template mode="widget_class" match="widget[@type='JsonTable']">
     <xsl:text>class JsonTableWidget extends Widget{
 </xsl:text>
-    <xsl:text>    cache = [100,50];
+    <xsl:text>    // arbitrary defaults to avoid missing entries in query
+</xsl:text>
+    <xsl:text>    cache = [0,100,50];
 </xsl:text>
     <xsl:text>    do_http_request(...opt) {
 </xsl:text>
@@ -3840,6 +3842,8 @@
 </xsl:text>
     <xsl:text>            visible: this.visible,
 </xsl:text>
+    <xsl:text>            extra: this.cache.slice(4),
+</xsl:text>
     <xsl:text>            options: opt
 </xsl:text>
     <xsl:text>        };
@@ -4177,8 +4181,6 @@
 </xsl:text>
     <xsl:text>        this.apply_hmi_value(3, this.visible);
 </xsl:text>
-    <xsl:text>        console.log(range,position,jdata);
-</xsl:text>
     <xsl:apply-templates mode="json_table_render_except_comments" select="$data_elt">
       <xsl:with-param name="expressions" select="$initexpr_ns"/>
       <xsl:with-param name="widget_elts" select="$hmi_element/*[@inkscape:label = 'data']/descendant::svg:*"/>
--- a/svghmi/widget_jsontable.ysl2	Thu Oct 22 22:44:29 2020 +0200
+++ b/svghmi/widget_jsontable.ysl2	Wed Oct 28 18:21:12 2020 +0200
@@ -3,13 +3,15 @@
 template "widget[@type='JsonTable']", mode="widget_class"
     ||
     class JsonTableWidget extends Widget{
-        cache = [100,50];
+        // arbitrary defaults to avoid missing entries in query
+        cache = [0,100,50];
         do_http_request(...opt) {
             const query = {
                 args: this.args,
                 range: this.cache[1],
                 position: this.cache[2],
                 visible: this.visible,
+                extra: this.cache.slice(4),
                 options: opt
             };
 
@@ -220,7 +222,6 @@
     |         this.apply_hmi_value(1, range);
     |         this.apply_hmi_value(2, position);
     |         this.apply_hmi_value(3, this.visible);
-    |         console.log(range,position,jdata);
     apply "$data_elt", mode="json_table_render_except_comments" {
         with "expressions","$initexpr_ns";
         with "widget_elts","$hmi_element/*[@inkscape:label = 'data']/descendant::svg:*";
--- a/tests/svghmi/plc.xml	Thu Oct 22 22:44:29 2020 +0200
+++ b/tests/svghmi/plc.xml	Wed Oct 28 18:21:12 2020 +0200
@@ -1,7 +1,7 @@
 <?xml version='1.0' encoding='utf-8'?>
 <project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
   <fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2019-08-06T14:23:42"/>
-  <contentHeader name="Unnamed" modificationDateTime="2020-10-22T08:43:10">
+  <contentHeader name="Unnamed" modificationDateTime="2020-10-30T20:07:00">
     <coordinateInfo>
       <fbd>
         <scaling x="5" y="5"/>
--- a/tests/svghmi/py_ext_0@py_ext/pyfile.xml	Thu Oct 22 22:44:29 2020 +0200
+++ b/tests/svghmi/py_ext_0@py_ext/pyfile.xml	Wed Oct 28 18:21:12 2020 +0200
@@ -34,6 +34,7 @@
         range_feedback = newdata[u'range']
         slider_position = newdata[u'position']
         visible = newdata[u'visible']
+        extra = newdata[u'extra']
         options = newdata[u'options']
 
         if len(options) == 2 :
@@ -41,18 +42,22 @@
             if action == "onClick[acknowledge]":
                 AlarmIndex[int(alarmid)][2] = "ack"
 
-        answer = self.renderTable(range_feedback, slider_position, visible)
+        answer = self.renderTable(range_feedback, slider_position, visible, extra)
         janswer = json.dumps(answer)
         return janswer
 
-    def renderTable(self, old_range, old_position, visible):
-        new_range = len(Alarms)
+    def renderTable(self, old_range, old_position, visible, extra):
+        if len(extra) > 0 and extra[0] != "":
+            fAlarms = [alrm for alrm in Alarms if alrm[1].find(extra[0])!=-1]
+        else:
+            fAlarms = Alarms
+        new_range = len(fAlarms)
         delta = new_range - visible
         new_position = 0 if delta <= 0 else delta if old_position > delta else old_position
         new_visible = new_range if delta <= 0 else visible
         
         visible_alarms = []
-        for ts, text, status, alarmid in Alarms[new_position:new_position + new_visible]:
+        for ts, text, status, alarmid in fAlarms[new_position:new_position + new_visible]:
             visible_alarms.append({
                 "time": time.ctime(ts),
                 "text": text, # TODO translate text
--- a/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Thu Oct 22 22:44:29 2020 +0200
+++ b/tests/svghmi/svghmi_0@svghmi/svghmi.svg	Wed Oct 28 18:21:12 2020 +0200
@@ -200,12 +200,12 @@
      inkscape:current-layer="hmi0"
      showgrid="false"
      units="px"
-     inkscape:zoom="0.38583842"
-     inkscape:cx="-56.535477"
-     inkscape:cy="77.476632"
-     inkscape:window-width="1920"
-     inkscape:window-height="1043"
-     inkscape:window-x="0"
+     inkscape:zoom="1.5433537"
+     inkscape:cx="-705.74041"
+     inkscape:cy="175.04058"
+     inkscape:window-width="3840"
+     inkscape:window-height="2123"
+     inkscape:window-x="1600"
      inkscape:window-y="0"
      inkscape:window-maximized="1"
      showguides="true"
@@ -5248,7 +5248,7 @@
        style="fill:#ffffff;stroke-width:1px">Alarm Page</tspan></text>
   <g
      id="g1289"
-     inkscape:label="HMI:JsonTable:/alarms@/ALARMNOTIFY@.range@.position"
+     inkscape:label="HMI:JsonTable:/alarms@/ALARMNOTIFY@.range@.position@.visibleAlarms@.filter"
      transform="matrix(0.5,0,0,0.5,-1757.3465,454.4367)">
     <g
        id="g5231"
@@ -5490,7 +5490,7 @@
        inkscape:label="disabled" />
   </g>
   <g
-     transform="matrix(0.33436432,0,0,0.33436432,-664.21063,278.8185)"
+     transform="matrix(0.33436432,0,0,0.33436432,-584.21063,278.8185)"
      inkscape:label="HMI:Input@/ALARMNOTIFY"
      id="g5222"
      style="stroke-width:0.75594342">
@@ -5695,7 +5695,7 @@
        inkscape:label="disabled" />
   </g>
   <g
-     transform="matrix(0.33436432,0,0,0.33436432,-1128.7703,278.8185)"
+     transform="matrix(0.33436432,0,0,0.33436432,-1048.7703,278.8185)"
      inkscape:label="HMI:Input@.range"
      id="g5222-3"
      style="stroke-width:0.75594342">
@@ -5757,7 +5757,7 @@
        sodipodi:type="star" />
   </g>
   <g
-     transform="matrix(0.33436432,0,0,0.33436432,-896.49047,278.8185)"
+     transform="matrix(0.33436432,0,0,0.33436432,-816.49047,278.8185)"
      inkscape:label="HMI:Input@.position"
      id="g5222-6"
      style="stroke-width:0.75594342">
@@ -5821,34 +5821,34 @@
   <text
      xml:space="preserve"
      style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:26.45700645px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-     x="-1015.5838"
+     x="-935.5838"
      y="291.8042"
      id="text887"><tspan
        sodipodi:role="line"
        id="tspan885"
-       x="-1015.5838"
+       x="-935.5838"
        y="291.8042"
        style="fill:#ffffff;stroke-width:1px">range</tspan></text>
   <text
      id="text891"
      y="291.8042"
-     x="-782.87115"
+     x="-702.87115"
      style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:26.45700645px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
      xml:space="preserve"><tspan
        style="fill:#ffffff;stroke-width:1px"
        y="291.8042"
-       x="-782.87115"
+       x="-702.87115"
        id="tspan889"
        sodipodi:role="line">position</tspan></text>
   <text
      xml:space="preserve"
      style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:26.45700645px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-     x="-551.33417"
+     x="-471.33417"
      y="291.8042"
      id="text895"><tspan
        sodipodi:role="line"
        id="tspan893"
-       x="-551.33417"
+       x="-471.33417"
        y="291.8042"
        style="fill:#ffffff;stroke-width:1px">notify</tspan></text>
   <g
@@ -6100,4 +6100,45 @@
        x="668.18188"
        y="242.50345"
        style="fill:#ffffff;fill-opacity:1;stroke-width:0.28590268px">8888</tspan></text>
+  <g
+     style="stroke-width:0.75594342"
+     id="g900"
+     inkscape:label="HMI:Input@.filter"
+     transform="matrix(0.33436432,0,0,0.33436432,-1288.7703,278.8185)">
+    <text
+       inkscape:label="value"
+       id="text892"
+       y="218.24219"
+       x="136.32812"
+       style="font-style:normal;font-weight:normal;font-size:160px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.75594342px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       xml:space="preserve"><tspan
+         style="stroke-width:0.75594342px"
+         y="218.24219"
+         x="136.32812"
+         id="tspan890"
+         sodipodi:role="line">8888</tspan></text>
+    <rect
+       style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:0;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#ff00ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:3.77971721;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
+       id="rect896"
+       width="615.05096"
+       height="128"
+       x="139.85185"
+       y="95.40741"
+       onclick=""
+       inkscape:label="edit" />
+  </g>
+  <text
+     id="text904"
+     y="291.8042"
+     x="-1175.5837"
+     style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:26.45700645px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+     xml:space="preserve"><tspan
+       style="fill:#ffffff;stroke-width:1px"
+       y="291.8042"
+       x="-1175.5837"
+       id="tspan902"
+       sodipodi:role="line">filter</tspan></text>
+  <g
+     id="g909"
+     inkscape:label="HMI:VarInit:&quot;&quot;@.filter" />
 </svg>