SVGHMI: Check that explicit relative page jump path is consistant with destination page reference path. svghmi
authorEdouard Tisserant
Thu, 26 Mar 2020 11:17:34 +0100
branchsvghmi
changeset 2900 3ef217f525ff
parent 2899 f1baf2d0552c
child 2901 3f5194bba67d
SVGHMI: Check that explicit relative page jump path is consistant with destination page reference path.
svghmi/hmi_tree.ysl2
svghmi/widget_jump.ysl2
--- a/svghmi/hmi_tree.ysl2	Wed Mar 25 14:09:15 2020 +0100
+++ b/svghmi/hmi_tree.ysl2	Thu Mar 26 11:17:34 2020 +0100
@@ -116,6 +116,13 @@
     result "string-length($ancest) > 0 and starts-with($descend,$ancest)";
 }
 
+def "func:same_class_paths" {
+    param "a";
+    param "b";
+    const "class_a", "$indexed_hmitree/*[@hmipath = $a]/@class";
+    const "class_b", "$indexed_hmitree/*[@hmipath = $b]/@class";
+    result "$class_a and $class_b and $class_a = $class_b";
+}
 
 // Debug data
 template "*", mode="testtree"{
--- a/svghmi/widget_jump.ysl2	Wed Mar 25 14:09:15 2020 +0100
+++ b/svghmi/widget_jump.ysl2	Thu Mar 26 11:17:34 2020 +0100
@@ -2,6 +2,17 @@
 
 template "widget[@type='Jump']", mode="widget_defs" {
     param "hmi_element";
+
+    /* check that given path is compatible with page's reference path */
+    if "count(arg) > 0 and count(path) > 0" {
+        const "target_page_name", "arg[1]/@value";
+        const "target_page_desc", "$hmi_pages_descs[arg[1]/@value = $target_page_name]";
+        const "target_page_path", "$target_page_desc/path[1]/@value";
+        if "not(func:same_class_paths($target_page_path, path[1]/@value))"
+            warning > Jump id="«@id»" to page "«$target_page_name»" with incompatible path "«path[1]/@value»"
+    }
+    /* TODO check that path is also matching in case of implicit local jump (no page name given) */
+
     |     on_click: function(evt) {
     |         const index = this.indexes.length > 0 ? this.indexes[0] + this.offset : undefined;
     |         switch_page(this.args[0], index);