mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 05:07:52 +00:00
[Tree] Simplify synchronization (#1100)
Simplify synchronization of selection in tree with state passed-in, letting Angular deal with more of the specifics. Fixes #1008.
This commit is contained in:
parent
0274490b68
commit
c8931f8535
@ -381,7 +381,7 @@ define([
|
|||||||
{
|
{
|
||||||
"key": "mctTree",
|
"key": "mctTree",
|
||||||
"implementation": MCTTree,
|
"implementation": MCTTree,
|
||||||
"depends": ['$parse', 'gestureService']
|
"depends": ['gestureService']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"constants": [
|
"constants": [
|
||||||
|
@ -24,20 +24,17 @@ define([
|
|||||||
'angular',
|
'angular',
|
||||||
'../ui/TreeView'
|
'../ui/TreeView'
|
||||||
], function (angular, TreeView) {
|
], function (angular, TreeView) {
|
||||||
function MCTTree($parse, gestureService) {
|
function MCTTree(gestureService) {
|
||||||
function link(scope, element, attrs) {
|
function link(scope, element) {
|
||||||
var treeView = new TreeView(gestureService),
|
var treeView = new TreeView(gestureService),
|
||||||
expr = $parse(attrs.mctModel),
|
|
||||||
unobserve = treeView.observe(function (domainObject) {
|
unobserve = treeView.observe(function (domainObject) {
|
||||||
if (domainObject !== expr(scope.$parent)) {
|
scope.mctModel = domainObject;
|
||||||
expr.assign(scope.$parent, domainObject);
|
|
||||||
scope.$apply();
|
scope.$apply();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
element.append(angular.element(treeView.elements()));
|
element.append(angular.element(treeView.elements()));
|
||||||
|
|
||||||
scope.$parent.$watch(attrs.mctModel, treeView.value.bind(treeView));
|
scope.$watch('mctModel', treeView.value.bind(treeView));
|
||||||
scope.$watch('mctObject', treeView.model.bind(treeView));
|
scope.$watch('mctObject', treeView.model.bind(treeView));
|
||||||
scope.$on('$destroy', unobserve);
|
scope.$on('$destroy', unobserve);
|
||||||
}
|
}
|
||||||
@ -45,7 +42,7 @@ define([
|
|||||||
return {
|
return {
|
||||||
restrict: "E",
|
restrict: "E",
|
||||||
link: link,
|
link: link,
|
||||||
scope: { mctObject: "=" }
|
scope: { mctObject: "=", mctModel: "=" }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ define([
|
|||||||
expect(mctTree.restrict).toEqual("E");
|
expect(mctTree.restrict).toEqual("E");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("two-way binds to mctObject", function () {
|
it("two-way binds to mctObject and mctModel", function () {
|
||||||
expect(mctTree.scope).toEqual({ mctObject: "=" });
|
expect(mctTree.scope).toEqual({ mctObject: "=", mctModel: "=" });
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("link", function () {
|
describe("link", function () {
|
||||||
@ -69,8 +69,8 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("watches for mct-model's expression in the parent", function () {
|
it("watches for mct-model's expression in the parent", function () {
|
||||||
expect(mockScope.$parent.$watch).toHaveBeenCalledWith(
|
expect(mockScope.$watch).toHaveBeenCalledWith(
|
||||||
testAttrs.mctModel,
|
"mctModel",
|
||||||
jasmine.any(Function)
|
jasmine.any(Function)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user