svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2790 8fab1886ebec
parent 2789 ba0dd2ec6dc4
child 2791 d022523cb621
--- a/svghmi/gen_index_xhtml.xslt	Wed Oct 02 11:31:02 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt	Sat Oct 05 09:45:58 2019 +0200
@@ -1,8 +1,55 @@
 <?xml version="1.0"?>
-<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/1999/xhtml" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
+<xsl:stylesheet xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns="beremiz" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" exclude-result-prefixes="ns" extension-element-prefixes="ns" version="1.0">
   <xsl:output method="xml" cdata-section-elements="script"/>
   <xsl:variable name="geometry" select="ns:GetSVGGeometry()"/>
   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
+  <xsl:variable name="_categories">
+    <noindex>
+      <xsl:text>HMI_ROOT</xsl:text>
+    </noindex>
+    <noindex>
+      <xsl:text>HMI_LABEL</xsl:text>
+    </noindex>
+    <noindex>
+      <xsl:text>HMI_CLASS</xsl:text>
+    </noindex>
+    <noindex>
+      <xsl:text>HMI_PLC_STATUS</xsl:text>
+    </noindex>
+    <noindex>
+      <xsl:text>HMI_CURRENT_PAGE</xsl:text>
+    </noindex>
+  </xsl:variable>
+  <xsl:variable name="categories" select="exsl:node-set($_categories)"/>
+  <xsl:variable name="indexed_hmitree">
+    <xsl:apply-templates mode="index" select="$hmitree"/>
+  </xsl:variable>
+  <xsl:template mode="index" match="node()">
+    <xsl:param name="index" select="0"/>
+    <xsl:variable name="content">
+      <xsl:choose>
+        <xsl:when test="not(local-name() = $categories/noindex)">
+          <xsl:copy>
+            <xsl:attribute name="index">
+              <xsl:value-of select="$index"/>
+            </xsl:attribute>
+            <xsl:for-each select="@*">
+              <xsl:copy/>
+            </xsl:for-each>
+          </xsl:copy>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:apply-templates mode="index" select="*[1]">
+            <xsl:with-param name="index" select="$index"/>
+          </xsl:apply-templates>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:variable>
+    <xsl:copy-of select="$content"/>
+    <xsl:apply-templates mode="index" select="following-sibling::*[1]">
+      <xsl:with-param name="index" select="$index + count(exsl:node-set($content)/*)"/>
+    </xsl:apply-templates>
+  </xsl:template>
   <xsl:template match="@* | node()">
     <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
@@ -23,25 +70,14 @@
           <xsl:comment>
             <xsl:apply-templates mode="testtree" select="$hmitree"/>
           </xsl:comment>
+          <xsl:comment>
+            <xsl:apply-templates mode="testtree" select="exsl:node-set($indexed_hmitree)"/>
+          </xsl:comment>
           <xsl:apply-templates select="@* | node()"/>
         </xsl:copy>
         <script>
-          <xsl:text>function evaluate_js_from_descriptions() {
-</xsl:text>
-          <xsl:text>    var Page;
-</xsl:text>
-          <xsl:text>    var Input;
-</xsl:text>
-          <xsl:text>    var Display;
-</xsl:text>
-          <xsl:text>    var res = [];
-</xsl:text>
-          <xsl:variable name="midmark">
-            <xsl:text>
-</xsl:text>
-            <xsl:value-of select="$mark"/>
-          </xsl:variable>
-          <xsl:apply-templates mode="code_from_descs" select="//*[contains(child::svg:desc, $midmark) or                                starts-with(child::svg:desc, $mark)]"/>
+          <xsl:text>var subscriptions = {
+</xsl:text>
           <xsl:text>    return res;
 </xsl:text>
           <xsl:text>}
@@ -96,6 +132,66 @@
 </xsl:text>
           <xsl:text>    };
 </xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>    var pending_updates = {};
+</xsl:text>
+          <xsl:text>    
+</xsl:text>
+          <xsl:text>    // subscription state, as it should be in hmi server
+</xsl:text>
+          <xsl:text>    // expected {index:period}
+</xsl:text>
+          <xsl:text>    var subscriptions = {};
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>    // subscription state as needed by widget now
+</xsl:text>
+          <xsl:text>    // expected {index:[widgets]};
+</xsl:text>
+          <xsl:text>    var subscribers = {};
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>    // return the diff in between curently subscribed and subscription
+</xsl:text>
+          <xsl:text>    function update_subscriptions() {
+</xsl:text>
+          <xsl:text>        let result = [];
+</xsl:text>
+          <xsl:text>        Object.keys(subscribers).forEach(index =&gt; {
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>            let previous_period = subscriptions[index];
+</xsl:text>
+          <xsl:text>            let new_period = Math.min(...widgets.map(widget =&gt; widget.period));
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>            if(previous_period != new_period) 
+</xsl:text>
+          <xsl:text>                result.push({index: index, period: new_period});
+</xsl:text>
+          <xsl:text>        })
+</xsl:text>
+          <xsl:text>    }
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>    function update_value(index, value) {
+</xsl:text>
+          <xsl:text>
+</xsl:text>
+          <xsl:text>    };
+</xsl:text>
+          <xsl:text>
+</xsl:text>
           <xsl:text>})();
 </xsl:text>
         </script>
@@ -159,11 +255,12 @@
     <xsl:text> </xsl:text>
     <xsl:value-of select="local-name()"/>
     <xsl:text> </xsl:text>
-    <xsl:value-of select="@name"/>
-    <xsl:text> </xsl:text>
-    <xsl:value-of select="@type"/>
-    <xsl:text> </xsl:text>
-    <xsl:value-of select="@path"/>
+    <xsl:for-each select="@*">
+      <xsl:value-of select="local-name()"/>
+      <xsl:text>=</xsl:text>
+      <xsl:value-of select="."/>
+      <xsl:text> </xsl:text>
+    </xsl:for-each>
     <xsl:text>
 </xsl:text>
     <xsl:apply-templates mode="testtree" select="*">