|
@@ -379,7 +379,10 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo
|
|
var configConditions = this.get('config.configConditions');
|
|
var configConditions = this.get('config.configConditions');
|
|
if (configConditions && configConditions.length) {
|
|
if (configConditions && configConditions.length) {
|
|
this.configValueObserver();
|
|
this.configValueObserver();
|
|
- this.addObserver('config.value', this, this.configValueObserver);
|
|
|
|
|
|
+ var isConditionConfigDependent = configConditions.filterProperty('resource', 'config').length;
|
|
|
|
+ if (isConditionConfigDependent) {
|
|
|
|
+ this.addObserver('config.value', this, this.configValueObserver);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -393,41 +396,68 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo
|
|
var configConditions = this.get('config.configConditions');
|
|
var configConditions = this.get('config.configConditions');
|
|
var serviceName = this.get('config.serviceName');
|
|
var serviceName = this.get('config.serviceName');
|
|
var serviceConfigs = this.get('controller.stepConfigs').findProperty('serviceName',serviceName).get('configs');
|
|
var serviceConfigs = this.get('controller.stepConfigs').findProperty('serviceName',serviceName).get('configs');
|
|
|
|
+ var isConditionTrue;
|
|
configConditions.forEach(function(configCondition){
|
|
configConditions.forEach(function(configCondition){
|
|
var ifStatement = configCondition.get("if");
|
|
var ifStatement = configCondition.get("if");
|
|
- var splitIfCondition = ifStatement.split('===');
|
|
|
|
- var ifCondition = splitIfCondition[0];
|
|
|
|
- var result = splitIfCondition[1] || "true";
|
|
|
|
- var conditionalConfigName = configCondition.get("configName");
|
|
|
|
- var conditionalConfigFileName = configCondition.get("fileName");
|
|
|
|
- var parseIfConditionVal = ifCondition;
|
|
|
|
- var regex = /\$\{.*?\}/g;
|
|
|
|
- var configStrings = ifCondition.match(regex);
|
|
|
|
- configStrings.forEach(function(_configString){
|
|
|
|
- var configObject = _configString.substring(2, _configString.length-1).split("/");
|
|
|
|
- var config = serviceConfigs.filterProperty('filename',configObject[0] + '.xml').findProperty('name', configObject[1]);
|
|
|
|
- if (config) {
|
|
|
|
- var configValue = config.get('value');
|
|
|
|
- parseIfConditionVal = parseIfConditionVal.replace(_configString, configValue);
|
|
|
|
- }
|
|
|
|
- }, this);
|
|
|
|
-
|
|
|
|
- var isConditionTrue = window.eval(JSON.stringify(parseIfConditionVal.trim())) === result.trim();
|
|
|
|
- var action = isConditionTrue ? configCondition.get("then") : configCondition.get("else");
|
|
|
|
- var valueAttributes = action.property_value_attributes;
|
|
|
|
- for (var key in valueAttributes) {
|
|
|
|
- if (valueAttributes.hasOwnProperty(key)) {
|
|
|
|
- var valueAttribute = App.StackConfigValAttributesMap[key] || key;
|
|
|
|
- var conditionalConfig = serviceConfigs.filterProperty('filename',conditionalConfigFileName).findProperty('name', conditionalConfigName);
|
|
|
|
- if (conditionalConfig) {
|
|
|
|
- conditionalConfig.set(valueAttribute, valueAttributes[key]);
|
|
|
|
|
|
+ if (configCondition.get("resource") === 'config') {
|
|
|
|
+ var splitIfCondition = ifStatement.split('===');
|
|
|
|
+ var ifCondition = splitIfCondition[0];
|
|
|
|
+ var result = splitIfCondition[1] || "true";
|
|
|
|
+ var parseIfConditionVal = ifCondition;
|
|
|
|
+ var regex = /\$\{.*?\}/g;
|
|
|
|
+ var configStrings = ifCondition.match(regex);
|
|
|
|
+ configStrings.forEach(function(_configString){
|
|
|
|
+ var configObject = _configString.substring(2, _configString.length-1).split("/");
|
|
|
|
+ var config = serviceConfigs.filterProperty('filename',configObject[0] + '.xml').findProperty('name', configObject[1]);
|
|
|
|
+ if (config) {
|
|
|
|
+ var configValue = config.get('value');
|
|
|
|
+ parseIfConditionVal = parseIfConditionVal.replace(_configString, configValue);
|
|
}
|
|
}
|
|
|
|
+ }, this);
|
|
|
|
+
|
|
|
|
+ isConditionTrue = window.eval(JSON.stringify(parseIfConditionVal.trim())) === result.trim();
|
|
|
|
+ this.changeConfigAttribute(configCondition, isConditionTrue);
|
|
|
|
+ } else if (configCondition.get("resource") === 'service') {
|
|
|
|
+ var service = App.Service.find().findProperty('serviceName', ifStatement);
|
|
|
|
+ var serviceName;
|
|
|
|
+ if (service) {
|
|
|
|
+ isConditionTrue = true;
|
|
|
|
+ } else if (!service && this.get('controller.allSelectedServiceNames') && this.get('controller.allSelectedServiceNames').length) {
|
|
|
|
+ isConditionTrue = this.get('controller.allSelectedServiceNames').contains(ifStatement);
|
|
|
|
+ } else {
|
|
|
|
+ isConditionTrue = false;
|
|
}
|
|
}
|
|
|
|
+ this.changeConfigAttribute(configCondition, isConditionTrue);
|
|
}
|
|
}
|
|
}, this);
|
|
}, this);
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param configCondition {App.ConfigCondition}
|
|
|
|
+ * @param isConditionTrue {boolean}
|
|
|
|
+ */
|
|
|
|
+ changeConfigAttribute: function(configCondition, isConditionTrue) {
|
|
|
|
+ var conditionalConfigName = configCondition.get("configName");
|
|
|
|
+ var conditionalConfigFileName = configCondition.get("fileName");
|
|
|
|
+ var serviceName = this.get('config.serviceName');
|
|
|
|
+ var serviceConfigs = this.get('controller.stepConfigs').findProperty('serviceName',serviceName).get('configs');
|
|
|
|
+ var action = isConditionTrue ? configCondition.get("then") : configCondition.get("else");
|
|
|
|
+ var valueAttributes = action.property_value_attributes;
|
|
|
|
+ for (var key in valueAttributes) {
|
|
|
|
+ if (valueAttributes.hasOwnProperty(key)) {
|
|
|
|
+ var valueAttribute = App.StackConfigValAttributesMap[key] || key;
|
|
|
|
+ var conditionalConfig = serviceConfigs.filterProperty('filename',conditionalConfigFileName).findProperty('name', conditionalConfigName);
|
|
|
|
+ if (conditionalConfig) {
|
|
|
|
+ conditionalConfig.set(valueAttribute, valueAttributes[key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* set widget value same as config value
|
|
* set widget value same as config value
|
|
* useful for widgets that work with intermediate config value, not original
|
|
* useful for widgets that work with intermediate config value, not original
|