Skip to content

Commit

Permalink
Fix issues with composite types due to valueOnIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 14, 2017
1 parent ce60321 commit b9ebcfb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
8 changes: 0 additions & 8 deletions src/style_manager/model/Properties.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
var Backbone = require('backbone');
var Property = require('./Property');
module.exports = Backbone.Collection.extend({
model: Property,
});
*/
import TypeableCollection from 'domain_abstract/model/TypeableCollection';
const Property = require('./Property');

Expand Down
16 changes: 16 additions & 0 deletions src/style_manager/model/Property.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ module.exports = Backbone.Model.extend({
return result;
},

/**
* Parse a raw value, generally fetched from the target, for this property
* @param {string} value
* @return {string}
*/
parseValue(value) {
if (!this.get('functionName')) {
return value;
}

let valueStr = value + '';
let start = valueStr.indexOf('(') + 1;
let end = valueStr.lastIndexOf(')');
return valueStr.substring(start, end);
},

/**
* Get the default value
* @return {string}
Expand Down
24 changes: 14 additions & 10 deletions src/style_manager/view/PropertyCompositeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,21 @@ module.exports = PropertyView.extend({
* @return {string}
* */
valueOnIndex(index, view) {
var result = null;
var a = this.getComponentValue().split(' ');
if(a.length && a[index]){
result = a[index];
if(view && view.model && view.model.get('functionName')){
var v = this.fetchFromFunction(result);
if(v)
result = v;
}
let value;
const model = view.model;
const targetValue = this.getTargetValue({ignoreDefault: 1});

// If the target value of the composite is not empty I'll fetch
// the corresponding value from the requested index, otherwise try
// to get the value of the sub-property
if (targetValue) {
const values = targetValue.split(' ');
value = model.parseValue(values[index]);
} else {
value = view.getTargetValue({ignoreCustomValue: 1});
}
return result;

return value;
},

});
1 change: 1 addition & 0 deletions src/style_manager/view/PropertyView.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ module.exports = Backbone.View.extend({
}

result = target.getStyle()[model.get('property')];
result = model.parseValue(result);

if (!result && !opts.ignoreDefault) {
result = this.getDefaultValue();
Expand Down

0 comments on commit b9ebcfb

Please sign in to comment.