widgets: dynamic address when split is true (#344)

This commit is contained in:
jean-emmanuel 2018-07-31 18:24:03 +02:00
parent 499de514f9
commit e5d8f0daa4
8 changed files with 65 additions and 37 deletions

View file

@ -1,5 +1,10 @@
# Changelog
## 0.34.4
- bug fixes
- widgets: dynamic `address` when `split` is `true`
## 0.34.3
- bug fixes

View file

@ -123,7 +123,7 @@ var WidgetManager = class WidgetManager extends EventEmitter {
data: updatedData || {
precision: widget.getProp('precision'),
preArgs: widget.getProp('preArgs'),
split: widget.split,
split: widget.getSplit(),
target: widget.getProp('target'),
address: widget.getProp('address'),
noSync: widget.getProp('noSync'),

View file

@ -223,6 +223,8 @@ class Widget extends EventEmitter {
}
getSplit() {}
static deepCopy(obj, precision){
var copy = obj
@ -520,6 +522,9 @@ class Widget extends EventEmitter {
address: propName == 'address' ? oldPropValue : this.getProp('address')
}
data[propName] = this.getProp(propName)
if (propName === 'address' && this.getSplit()) {
data['split'] = this.getSplit()
}
widgetManager.registerWidget(this, data, oldData)
return

View file

@ -56,8 +56,6 @@ module.exports = class Formula extends Widget {
this.formulaString = String(this.getProp('formula'))
this.conditionString = String(this.getProp('condition'))
this.split = typeof this.getProp('split') == 'object' && this.getProp('split').length ? this.getProp('split') : false
this.input = new Input({
props:{
...Input.defaults(),
@ -196,6 +194,12 @@ module.exports = class Formula extends Widget {
}
getSplit() {
return typeof this.getProp('split') == 'object' && this.getProp('split').length ? this.getProp('split') : false
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true

View file

@ -66,22 +66,6 @@ module.exports = class MultiXy extends Pad {
this.labels = typeof this.getProp('points') == 'object'
this.pointSize = parseInt(this.getProp('pointSize'))
this.split = this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 * this.npoints ?
this.getProp('split')
: (()=>{
var s={},
t
for (var i=0; i<this.npoints * 2;i=i+2) {
t = this.labels ? this.getProp('points')[i/2] : i/2
s[i]=this.getProp('address') + '/' + t + '/x'
s[i+1]=this.getProp('address') + '/' + t + '/y'
}
return s
})()
: false
this.pads = []
for (let i=this.npoints-1;i>=0;i--) {
@ -254,6 +238,25 @@ module.exports = class MultiXy extends Pad {
}
getSplit() {
return this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 * this.npoints ?
this.getProp('split')
: (()=>{
var s={},
t
for (var i=0; i<this.npoints * 2;i=i+2) {
t = this.labels ? this.getProp('points')[i/2] : i/2
s[i]=this.getProp('address') + '/' + t + '/x'
s[i+1]=this.getProp('address') + '/' + t + '/y'
}
return s
})()
: false
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true

View file

@ -57,12 +57,6 @@ module.exports = class Rgb extends Pad {
super(options)
this.split = this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 3 ?
this.getProp('split')
: [this.getProp('address') + '/r', this.getProp('address') + '/g', this.getProp('address') + '/b']
: false
this.hueWrapper = this.widget.appendChild(DOM.create('<div class="hue-wrapper"></div>'))
this.hue = new Fader({props:{
@ -212,6 +206,16 @@ module.exports = class Rgb extends Pad {
}
getSplit() {
return this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 3 ?
this.getProp('split')
: [this.getProp('address') + '/r', this.getProp('address') + '/g', this.getProp('address') + '/b']
: false
}
onPropChanged(propName, options, oldPropValue) {
if (super.onPropChanged(...arguments)) return true

View file

@ -62,12 +62,6 @@ module.exports = class Xy extends Pad {
super(options)
this.split = this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 ?
this.getProp('split')
: [this.getProp('address') + '/x', this.getProp('address') + '/y']
: false
this.faders = {
x: new Fader({props:{
...faderDefaults,
@ -281,6 +275,16 @@ module.exports = class Xy extends Pad {
}
getSplit() {
return this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 ?
this.getProp('split')
: [this.getProp('address') + '/x', this.getProp('address') + '/y']
: false
}
onPropChanged(propName, options, oldPropValue) {

View file

@ -232,12 +232,6 @@ module.exports = class Range extends Widget {
super({...options, html: html})
this.split = this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 ?
this.getProp('split')
: [this.getProp('address') + '/low', this.getProp('address') + '/high']
: false
this.wrapper = DOM.get(this.widget, '.wrapper')[0]
this.faders = [
@ -436,6 +430,15 @@ module.exports = class Range extends Widget {
}
getSplit() {
return this.getProp('split')?
typeof this.getProp('split') == 'object' && this.getProp('split').length == 2 ?
this.getProp('split')
: [this.getProp('address') + '/low', this.getProp('address') + '/high']
: false
}
onPropChanged(propName, options, oldPropValue) {