svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 3094 3e184f1e1012
parent 3092 96ffd8b1b016
child 3097 a098b2dd9dff
equal deleted inserted replaced
3093:9986e691c2ee 3094:3e184f1e1012
     1 <?xml version="1.0"?>
     1 <?xml version="1.0"?>
     2 <xsl:stylesheet xmlns:ns="beremiz" xmlns:definitions="definitions" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:func="http://exslt.org/functions" xmlns:epilogue="epilogue" xmlns:preamble="preamble" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:svg="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:str="http://exslt.org/strings" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:exsl="http://exslt.org/common" xmlns:declarations="declarations" xmlns:debug="debug" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions" extension-element-prefixes="ns func exsl regexp str dyn" version="1.0">
     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" xmlns:func="http://exslt.org/functions" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:debug="debug" xmlns:preamble="preamble" xmlns:declarations="declarations" xmlns:definitions="definitions" xmlns:epilogue="epilogue" xmlns:ns="beremiz" version="1.0" extension-element-prefixes="ns func exsl regexp str dyn" exclude-result-prefixes="ns func exsl regexp str dyn debug preamble epilogue declarations definitions">
     3   <xsl:output method="xml" cdata-section-elements="xhtml:script"/>
     3   <xsl:output cdata-section-elements="xhtml:script" method="xml"/>
     4   <xsl:variable name="svg" select="/svg:svg"/>
     4   <xsl:variable name="svg" select="/svg:svg"/>
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     5   <xsl:variable name="hmi_elements" select="//svg:*[starts-with(@inkscape:label, 'HMI:')]"/>
     6   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
     6   <xsl:variable name="hmitree" select="ns:GetHMITree()"/>
     7   <xsl:variable name="_categories">
     7   <xsl:variable name="_categories">
     8     <noindex>
     8     <noindex>
  3414 </xsl:text>
  3414 </xsl:text>
  3415     <xsl:text>            if(forward){
  3415     <xsl:text>            if(forward){
  3416 </xsl:text>
  3416 </xsl:text>
  3417     <xsl:text>                // reduce accounted menu size because of back button
  3417     <xsl:text>                // reduce accounted menu size because of back button
  3418 </xsl:text>
  3418 </xsl:text>
  3419     <xsl:text>                if(this.menu_offset != 0) spanslength--;
  3419     <xsl:text>                // in current view
       
  3420 </xsl:text>
       
  3421     <xsl:text>                if(this.menu_offset &gt; 0) spanslength--;
  3420 </xsl:text>
  3422 </xsl:text>
  3421     <xsl:text>                this.menu_offset = Math.min(
  3423     <xsl:text>                this.menu_offset = Math.min(
  3422 </xsl:text>
  3424 </xsl:text>
  3423     <xsl:text>                    contentlength - spans.length + 1,
  3425     <xsl:text>                    contentlength - spans.length + 1,
  3424 </xsl:text>
  3426 </xsl:text>
  3425     <xsl:text>                    this.menu_offset + spanslength);
  3427     <xsl:text>                    this.menu_offset + spanslength);
  3426 </xsl:text>
  3428 </xsl:text>
  3427     <xsl:text>            }else{
  3429     <xsl:text>            }else{
       
  3430 </xsl:text>
       
  3431     <xsl:text>                // reduce accounted menu size because of back button
       
  3432 </xsl:text>
       
  3433     <xsl:text>                // in view once scrolled
  3428 </xsl:text>
  3434 </xsl:text>
  3429     <xsl:text>                if(this.menu_offset - spanslength &gt; 0) spanslength--;
  3435     <xsl:text>                if(this.menu_offset - spanslength &gt; 0) spanslength--;
  3430 </xsl:text>
  3436 </xsl:text>
  3431     <xsl:text>                this.menu_offset = Math.max(
  3437     <xsl:text>                this.menu_offset = Math.max(
  3432 </xsl:text>
  3438 </xsl:text>
  3982     <xsl:text>    }
  3988     <xsl:text>    }
  3983 </xsl:text>
  3989 </xsl:text>
  3984     <xsl:text>}
  3990     <xsl:text>}
  3985 </xsl:text>
  3991 </xsl:text>
  3986   </xsl:template>
  3992   </xsl:template>
       
  3993   <xsl:template mode="widget_class" match="widget[@type='Input']">
       
  3994     <xsl:text>    class InputWidget extends Widget{
       
  3995 </xsl:text>
       
  3996     <xsl:text>         on_op_click(opstr) {
       
  3997 </xsl:text>
       
  3998     <xsl:text>             let new_val = this.change_hmi_value(0, opstr);
       
  3999 </xsl:text>
       
  4000     <xsl:text>         }
       
  4001 </xsl:text>
       
  4002     <xsl:text>         edit_callback(new_val) {
       
  4003 </xsl:text>
       
  4004     <xsl:text>             this.apply_hmi_value(0, new_val);
       
  4005 </xsl:text>
       
  4006     <xsl:text>         }
       
  4007 </xsl:text>
       
  4008     <xsl:text>    }
       
  4009 </xsl:text>
       
  4010   </xsl:template>
  3987   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  4011   <xsl:template mode="widget_defs" match="widget[@type='Input']">
  3988     <xsl:param name="hmi_element"/>
  4012     <xsl:param name="hmi_element"/>
  3989     <xsl:call-template name="defs_by_labels">
  4013     <xsl:variable name="key_pos_elt">
  3990       <xsl:with-param name="hmi_element" select="$hmi_element"/>
  4014       <xsl:call-template name="defs_by_labels">
  3991       <xsl:with-param name="labels">
  4015         <xsl:with-param name="hmi_element" select="$hmi_element"/>
  3992         <xsl:text>key_pos</xsl:text>
  4016         <xsl:with-param name="labels">
  3993       </xsl:with-param>
  4017           <xsl:text>key_pos</xsl:text>
  3994       <xsl:with-param name="mandatory" select="'no'"/>
  4018         </xsl:with-param>
  3995     </xsl:call-template>
  4019         <xsl:with-param name="mandatory" select="'no'"/>
       
  4020       </xsl:call-template>
       
  4021     </xsl:variable>
       
  4022     <xsl:value-of select="$key_pos_elt"/>
  3996     <xsl:variable name="value_elt">
  4023     <xsl:variable name="value_elt">
  3997       <xsl:call-template name="defs_by_labels">
  4024       <xsl:call-template name="defs_by_labels">
  3998         <xsl:with-param name="hmi_element" select="$hmi_element"/>
  4025         <xsl:with-param name="hmi_element" select="$hmi_element"/>
  3999         <xsl:with-param name="labels">
  4026         <xsl:with-param name="labels">
  4000           <xsl:text>value</xsl:text>
  4027           <xsl:text>value</xsl:text>
  4002         <xsl:with-param name="mandatory" select="'no'"/>
  4029         <xsl:with-param name="mandatory" select="'no'"/>
  4003       </xsl:call-template>
  4030       </xsl:call-template>
  4004     </xsl:variable>
  4031     </xsl:variable>
  4005     <xsl:variable name="have_value" select="string-length($value_elt)&gt;0"/>
  4032     <xsl:variable name="have_value" select="string-length($value_elt)&gt;0"/>
  4006     <xsl:value-of select="$value_elt"/>
  4033     <xsl:value-of select="$value_elt"/>
       
  4034     <xsl:variable name="edit_elt">
       
  4035       <xsl:call-template name="defs_by_labels">
       
  4036         <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
  4037         <xsl:with-param name="labels">
       
  4038           <xsl:text>edit</xsl:text>
       
  4039         </xsl:with-param>
       
  4040         <xsl:with-param name="mandatory" select="'no'"/>
       
  4041       </xsl:call-template>
       
  4042     </xsl:variable>
       
  4043     <xsl:variable name="have_edit" select="string-length($edit_elt)&gt;0"/>
       
  4044     <xsl:value-of select="$edit_elt"/>
  4007     <xsl:if test="$have_value">
  4045     <xsl:if test="$have_value">
  4008       <xsl:text>    frequency: 5,
  4046       <xsl:text>    frequency: 5,
  4009 </xsl:text>
  4047 </xsl:text>
  4010     </xsl:if>
  4048     </xsl:if>
  4011     <xsl:text>    last_val: undefined,
       
  4012 </xsl:text>
       
  4013     <xsl:text>    dispatch: function(value) {
  4049     <xsl:text>    dispatch: function(value) {
  4014 </xsl:text>
  4050 </xsl:text>
  4015     <xsl:text>        this.last_val = value;
  4051     <xsl:if test="$have_edit">
  4016 </xsl:text>
  4052       <xsl:text>        this.last_val = value;
       
  4053 </xsl:text>
       
  4054     </xsl:if>
  4017     <xsl:if test="$have_value">
  4055     <xsl:if test="$have_value">
  4018       <xsl:text>        this.value_elt.textContent = String(value);
  4056       <xsl:text>        this.value_elt.textContent = String(value);
  4019 </xsl:text>
  4057 </xsl:text>
  4020     </xsl:if>
  4058     </xsl:if>
  4021     <xsl:text>    },
  4059     <xsl:text>    },
  4022 </xsl:text>
  4060 </xsl:text>
  4023     <xsl:variable name="edit_elt_id" select="$hmi_element/*[@inkscape:label='edit'][1]/@id"/>
       
  4024     <xsl:text>    init: function() {
  4061     <xsl:text>    init: function() {
  4025 </xsl:text>
  4062 </xsl:text>
  4026     <xsl:if test="$edit_elt_id">
  4063     <xsl:if test="$have_edit">
  4027       <xsl:text>        id("</xsl:text>
  4064       <xsl:text>        this.edit_elt.onclick = () =&gt; edit_value(
  4028       <xsl:value-of select="$edit_elt_id"/>
  4065 </xsl:text>
  4029       <xsl:text>").setAttribute("onclick", "hmi_widgets['</xsl:text>
  4066       <xsl:text>            "</xsl:text>
  4030       <xsl:value-of select="$hmi_element/@id"/>
  4067       <xsl:value-of select="path/@value"/>
  4031       <xsl:text>'].on_edit_click()");
  4068       <xsl:text>", "</xsl:text>
       
  4069       <xsl:value-of select="path/@type"/>
       
  4070       <xsl:text>",
       
  4071 </xsl:text>
       
  4072       <xsl:text>            this, this.last_val, 
       
  4073 </xsl:text>
       
  4074       <xsl:choose>
       
  4075         <xsl:when test="string-length($key_pos_elt)&gt;0">
       
  4076           <xsl:text>            this.key_pos_elt.getBBox()
       
  4077 </xsl:text>
       
  4078         </xsl:when>
       
  4079         <xsl:otherwise>
       
  4080           <xsl:text>            undefined
       
  4081 </xsl:text>
       
  4082         </xsl:otherwise>
       
  4083       </xsl:choose>
       
  4084       <xsl:text>        );
  4032 </xsl:text>
  4085 </xsl:text>
  4033     </xsl:if>
  4086     </xsl:if>
  4034     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
  4087     <xsl:for-each select="$hmi_element/*[regexp:test(@inkscape:label,'^[=+\-].+')]">
  4035       <xsl:text>        id("</xsl:text>
  4088       <xsl:text>        id("</xsl:text>
  4036       <xsl:value-of select="@id"/>
  4089       <xsl:value-of select="@id"/>
  4037       <xsl:text>").setAttribute("onclick", "hmi_widgets['</xsl:text>
  4090       <xsl:text>").onclick = () =&gt; this.on_op_click("</xsl:text>
  4038       <xsl:value-of select="$hmi_element/@id"/>
       
  4039       <xsl:text>'].on_op_click('</xsl:text>
       
  4040       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
  4091       <xsl:value-of select="func:escape_quotes(@inkscape:label)"/>
  4041       <xsl:text>')");
  4092       <xsl:text>");
  4042 </xsl:text>
  4093 </xsl:text>
  4043     </xsl:for-each>
  4094     </xsl:for-each>
  4044     <xsl:text>    },
  4095     <xsl:text>    },
  4045 </xsl:text>
  4096 </xsl:text>
  4046     <xsl:text>    on_op_click: function(opstr) {
       
  4047 </xsl:text>
       
  4048     <xsl:text>        let new_val = this.change_hmi_value(0, opstr);
       
  4049 </xsl:text>
       
  4050     <xsl:text>    },
       
  4051 </xsl:text>
       
  4052     <xsl:text>    on_edit_click: function(opstr) {
       
  4053 </xsl:text>
       
  4054     <xsl:text>        var size = (typeof this.key_pos_elt !== 'undefined') ?  this.key_pos_elt.getBBox() : undefined
       
  4055 </xsl:text>
       
  4056     <xsl:text>        edit_value("</xsl:text>
       
  4057     <xsl:value-of select="path/@value"/>
       
  4058     <xsl:text>", "</xsl:text>
       
  4059     <xsl:value-of select="path/@type"/>
       
  4060     <xsl:text>", this, this.last_val, size);
       
  4061 </xsl:text>
       
  4062     <xsl:text>    },
       
  4063 </xsl:text>
       
  4064     <xsl:text>    edit_callback: function(new_val) {
       
  4065 </xsl:text>
       
  4066     <xsl:text>        this.apply_hmi_value(0, new_val);
       
  4067 </xsl:text>
       
  4068     <xsl:text>    },
       
  4069 </xsl:text>
       
  4070   </xsl:template>
  4097   </xsl:template>
  4071   <xsl:template mode="widget_class" match="widget[@type='JsonTable']">
  4098   <xsl:template mode="widget_class" match="widget[@type='JsonTable']">
  4072     <xsl:text>class JsonTableWidget extends Widget{
  4099     <xsl:text>class JsonTableWidget extends Widget{
  4073 </xsl:text>
  4100 </xsl:text>
  4074     <xsl:text>    // arbitrary defaults to avoid missing entries in query
  4101     <xsl:text>    // arbitrary defaults to avoid missing entries in query
  4096     <xsl:text>    }
  4123     <xsl:text>    }
  4097 </xsl:text>
  4124 </xsl:text>
  4098     <xsl:text>
  4125     <xsl:text>
  4099 </xsl:text>
  4126 </xsl:text>
  4100     <xsl:text>    do_http_request(...opt) {
  4127     <xsl:text>    do_http_request(...opt) {
  4101 </xsl:text>
       
  4102     <xsl:text>        console.log(opt);
       
  4103 </xsl:text>
  4128 </xsl:text>
  4104     <xsl:text>        const query = {
  4129     <xsl:text>        const query = {
  4105 </xsl:text>
  4130 </xsl:text>
  4106     <xsl:text>            args: this.args,
  4131     <xsl:text>            args: this.args,
  4107 </xsl:text>
  4132 </xsl:text>
  6225       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  6250       <xsl:text>Made with SVGHMI. https://beremiz.org</xsl:text>
  6226     </xsl:comment>
  6251     </xsl:comment>
  6227     <xsl:comment>
  6252     <xsl:comment>
  6228       <xsl:apply-templates select="document('')/*/debug:*"/>
  6253       <xsl:apply-templates select="document('')/*/debug:*"/>
  6229     </xsl:comment>
  6254     </xsl:comment>
  6230     <html xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/1999/xhtml">
  6255     <html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  6231       <head/>
  6256       <head/>
  6232       <body style="margin:0;overflow:hidden;user-select:none;touch-action:none;">
  6257       <body style="margin:0;overflow:hidden;user-select:none;touch-action:none;">
  6233         <xsl:copy-of select="$result_svg"/>
  6258         <xsl:copy-of select="$result_svg"/>
  6234         <script>
  6259         <script>
  6235           <xsl:text>
  6260           <xsl:text>