# HG changeset patch # User Edouard Tisserant # Date 1589122869 -7200 # Node ID b5dccd0d99ac0591681496d6325b67238309260f # Parent 15bebe9a2806a86d88a20aa2207fb85590a78c45 SVGHMI: clean up dead code, update generated xslt. diff -r 15bebe9a2806 -r b5dccd0d99ac svghmi/gen_index_xhtml.xslt --- a/svghmi/gen_index_xhtml.xslt Sun May 10 16:36:41 2020 +0200 +++ b/svghmi/gen_index_xhtml.xslt Sun May 10 17:01:09 2020 +0200 @@ -784,69 +784,54 @@ + + + " + + " + + , + + + + + + + + + Widget + + id=" + + " : No match for path " + + " in HMI tree + + + + + + , + + + + + " ": new - Widget ({ - - args: [ - - - " - - " - - , - - - - - ], - - offset: 0, - - indexes: [ - - - - - - Widget - - id=" - - " : No match for path " - - " in HMI tree - - - - - - /* - - */ - - , - - - - - - - ], - - element: id(" + Widget (" - "), + ",[ + + ],[ + + ],{ - - - }) , @@ -885,12 +870,78 @@ class Widget { - constructor(members){ + constructor(elt_id,args,indexes,members){ + + this.element = id(elt_id); + + this.args = args; + + this.indexes = indexes; + + this.offset = 0; Object.keys(members).forEach(prop => this[prop]=members[prop]); } + unsub(){ + + /* remove subsribers */ + + for(let index of this.indexes){ + + let idx = index + this.offset; + + subscribers[idx].delete(this); + + } + + this.offset = 0; + + } + + + + sub(new_offset=0){ + + /* set the offset because relative */ + + this.offset = new_offset; + + /* add this's subsribers */ + + for(let index of this.indexes){ + + subscribers[index + new_offset].add(this); + + } + + need_cache_apply.push(this); + + } + + + + apply_cache() { + + for(let index of this.indexes){ + + /* dispatch current cache in newly opened page widgets */ + + let realindex = index+this.offset; + + let cached_val = cache[realindex]; + + if(cached_val != undefined) + + dispatch_value_to_widget(this, realindex, cached_val, cached_val); + + } + + } + + + } @@ -941,15 +992,6 @@ - - sub: subscribe, - - unsub: unsubscribe, - - apply_cache: widget_apply_cache, - - - @@ -1825,135 +1867,114 @@ item_offset: 0, - on_click: foreach_onclick, - - - - sub: foreach_subscribe, - - unsub: foreach_unsubscribe, - - apply_cache: foreach_apply_cache, - - - - - - - /* - - */ - - - - function foreach_unsubscribe(){ - - for(let item of this.items){ - - for(let widget of item) { - - unsubscribe.call(widget); + + + class ForEachWidget extends Widget{ + + unsub(){ + + for(let item of this.items){ + + for(let widget of item) { + + widget.unsub(); + + } } + this.offset = 0; + } - this.offset = 0; + + + foreach_widgets_do(new_offset, todo){ + + this.offset = new_offset; + + for(let i = 0; i < this.items.length; i++) { + + let item = this.items[i]; + + let orig_item_index = this.index_pool[i]; + + let item_index = this.index_pool[i+this.item_offset]; + + let item_index_offset = item_index - orig_item_index; + + for(let widget of item) { + + todo(widget).call(widget, new_offset + item_index_offset); + + } + + } + + } + + + + sub(new_offset=0){ + + this.foreach_widgets_do(new_offset, w=>w.sub); + + } + + + + apply_cache() { + + this.foreach_widgets_do(this.offset, w=>w.apply_cache); + + } + + + + on_click(opstr, evt) { + + let new_item_offset = eval(String(this.item_offset)+opstr); + + if(new_item_offset + this.items.length > this.index_pool.length) { + + if(this.item_offset + this.items.length == this.index_pool.length) + + new_item_offset = 0; + + else + + new_item_offset = this.index_pool.length - this.items.length; + + } else if(new_item_offset < 0) { + + if(this.item_offset == 0) + + new_item_offset = this.index_pool.length - this.items.length; + + else + + new_item_offset = 0; + + } + + this.item_offset = new_item_offset; + + this.unsub(); + + this.sub(this.offset); + + update_subscriptions(); + + need_cache_apply.push(this); + + jumps_need_update = true; + + requestHMIAnimation(); + + } } - - - function foreach_widgets_do(new_offset, todo){ - - this.offset = new_offset; - - for(let i = 0; i < this.items.length; i++) { - - let item = this.items[i]; - - let orig_item_index = this.index_pool[i]; - - let item_index = this.index_pool[i+this.item_offset]; - - let item_index_offset = item_index - orig_item_index; - - for(let widget of item) { - - todo.call(widget, new_offset + item_index_offset); - - } - - } - - } - - - - function foreach_subscribe(new_offset=0){ - - foreach_widgets_do.call(this, new_offset, subscribe); - - } - - - - function foreach_apply_cache() { - - foreach_widgets_do.call(this, this.offset, widget_apply_cache); - - } - - - - function foreach_onclick(opstr, evt) { - - new_item_offset = eval(String(this.item_offset)+opstr) - - if(new_item_offset + this.items.length > this.index_pool.length) { - - if(this.item_offset + this.items.length == this.index_pool.length) - - new_item_offset = 0; - - else - - new_item_offset = this.index_pool.length - this.items.length; - - } else if(new_item_offset < 0) { - - if(this.item_offset == 0) - - new_item_offset = this.index_pool.length - this.items.length; - - else - - new_item_offset = 0; - - } - - this.item_offset = new_item_offset; - - off = this.offset; - - foreach_unsubscribe.call(this); - - foreach_subscribe.call(this,off); - - update_subscriptions(); - - need_cache_apply.push(this); - - jumps_need_update = true; - - requestHMIAnimation(); - - } - - - - - @@ -2180,45 +2201,22 @@ this.inactive_elt_style = this.inactive_elt.getAttribute("style"); - - this.disabled_elt_style = this.disabled_elt.getAttribute("style"); - - - }, - - - - - - - - - - - - - - - - - sub: subscribe, - - unsub: unsubscribe, - - apply_cache: widget_apply_cache, + this.disabled_elt_style = this.disabled_elt.getAttribute("style"); - sub: function(){}, - - unsub: function(){}, - - apply_cache: function(){}, + this.sub = function(){}; + + this.unsub = function(){}; + + this.apply_cache = function(){}; + }, + @@ -3344,74 +3342,6 @@ - function* chain(a,b){ - - yield* a; - - yield* b; - - }; - - - - function unsubscribe(){ - - /* remove subsribers */ - - for(let index of this.indexes){ - - let idx = index + this.offset; - - subscribers[idx].delete(this); - - } - - this.offset = 0; - - } - - - - function subscribe(new_offset=0){ - - /* set the offset because relative */ - - this.offset = new_offset; - - /* add this's subsribers */ - - for(let index of this.indexes){ - - subscribers[index + new_offset].add(this); - - } - - need_cache_apply.push(this); - - } - - - - function widget_apply_cache() { - - for(let index of this.indexes){ - - /* dispatch current cache in newly opened page widgets */ - - let realindex = index+this.offset; - - let cached_val = cache[realindex]; - - if(cached_val != undefined) - - dispatch_value_to_widget(this, realindex, cached_val, cached_val); - - } - - } - - - function switch_visible_page(page_name) { diff -r 15bebe9a2806 -r b5dccd0d99ac svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Sun May 10 16:36:41 2020 +0200 +++ b/svghmi/widgets_common.ysl2 Sun May 10 17:01:09 2020 +0200 @@ -38,7 +38,6 @@ | "«@id»": new «$widget/@type»Widget ("«@id»",[«$args»],[«$indexes»],{ apply "$widget", mode="widget_defs" with "hmi_element","."; - apply "$widget", mode="widget_subscribe" with "hmi_element","."; | })`if "position()!=last()" > ,` } @@ -124,13 +123,6 @@ | } } - -// default : normal subscribing -template "widget", mode="widget_subscribe" { -} -// page aren't subscribers -template "widget[@type='Page']", mode="widget_subscribe"; - function "defs_by_labels" { param "labels","''"; param "mandatory","'yes'";