SVGHMI: added Back widget.
--- a/svghmi/gen_index_xhtml.xslt Thu Mar 26 13:33:20 2020 +0100
+++ b/svghmi/gen_index_xhtml.xslt Thu Mar 26 14:21:52 2020 +0100
@@ -694,6 +694,33 @@
</xsl:otherwise>
</xsl:choose>
</func:function>
+ <xsl:template mode="widget_defs" match="widget[@type='Back']">
+ <xsl:param name="hmi_element"/>
+ <xsl:text> on_click: function(evt) {
+</xsl:text>
+ <xsl:text> console.log("Back !");
+</xsl:text>
+ <xsl:text> if(jump_history.length > 1){
+</xsl:text>
+ <xsl:text> jump_history.pop();
+</xsl:text>
+ <xsl:text> let [page_name, index] = jump_history.pop();
+</xsl:text>
+ <xsl:text> switch_page(page_name, index);
+</xsl:text>
+ <xsl:text> }
+</xsl:text>
+ <xsl:text> },
+</xsl:text>
+ <xsl:text> init: function() {
+</xsl:text>
+ <xsl:text> this.element.setAttribute("onclick", "hmi_widgets['</xsl:text>
+ <xsl:value-of select="$hmi_element/@id"/>
+ <xsl:text>'].on_click(evt)");
+</xsl:text>
+ <xsl:text> },
+</xsl:text>
+ </xsl:template>
<xsl:template mode="widget_defs" match="widget[@type='Display']">
<xsl:param name="hmi_element"/>
<xsl:text> frequency: 5,
@@ -890,7 +917,9 @@
</xsl:text>
<xsl:text> const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
</xsl:text>
- <xsl:text> switch_page(this.args[0], index);
+ <xsl:text> const name = this.args[0];
+</xsl:text>
+ <xsl:text> switch_page(name, index);
</xsl:text>
<xsl:text> },
</xsl:text>
@@ -1195,6 +1224,8 @@
</xsl:text>
<xsl:text>var need_cache_apply = [];
</xsl:text>
+ <xsl:text>var jump_history = [[default_page, undefined]];
+</xsl:text>
<xsl:text>
</xsl:text>
<xsl:text>function dispatch_value_to_widget(widget, index, value, oldval) {
@@ -1731,7 +1762,7 @@
</xsl:text>
<xsl:text> /* TODO LOG ERROR */
</xsl:text>
- <xsl:text> return;
+ <xsl:text> return false;
</xsl:text>
<xsl:text> }
</xsl:text>
@@ -1743,7 +1774,7 @@
</xsl:text>
<xsl:text>
</xsl:text>
- <xsl:text> switch_subscribed_page(page_name, page_index);
+ <xsl:text> return switch_subscribed_page(page_name, page_index);
</xsl:text>
<xsl:text>};
</xsl:text>
@@ -1935,7 +1966,7 @@
</xsl:text>
<xsl:text> /* TODO LOG ERROR */
</xsl:text>
- <xsl:text> return;
+ <xsl:text> return false;
</xsl:text>
<xsl:text> }
</xsl:text>
@@ -1975,6 +2006,14 @@
</xsl:text>
<xsl:text> requestHMIAnimation();
</xsl:text>
+ <xsl:text>
+</xsl:text>
+ <xsl:text> jump_history.push([page_name, page_index]);
+</xsl:text>
+ <xsl:text>
+</xsl:text>
+ <xsl:text> return true;
+</xsl:text>
<xsl:text>}
</xsl:text>
<xsl:text>
--- a/svghmi/svghmi.js Thu Mar 26 13:33:20 2020 +0100
+++ b/svghmi/svghmi.js Thu Mar 26 14:21:52 2020 +0100
@@ -3,6 +3,7 @@
var cache = hmitree_types.map(_ignored => undefined);
var updates = {};
var need_cache_apply = [];
+var jump_history = [[default_page, undefined]];
function dispatch_value_to_widget(widget, index, value, oldval) {
try {
@@ -271,13 +272,13 @@
if(current_subscribed_page != current_visible_page){
/* page switch already going */
/* TODO LOG ERROR */
- return;
+ return false;
}
if(page_name == undefined)
page_name = current_subscribed_page;
- switch_subscribed_page(page_name, page_index);
+ return switch_subscribed_page(page_name, page_index);
};
function* chain(a,b){
@@ -373,7 +374,7 @@
if(new_desc == undefined){
/* TODO LOG ERROR */
- return;
+ return false;
}
if(page_index == undefined){
@@ -393,6 +394,10 @@
current_subscribed_page = page_name;
requestHMIAnimation();
+
+ jump_history.push([page_name, page_index]);
+
+ return true;
}
function switch_visible_page(page_name) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/svghmi/widget_back.ysl2 Thu Mar 26 14:21:52 2020 +0100
@@ -0,0 +1,18 @@
+// widget_back.ysl2
+
+template "widget[@type='Back']", mode="widget_defs" {
+ param "hmi_element";
+
+ | on_click: function(evt) {
+ | console.log("Back !");
+ | if(jump_history.length > 1){
+ | jump_history.pop();
+ | let [page_name, index] = jump_history.pop();
+ | switch_page(page_name, index);
+ | }
+ | },
+ | init: function() {
+ | this.element.setAttribute("onclick", "hmi_widgets['«$hmi_element/@id»'].on_click(evt)");
+ | },
+}
+
--- a/svghmi/widget_jump.ysl2 Thu Mar 26 13:33:20 2020 +0100
+++ b/svghmi/widget_jump.ysl2 Thu Mar 26 14:21:52 2020 +0100
@@ -5,7 +5,8 @@
| on_click: function(evt) {
| const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
- | switch_page(this.args[0], index);
+ | const name = this.args[0];
+ | switch_page(name, index);
| },
| init: function() {
/* registering event this way does not "click" through svg:use