Compare commits

...

3 Commits

Author SHA1 Message Date
bc72fd54e8 clean out summaryWidgets initialize block, move logic to separate functions 2017-11-29 10:43:05 -08:00
9569ee2b56 refactor SummaryWidget.js initialize 2017-11-28 15:15:20 -08:00
cea6d4978a partial fix for issue #1804
Rename Rule.initCondition to Rule.addCondition for parity with Rule.removeCondition
2017-11-28 13:38:03 -08:00
3 changed files with 33 additions and 19 deletions

View File

@ -204,7 +204,7 @@ define([
this.deleteButton.on('click', this.remove);
this.duplicateButton.on('click', this.duplicate);
this.addConditionButton.on('click', function () {
self.initCondition();
self.addCondition();
});
this.toggleConfigButton.on('click', toggleConfig);
this.trigger.on('change', onTriggerInput);
@ -350,7 +350,7 @@ define([
* @param {Object} [config] The configuration to initialize this rule from,
* consisting of sourceCondition and index fields
*/
Rule.prototype.initCondition = function (config) {
Rule.prototype.addCondition = function (config) {
var ruleConfigById = this.domainObject.configuration.ruleConfigById,
newConfig,
sourceIndex = config && config.index,
@ -388,7 +388,7 @@ define([
this.config.conditions.forEach(function (condition, index) {
var newCondition = new Condition(condition, index, self.conditionManager);
newCondition.on('remove', self.removeCondition, self);
newCondition.on('duplicate', self.initCondition, self);
newCondition.on('duplicate', self.addCondition, self);
newCondition.on('change', self.onConditionChange, self);
self.conditions.push(newCondition);
});

View File

@ -35,9 +35,25 @@ define([
this.domainObject = domainObject;
this.openmct = openmct;
this.initializeLocalVariables();
this.addHyperlink(domainObject.url, domainObject.openNewTab);
this.watchForChanges(openmct, domainObject);
this.addToggleSectionCallbacks();
this.addEditListener();
this.watchForChanges = this.watchForChanges.bind(this);
this.show = this.show.bind(this);
this.destroy = this.destroy.bind(this);
this.addRule = this.addRule.bind(this);
this.onEdit = this.onEdit.bind(this);
}
SummaryWidget.prototype.initializeLocalVariables = function () {
this.domainObject.configuration = this.domainObject.configuration || {};
this.domainObject.configuration.ruleConfigById = this.domainObject.configuration.ruleConfigById || {};
this.domainObject.configuration.ruleOrder = this.domainObject.configuration.ruleOrder || ['default'];
this.domainObject.configuration.testDataConfig = this.domainObject.configuration.testDataConfig || [{
object: '',
key: '',
@ -63,20 +79,11 @@ define([
this.conditionManager = new ConditionManager(this.domainObject, this.openmct);
this.testDataManager = new TestDataManager(this.domainObject, this.conditionManager, this.openmct);
};
this.watchForChanges = this.watchForChanges.bind(this);
this.show = this.show.bind(this);
this.destroy = this.destroy.bind(this);
this.addRule = this.addRule.bind(this);
this.onEdit = this.onEdit.bind(this);
SummaryWidget.prototype.addToggleSectionCallbacks = function () {
this.addHyperlink(domainObject.url, domainObject.openNewTab);
this.watchForChanges(openmct, domainObject);
var id = this.domainObject.identifier.key,
self = this,
oldDomainObject,
statusCapability;
var self = this;
/**
* Toggles the configuration area for test data in the view
@ -97,8 +104,15 @@ define([
self.toggleRulesControl.toggleClass('expanded');
}
this.toggleRulesControl.on('click', toggleRules);
};
openmct.$injector.get('objectService')
SummaryWidget.prototype.addEditListener = function () {
var oldDomainObject,
statusCapability,
self = this,
id = this.domainObject.identifier.key;
this.openmct.$injector.get('objectService')
.getObjects([id])
.then(function (objs) {
oldDomainObject = objs[id];
@ -110,7 +124,7 @@ define([
self.onEdit([]);
}
});
}
};
/**
* adds or removes href to widget button and adds or removes openInNewTab

View File

@ -131,7 +131,7 @@ define(['../src/Rule', 'zepto'], function (Rule, $) {
});
it('allows initializing a new condition with a default configuration', function () {
testRule.initCondition();
testRule.addCondition();
expect(mockRuleConfig.conditions).toEqual([{
object: '',
key: '',
@ -151,7 +151,7 @@ define(['../src/Rule', 'zepto'], function (Rule, $) {
});
it('allows initializing a new condition from a given configuration', function () {
testRule.initCondition({
testRule.addCondition({
sourceCondition: {
object: 'object1',
key: 'key1',