mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 05:38:12 +00:00
[Plot] Switched to $watchCollection on form model
This commit is contained in:
@ -78,8 +78,7 @@ define([
|
|||||||
"key": "PlotOptionsController",
|
"key": "PlotOptionsController",
|
||||||
"implementation": PlotOptionsController,
|
"implementation": PlotOptionsController,
|
||||||
"depends": [
|
"depends": [
|
||||||
"$scope",
|
"$scope"
|
||||||
"topic"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -45,13 +45,13 @@ define(
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {Scope} $scope the controller's Angular scope
|
* @param {Scope} $scope the controller's Angular scope
|
||||||
*/
|
*/
|
||||||
function PlotOptionsController($scope, topic) {
|
function PlotOptionsController($scope) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$scope = $scope;
|
this.$scope = $scope;
|
||||||
this.domainObject = $scope.domainObject;
|
this.domainObject = $scope.domainObject;
|
||||||
this.configuration = this.domainObject.getModel().configuration || {};
|
this.configuration = this.domainObject.getModel().configuration || {};
|
||||||
this.plotOptionsForm = new PlotOptionsForm(topic);
|
this.plotOptionsForm = new PlotOptionsForm();
|
||||||
this.composition = [];
|
this.composition = [];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -64,10 +64,6 @@ define(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.formListener = this.plotOptionsForm.listen(function(value){
|
|
||||||
self.updateConfiguration(value);
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set form structures on scope
|
Set form structures on scope
|
||||||
*/
|
*/
|
||||||
@ -78,11 +74,27 @@ define(
|
|||||||
$scope.$on("$destroy", function() {
|
$scope.$on("$destroy", function() {
|
||||||
//Clean up any listeners on destruction of controller
|
//Clean up any listeners on destruction of controller
|
||||||
self.mutationListener();
|
self.mutationListener();
|
||||||
self.formListener();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.defaultConfiguration();
|
this.defaultConfiguration();
|
||||||
this.updateChildren();
|
this.updateChildren();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup a number of watches for changes to form values. On
|
||||||
|
* change, update the model configuration via mutation
|
||||||
|
*/
|
||||||
|
$scope.$watchCollection('configuration.plot.yAxis', function(newValue, oldValue){
|
||||||
|
self.updateConfiguration(newValue, oldValue);
|
||||||
|
});
|
||||||
|
$scope.$watchCollection('configuration.plot.xAxis', function(newValue, oldValue){
|
||||||
|
self.updateConfiguration(newValue, oldValue);
|
||||||
|
});
|
||||||
|
($scope.children || []).forEach(function(child){
|
||||||
|
$scope.$watchCollection('configuration.plot.series[' + child.getId() + ']', function(newValue, oldValue){
|
||||||
|
self.updateConfiguration(newValue, oldValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -134,6 +146,7 @@ define(
|
|||||||
*/
|
*/
|
||||||
PlotOptionsController.prototype.updateConfiguration = function() {
|
PlotOptionsController.prototype.updateConfiguration = function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
console.log('form values changed');
|
||||||
this.domainObject.useCapability('mutation', function(model){
|
this.domainObject.useCapability('mutation', function(model){
|
||||||
model.configuration = model.configuration || {};
|
model.configuration = model.configuration || {};
|
||||||
model.configuration.plot = self.configuration.plot;
|
model.configuration.plot = self.configuration.plot;
|
||||||
|
@ -33,13 +33,7 @@ define(
|
|||||||
* @param topic
|
* @param topic
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function PlotOptionsForm(topic) {
|
function PlotOptionsForm() {
|
||||||
var self = this;
|
|
||||||
this.onchangeTopic = topic();
|
|
||||||
|
|
||||||
function onchange(value){
|
|
||||||
self.onchangeTopic.notify(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Defined below are the form structures for the plot options.
|
Defined below are the form structures for the plot options.
|
||||||
@ -149,10 +143,6 @@ define(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotOptionsForm.prototype.listen = function (callback){
|
|
||||||
return this.onchangeTopic.listen(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
return PlotOptionsForm;
|
return PlotOptionsForm;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -28,8 +28,6 @@ define(
|
|||||||
|
|
||||||
describe("The Plot Options controller", function () {
|
describe("The Plot Options controller", function () {
|
||||||
var plotOptionsController,
|
var plotOptionsController,
|
||||||
mockTopicFunction,
|
|
||||||
mockTopicObject,
|
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockMutationCapability,
|
mockMutationCapability,
|
||||||
mockUseCapabilities,
|
mockUseCapabilities,
|
||||||
@ -79,18 +77,6 @@ define(
|
|||||||
mockUnlisten = jasmine.createSpy('unlisten');
|
mockUnlisten = jasmine.createSpy('unlisten');
|
||||||
mockMutationCapability.listen.andReturn(mockUnlisten);
|
mockMutationCapability.listen.andReturn(mockUnlisten);
|
||||||
|
|
||||||
|
|
||||||
mockTopicObject = jasmine.createSpyObj('Topic', [
|
|
||||||
'listen',
|
|
||||||
'notify'
|
|
||||||
]);
|
|
||||||
mockFormUnlisten = jasmine.createSpy('formUnlisten');
|
|
||||||
mockTopicObject.listen.andReturn(mockFormUnlisten);
|
|
||||||
|
|
||||||
mockTopicFunction = function() {
|
|
||||||
return mockTopicObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
mockDomainObject = jasmine.createSpyObj('domainObject', [
|
||||||
'getModel',
|
'getModel',
|
||||||
'useCapability',
|
'useCapability',
|
||||||
@ -103,11 +89,12 @@ define(
|
|||||||
mockDomainObject.getModel.andReturn(model);
|
mockDomainObject.getModel.andReturn(model);
|
||||||
|
|
||||||
mockScope = jasmine.createSpyObj('scope', [
|
mockScope = jasmine.createSpyObj('scope', [
|
||||||
'$on'
|
'$on',
|
||||||
|
'$watchCollection'
|
||||||
]);
|
]);
|
||||||
mockScope.domainObject = mockDomainObject;
|
mockScope.domainObject = mockDomainObject;
|
||||||
|
|
||||||
plotOptionsController = new PlotOptionsController(mockScope, mockTopicFunction);
|
plotOptionsController = new PlotOptionsController(mockScope);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets form definitions on scope", function () {
|
it("sets form definitions on scope", function () {
|
||||||
@ -135,25 +122,24 @@ define(
|
|||||||
var scopeConfiguration = mockScope.configuration,
|
var scopeConfiguration = mockScope.configuration,
|
||||||
model = mockDomainObject.getModel();
|
model = mockDomainObject.getModel();
|
||||||
|
|
||||||
scopeConfiguration.plot.xAxis.key = 'lst';
|
|
||||||
scopeConfiguration.plot.yAxis.autoScale = true;
|
scopeConfiguration.plot.yAxis.autoScale = true;
|
||||||
scopeConfiguration.plot.yAxis.key = 'eu';
|
scopeConfiguration.plot.yAxis.key = 'eu';
|
||||||
|
scopeConfiguration.plot.xAxis.key = 'lst';
|
||||||
|
|
||||||
expect(mockTopicObject.listen).toHaveBeenCalled();
|
expect(mockScope.$watchCollection).toHaveBeenCalled();
|
||||||
mockTopicObject.listen.mostRecentCall.args[0]();
|
mockScope.$watchCollection.calls[0].args[1]();
|
||||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function));
|
expect(mockDomainObject.useCapability).toHaveBeenCalledWith('mutation', jasmine.any(Function));
|
||||||
|
|
||||||
mockDomainObject.useCapability.mostRecentCall.args[1](model);
|
mockDomainObject.useCapability.mostRecentCall.args[1](model);
|
||||||
expect(model.configuration.plot.xAxis.key).toBe('lst');
|
|
||||||
expect(model.configuration.plot.yAxis.autoScale).toBe(true);
|
expect(model.configuration.plot.yAxis.autoScale).toBe(true);
|
||||||
expect(model.configuration.plot.yAxis.key).toBe('eu');
|
expect(model.configuration.plot.yAxis.key).toBe('eu');
|
||||||
|
expect(model.configuration.plot.xAxis.key).toBe('lst');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up listeners on destruction of the controller", function () {
|
it("cleans up listeners on destruction of the controller", function () {
|
||||||
mockScope.$on.mostRecentCall.args[1]();
|
mockScope.$on.mostRecentCall.args[1]();
|
||||||
expect(mockUnlisten).toHaveBeenCalled();
|
expect(mockUnlisten).toHaveBeenCalled();
|
||||||
expect(mockFormUnlisten).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -28,21 +28,11 @@ define(
|
|||||||
|
|
||||||
describe("The Plot Options form", function () {
|
describe("The Plot Options form", function () {
|
||||||
var plotOptionsForm,
|
var plotOptionsForm,
|
||||||
mockTopicFunction,
|
|
||||||
mockTopicObject,
|
|
||||||
listener;
|
listener;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
|
||||||
mockTopicObject = jasmine.createSpyObj('Topic', [
|
plotOptionsForm = new PlotOptionsForm();
|
||||||
'listen',
|
|
||||||
'notify'
|
|
||||||
]);
|
|
||||||
mockTopicFunction = function() {
|
|
||||||
return mockTopicObject;
|
|
||||||
};
|
|
||||||
|
|
||||||
plotOptionsForm = new PlotOptionsForm(mockTopicFunction);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("defines form specs for x-axis, y-axis, and series data", function () {
|
it("defines form specs for x-axis, y-axis, and series data", function () {
|
||||||
@ -55,19 +45,6 @@ define(
|
|||||||
expect(plotOptionsForm.plotSeriesForm).toBeDefined();
|
expect(plotOptionsForm.plotSeriesForm).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("uses a topic to register a listener and inform them when a" +
|
|
||||||
" form value changes", function () {
|
|
||||||
var changedValue = 'changedValue';
|
|
||||||
|
|
||||||
expect(plotOptionsForm.xAxisForm.onchange).toBeDefined();
|
|
||||||
|
|
||||||
plotOptionsForm.listen(listener);
|
|
||||||
expect(mockTopicObject.listen).toHaveBeenCalledWith(listener);
|
|
||||||
|
|
||||||
plotOptionsForm.xAxisForm.onchange(changedValue);
|
|
||||||
expect(mockTopicObject.notify).toHaveBeenCalledWith(changedValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
name="mctControl"
|
name="mctControl"
|
||||||
ng-model="ngModel[field]"
|
ng-model="ngModel[field]"
|
||||||
ng-change="ngChange()"
|
|
||||||
ng-disabled="ngDisabled">
|
ng-disabled="ngDisabled">
|
||||||
<em></em>
|
<em></em>
|
||||||
</label>
|
</label>
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
name="mctControl"
|
name="mctControl"
|
||||||
ng-model="ngModel[field]"
|
ng-model="ngModel[field]"
|
||||||
ng-disabled="ngDisabled"
|
ng-disabled="ngDisabled"
|
||||||
ng-change="ngChange()"
|
|
||||||
ng-value="structure.value">
|
ng-value="structure.value">
|
||||||
<em></em>
|
<em></em>
|
||||||
</label>
|
</label>
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
ng-model="ngModel[field]"
|
ng-model="ngModel[field]"
|
||||||
ng-options="opt.value as opt.name for opt in options"
|
ng-options="opt.value as opt.name for opt in options"
|
||||||
ng-required="ngRequired"
|
ng-required="ngRequired"
|
||||||
ng-change="ngChange()"
|
|
||||||
name="mctControl">
|
name="mctControl">
|
||||||
<option value="" ng-show="!ngModel[field]">- Select One -</option>
|
<option value="" ng-show="!ngModel[field]">- Select One -</option>
|
||||||
</select>
|
</select>
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
ng-required="ngRequired"
|
ng-required="ngRequired"
|
||||||
ng-model="ngModel[field]"
|
ng-model="ngModel[field]"
|
||||||
ng-pattern="ngPattern"
|
ng-pattern="ngPattern"
|
||||||
ng-change="ngChange()"
|
|
||||||
size="{{structure.size}}"
|
size="{{structure.size}}"
|
||||||
name="mctControl">
|
name="mctControl">
|
||||||
</span>
|
</span>
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
<mct-control key="row.control"
|
<mct-control key="row.control"
|
||||||
ng-model="ngModel"
|
ng-model="ngModel"
|
||||||
ng-required="row.required"
|
ng-required="row.required"
|
||||||
ng-change="row.onchange(ngModel[row.key]); structure.onchange(ngModel)"
|
|
||||||
ng-pattern="getRegExp(row.pattern)"
|
ng-pattern="getRegExp(row.pattern)"
|
||||||
options="row.options"
|
options="row.options"
|
||||||
structure="row"
|
structure="row"
|
||||||
|
Reference in New Issue
Block a user