svghmi/gen_index_xhtml.xslt
branchsvghmi
changeset 2996 14635b09d329
parent 2994 b6a9ef7f7e43
child 2997 2f298089e32e
equal deleted inserted replaced
2995:7769e7c7f925 2996:14635b09d329
   656   <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']">
   656   <xsl:template mode="inline_svg" match="sodipodi:namedview[@units!='px' or @inkscape:document-units!='px']">
   657     <xsl:message terminate="yes">
   657     <xsl:message terminate="yes">
   658       <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text>
   658       <xsl:text>All units must be set to "px" in Inkscape's document properties</xsl:text>
   659     </xsl:message>
   659     </xsl:message>
   660   </xsl:template>
   660   </xsl:template>
   661   <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages)]/descendant-or-self::svg:use"/>
   661   <xsl:variable name="hmi_lists_descs" select="$parsed_widgets/widget[@type = 'List']"/>
       
   662   <xsl:variable name="hmi_lists" select="$hmi_elements[@id = $hmi_lists_descs/@id]"/>
       
   663   <xsl:variable name="targets_not_to_unlink" select="$hmi_elements[@id = $hmi_lists/@id]/descendant::svg:*"/>
       
   664   <xsl:variable name="to_unlink" select="$hmi_elements[not(@id = $hmi_pages/@id)]/descendant-or-self::svg:use"/>
   662   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:use">
   665   <xsl:template xmlns="http://www.w3.org/2000/svg" mode="inline_svg" match="svg:use">
       
   666     <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/>
   663     <xsl:choose>
   667     <xsl:choose>
   664       <xsl:when test="@id = $to_unlink/@id">
   668       <xsl:when test="@id = $to_unlink/@id and not($targetid = $targets_not_to_unlink/@id)">
   665         <xsl:call-template name="unlink_clone"/>
   669         <xsl:call-template name="unlink_clone">
       
   670           <xsl:with-param name="targetid" select="$targetid"/>
       
   671         </xsl:call-template>
   666       </xsl:when>
   672       </xsl:when>
   667       <xsl:otherwise>
   673       <xsl:otherwise>
   668         <xsl:copy>
   674         <xsl:copy>
   669           <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   675           <xsl:apply-templates mode="inline_svg" select="@* | node()"/>
   670         </xsl:copy>
   676         </xsl:copy>
   697       <xsl:text>style</xsl:text>
   703       <xsl:text>style</xsl:text>
   698     </name>
   704     </name>
   699   </xsl:variable>
   705   </xsl:variable>
   700   <xsl:variable name="merge_use_attrs" select="exsl:node-set($_merge_use_attrs)"/>
   706   <xsl:variable name="merge_use_attrs" select="exsl:node-set($_merge_use_attrs)"/>
   701   <xsl:template xmlns="http://www.w3.org/2000/svg" name="unlink_clone">
   707   <xsl:template xmlns="http://www.w3.org/2000/svg" name="unlink_clone">
   702     <xsl:variable name="targetid" select="substring-after(@xlink:href,'#')"/>
   708     <xsl:param name="targetid"/>
   703     <xsl:variable name="target" select="//svg:*[@id = $targetid]"/>
   709     <xsl:variable name="target" select="//svg:*[@id = $targetid]"/>
   704     <g>
   710     <g>
   705       <xsl:choose>
   711       <xsl:choose>
   706         <xsl:when test="$target[self::svg:g]">
   712         <xsl:when test="$target[self::svg:g]">
   707           <xsl:for-each select="@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]">
   713           <xsl:for-each select="@*[not(local-name() = $excluded_use_attrs/name | $merge_use_attrs)]">
   810     <xsl:text>
   816     <xsl:text>
   811 </xsl:text>
   817 </xsl:text>
   812     <xsl:text>Unlinked :
   818     <xsl:text>Unlinked :
   813 </xsl:text>
   819 </xsl:text>
   814     <xsl:for-each select="$to_unlink">
   820     <xsl:for-each select="$to_unlink">
       
   821       <xsl:value-of select="@id"/>
       
   822       <xsl:text>
       
   823 </xsl:text>
       
   824     </xsl:for-each>
       
   825     <xsl:text>Not to unlink :
       
   826 </xsl:text>
       
   827     <xsl:for-each select="$targets_not_to_unlink">
   815       <xsl:value-of select="@id"/>
   828       <xsl:value-of select="@id"/>
   816       <xsl:text>
   829       <xsl:text>
   817 </xsl:text>
   830 </xsl:text>
   818     </xsl:for-each>
   831     </xsl:for-each>
   819     <xsl:text>
   832     <xsl:text>
  2147 </xsl:text>
  2160 </xsl:text>
  2148   </xsl:template>
  2161   </xsl:template>
  2149   <xsl:template mode="widget_class" match="widget[@type='JsonTable']">
  2162   <xsl:template mode="widget_class" match="widget[@type='JsonTable']">
  2150     <xsl:text>class JsonTableWidget extends Widget{
  2163     <xsl:text>class JsonTableWidget extends Widget{
  2151 </xsl:text>
  2164 </xsl:text>
       
  2165     <xsl:text>    do_http_request() {
       
  2166 </xsl:text>
       
  2167     <xsl:text>        const query = {
       
  2168 </xsl:text>
       
  2169     <xsl:text>             offset: '42',
       
  2170 </xsl:text>
       
  2171     <xsl:text>             filter: '*powerloss*',
       
  2172 </xsl:text>
       
  2173     <xsl:text>             args: this.args
       
  2174 </xsl:text>
       
  2175     <xsl:text>        };
       
  2176 </xsl:text>
       
  2177     <xsl:text>
       
  2178 </xsl:text>
       
  2179     <xsl:text>        const options = {
       
  2180 </xsl:text>
       
  2181     <xsl:text>             method: 'POST',
       
  2182 </xsl:text>
       
  2183     <xsl:text>             body: JSON.stringify(query),
       
  2184 </xsl:text>
       
  2185     <xsl:text>             headers: {'Content-Type': 'application/json'}
       
  2186 </xsl:text>
       
  2187     <xsl:text>        }
       
  2188 </xsl:text>
       
  2189     <xsl:text>
       
  2190 </xsl:text>
       
  2191     <xsl:text>        fetch(this.args[0], options)
       
  2192 </xsl:text>
       
  2193     <xsl:text>            .then(res =&gt; res.json())
       
  2194 </xsl:text>
       
  2195     <xsl:text>            .then(this.spread_json_data);
       
  2196 </xsl:text>
       
  2197     <xsl:text>
       
  2198 </xsl:text>
       
  2199     <xsl:text>    }
       
  2200 </xsl:text>
       
  2201     <xsl:text>    dispatch(value) {
       
  2202 </xsl:text>
       
  2203     <xsl:text>        this.do_http_request();
       
  2204 </xsl:text>
       
  2205     <xsl:text>    }
       
  2206 </xsl:text>
  2152     <xsl:text>    on_click(evt) {
  2207     <xsl:text>    on_click(evt) {
  2153 </xsl:text>
  2208 </xsl:text>
  2154     <xsl:text>        const query = {
  2209     <xsl:text>        this.do_http_request();
  2155 </xsl:text>
       
  2156     <xsl:text>             offset: '42',
       
  2157 </xsl:text>
       
  2158     <xsl:text>             filter: '*powerloss*',
       
  2159 </xsl:text>
       
  2160     <xsl:text>             args: this.args
       
  2161 </xsl:text>
       
  2162     <xsl:text>        };
       
  2163 </xsl:text>
       
  2164     <xsl:text>
       
  2165 </xsl:text>
       
  2166     <xsl:text>        const options = {
       
  2167 </xsl:text>
       
  2168     <xsl:text>             method: 'POST',
       
  2169 </xsl:text>
       
  2170     <xsl:text>             body: JSON.stringify(query),
       
  2171 </xsl:text>
       
  2172     <xsl:text>             headers: {'Content-Type': 'application/json'}
       
  2173 </xsl:text>
       
  2174     <xsl:text>        }
       
  2175 </xsl:text>
       
  2176     <xsl:text>
       
  2177 </xsl:text>
       
  2178     <xsl:text>        fetch(this.args[0], options)
       
  2179 </xsl:text>
       
  2180     <xsl:text>            .then(res =&gt; res.json())
       
  2181 </xsl:text>
       
  2182     <xsl:text>            .then(res =&gt; console.log(res));
       
  2183 </xsl:text>
       
  2184     <xsl:text>
       
  2185 </xsl:text>
  2210 </xsl:text>
  2186     <xsl:text>    }
  2211     <xsl:text>    }
  2187 </xsl:text>
  2212 </xsl:text>
  2188     <xsl:text>    init() {
  2213     <xsl:text>    init() {
  2189 </xsl:text>
  2214 </xsl:text>
  2190     <xsl:text>        this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
  2215     <xsl:text>        this.element.setAttribute("onclick", "hmi_widgets['"+this.element_id+"'].on_click(evt)");
  2191 </xsl:text>
  2216 </xsl:text>
  2192     <xsl:text>    }
  2217     <xsl:text>    }
  2193 </xsl:text>
  2218 </xsl:text>
       
  2219     <xsl:text>}
       
  2220 </xsl:text>
       
  2221   </xsl:template>
       
  2222   <xsl:template mode="json_table_elt_render" match="svg:*">
       
  2223     <xsl:message terminate="no">
       
  2224       <xsl:text>JsonTable Widget can't contain element of type </xsl:text>
       
  2225       <xsl:value-of select="local-name()"/>
       
  2226       <xsl:text>.</xsl:text>
       
  2227     </xsl:message>
       
  2228   </xsl:template>
       
  2229   <xsl:template mode="json_table_elt_render" match="svg:use">
       
  2230     <xsl:param name="value_expr"/>
       
  2231     <xsl:text>    console.log("</xsl:text>
       
  2232     <xsl:value-of select="@id"/>
       
  2233     <xsl:text>", "</xsl:text>
       
  2234     <xsl:value-of select="$value_expr"/>
       
  2235     <xsl:text>", </xsl:text>
       
  2236     <xsl:value-of select="$value_expr"/>
       
  2237     <xsl:text>);
       
  2238 </xsl:text>
       
  2239   </xsl:template>
       
  2240   <xsl:template mode="json_table_elt_render" match="svg:text">
       
  2241     <xsl:param name="value_expr"/>
       
  2242     <xsl:text>    console.log("</xsl:text>
       
  2243     <xsl:value-of select="@id"/>
       
  2244     <xsl:text>", "</xsl:text>
       
  2245     <xsl:value-of select="$value_expr"/>
       
  2246     <xsl:text>", </xsl:text>
       
  2247     <xsl:value-of select="$value_expr"/>
       
  2248     <xsl:text>);
       
  2249 </xsl:text>
       
  2250   </xsl:template>
       
  2251   <xsl:template mode="json_table_render" match="svg:*">
       
  2252     <xsl:param name="objname"/>
       
  2253     <xsl:apply-templates mode="json_table_elt_render" select=".">
       
  2254       <xsl:with-param name="value_expr">
       
  2255         <xsl:value-of select="$objname"/>
       
  2256         <xsl:value-of select="@inkscape:label"/>
       
  2257       </xsl:with-param>
       
  2258     </xsl:apply-templates>
       
  2259   </xsl:template>
       
  2260   <xsl:template mode="json_table_render" match="svg:g">
       
  2261     <xsl:param name="objname"/>
       
  2262     <xsl:text>let obj_</xsl:text>
       
  2263     <xsl:value-of select="@id"/>
       
  2264     <xsl:text> = </xsl:text>
       
  2265     <xsl:value-of select="$objname"/>
       
  2266     <xsl:value-of select="@inkscape:label"/>
       
  2267     <xsl:text>;
       
  2268 </xsl:text>
       
  2269     <xsl:apply-templates mode="json_table_render" select="*[@inkscape:label]">
       
  2270       <xsl:with-param name="objname">
       
  2271         <xsl:text>obj_</xsl:text>
       
  2272         <xsl:value-of select="@id"/>
       
  2273       </xsl:with-param>
       
  2274     </xsl:apply-templates>
       
  2275   </xsl:template>
       
  2276   <xsl:template mode="widget_defs" match="widget[@type='JsonTable']">
       
  2277     <xsl:param name="hmi_element"/>
       
  2278     <xsl:call-template name="defs_by_labels">
       
  2279       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
  2280       <xsl:with-param name="labels">
       
  2281         <xsl:text>data</xsl:text>
       
  2282       </xsl:with-param>
       
  2283     </xsl:call-template>
       
  2284     <xsl:call-template name="defs_by_labels">
       
  2285       <xsl:with-param name="hmi_element" select="$hmi_element"/>
       
  2286       <xsl:with-param name="labels">
       
  2287         <xsl:text>forward backward cursor</xsl:text>
       
  2288       </xsl:with-param>
       
  2289       <xsl:with-param name="mandatory" select="'no'"/>
       
  2290     </xsl:call-template>
       
  2291     <xsl:variable name="data_elt" select="$result_svg_ns//*[@id = $hmi_element/@id]/*[@inkscape:label = 'data']"/>
       
  2292     <xsl:text>spread_json_data: function(jdata) {
       
  2293 </xsl:text>
       
  2294     <xsl:text>    console.log(jdata);
       
  2295 </xsl:text>
       
  2296     <xsl:apply-templates mode="json_table_render" select="$data_elt/*">
       
  2297       <xsl:with-param name="objname" select="'jdata'"/>
       
  2298     </xsl:apply-templates>
  2194     <xsl:text>}
  2299     <xsl:text>}
  2195 </xsl:text>
  2300 </xsl:text>
  2196   </xsl:template>
  2301   </xsl:template>
  2197   <xsl:template name="jump_widget_activity">
  2302   <xsl:template name="jump_widget_activity">
  2198     <xsl:param name="hmi_element"/>
  2303     <xsl:param name="hmi_element"/>