SVGHMI: Starting to define JS side more in details.
--- a/svghmi/gen_index_xhtml.xslt Thu Sep 19 15:32:36 2019 +0200
+++ b/svghmi/gen_index_xhtml.xslt Fri Sep 20 13:38:58 2019 +0200
@@ -26,13 +26,25 @@
<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>
+ <xsl:text> return res;
+</xsl:text>
+ <xsl:text>}
</xsl:text>
<xsl:text>(function(){
</xsl:text>
@@ -61,21 +73,41 @@
</html>
</xsl:template>
<xsl:template mode="code_from_descs" match="*">
- <xsl:text>function js_</xsl:text>
+ <xsl:text>{
+</xsl:text>
+ <xsl:text> var path, role, name, priv;
+</xsl:text>
+ <xsl:text> var id = "</xsl:text>
<xsl:value-of select="@id"/>
- <xsl:text>() {
+ <xsl:text>";
</xsl:text>
- <xsl:text>var path, role, path, priv;
+ <xsl:if test="«@inkscape:label»">
+ <xsl:text>name = "</xsl:text>
+ <xsl:value-of select="@inkscape:label"/>
+ <xsl:text>";
</xsl:text>
- <xsl:text>
+ </xsl:if>
+ <xsl:text>/* -------------- */
</xsl:text>
<xsl:value-of select="substring-after(svg:desc, $mark)"/>
<xsl:text>
</xsl:text>
+ <xsl:text> /* -------------- */
+</xsl:text>
+ <xsl:text> res.push({
+</xsl:text>
+ <xsl:text> path:path,
+</xsl:text>
+ <xsl:text> role:role,
+</xsl:text>
+ <xsl:text> name:name,
+</xsl:text>
+ <xsl:text> priv:priv
+</xsl:text>
+ <xsl:text> })
+</xsl:text>
<xsl:text>}
</xsl:text>
- <xsl:text>
-</xsl:text>
</xsl:template>
<xsl:template mode="testgeo" match="bbox">
<xsl:text>ID: </xsl:text>
--- a/svghmi/gen_index_xhtml.ysl2 Thu Sep 19 15:32:36 2019 +0200
+++ b/svghmi/gen_index_xhtml.ysl2 Fri Sep 20 13:38:58 2019 +0200
@@ -50,11 +50,21 @@
apply "@* | node()";
}
script{
+ ||
+ function evaluate_js_from_descriptions() {
+ var Page;
+ var Input;
+ var Display;
+ var res = [];
+ ||
variable "midmark" > \n«$mark»
apply """//*[contains(child::svg:desc, $midmark) or \
- starts-with(child::svg:desc, $mark)]""",
+ starts-with(child::svg:desc, $mark)]""",2
mode="code_from_descs";
- |
+ ||
+ return res;
+ }
+ ||
/*TODO add :
- pages content
@@ -68,13 +78,33 @@
}
template "*", mode="code_from_descs" {
- | function js_«@id»() {
- | var path, role, path, priv;
- |
+ ||
+ {
+ var path, role, name, priv;
+ var id = "«@id»";
+ ||
+
+ /* if label is used, use it as default name */
+ if "«@inkscape:label»"
+ |> name = "«@inkscape:label»";
+
+ | /* -------------- */
+
+ // this breaks indent, but fixing indent could break string literals
value "substring-after(svg:desc, $mark)";
- |
- | }
- |
+ // nobody reads generated code anyhow...
+
+ ||
+
+ /* -------------- */
+ res.push({
+ path:path,
+ role:role,
+ name:name,
+ priv:priv
+ })
+ }
+ ||
}
--- a/svghmi/svghmi.js Thu Sep 19 15:32:36 2019 +0200
+++ b/svghmi/svghmi.js Fri Sep 20 13:38:58 2019 +0200
@@ -1,11 +1,22 @@
+// svghmi.js
+
(function(){
- var relative_URI = window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws');
- var ws = new WebSocket(relative_URI);
+ // Open WebSocket to relative "/ws" address
+ var ws = new WebSocket(window.location.href.replace(/^http(s?:\/\/[^\/]*)\/.*$/, 'ws$1/ws'));
+
+ // Register message reception handler
ws.onmessage = function (evt) {
+ // TODO : dispatch and cache hmi tree updates
+
var received_msg = evt.data;
alert("Message is received..."+received_msg);
};
+
+ // Once connection established
ws.onopen = function (evt) {
+ // TODO : enable the HMI (was previously offline, or just starts)
+ // show main page
+
ws.send("test");
};
})();