From 0c1f77cfabbcb6e87b79821d091cb112db1eef0b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 21 Sep 2015 10:53:45 -0700 Subject: [PATCH] [Mobile] Collapse tree on click Collapse tree any time a user does an action in the tree that would select an object; don't only do this on navigation changes, because this fails to detect occasions where user clicks the already-navigated-to object. --- platform/commonUI/browse/bundle.json | 2 +- .../commonUI/browse/res/templates/browse.html | 4 +- .../browse/src/BrowseTreeController.js | 39 ++++++++++--------- .../browse/test/BrowseTreeControllerSpec.js | 37 +----------------- .../general/res/templates/subtree.html | 1 + .../general/res/templates/tree-node.html | 12 +++--- .../commonUI/general/res/templates/tree.html | 3 +- .../src/controllers/TreeNodeController.js | 25 ++++++++++++ .../controllers/TreeNodeControllerSpec.js | 17 +++++++- 9 files changed, 75 insertions(+), 65 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 602884c09f..558dc389c1 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -29,7 +29,7 @@ "key": "BrowseTreeController", "implementation": "BrowseTreeController.js", "priority": "preferred", - "depends": [ "$scope", "navigationService", "agentService" ] + "depends": [ "$scope", "agentService" ] }, { "key": "BrowseObjectController", diff --git a/platform/commonUI/browse/res/templates/browse.html b/platform/commonUI/browse/res/templates/browse.html index 0e510fd014..e6255bcb55 100644 --- a/platform/commonUI/browse/res/templates/browse.html +++ b/platform/commonUI/browse/res/templates/browse.html @@ -41,6 +41,7 @@ ng-hide="treeModel.search"> @@ -51,7 +52,8 @@
- +
diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index a6d3560ee0..885646d606 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -39,7 +39,7 @@ class="mobile-hide" key="'label'" mct-object="domainObject" - ng-click="ngModel.selectedObject = domainObject" + ng-click="treeNode.select()" > @@ -60,7 +57,7 @@ mct-device="mobile" class='ui-symbol view-control' ng-model="ngModel" - ng-click="ngModel.selectedObject = domainObject" + ng-click="treeNode.select()" > } @@ -73,6 +70,7 @@ diff --git a/platform/commonUI/general/res/templates/tree.html b/platform/commonUI/general/res/templates/tree.html index bf807991b6..5ecdfb98c7 100644 --- a/platform/commonUI/general/res/templates/tree.html +++ b/platform/commonUI/general/res/templates/tree.html @@ -23,7 +23,8 @@
  • + ng-model="ngModel" + parameters="parameters">
  • diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index 7c21ee46aa..3efcf82d28 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -48,6 +48,15 @@ define( * node expansion when this tree node's _subtree_ will contain * the navigated object (recursively, this becomes an * expand-to-show-navigated-object behavior.) + * + * Finally, if a `callback` property is passed in through the + * `parameters` attribute of the `tree-node`, that callback + * will be invoked whenever a user clicks in a manner which + * would result in a selection. This callback is invoked + * even if the selection does not change (if you are only + * interested in changes, watch the `selectedObject` property + * of the object passed in `ng-model` instead.) + * * @memberof platform/commonUI/general * @constructor */ @@ -140,6 +149,22 @@ define( $scope.$watch("domainObject", checkSelection); } + /** + * Select the domain object represented by this node in the tree. + * This will both update the `selectedObject` property in + * the object passed in via `ng-model`, and will fire any `callback` + * passed in via `parameters`. + */ + TreeNodeController.prototype.select = function () { + if (this.$scope.ngModel) { + this.$scope.ngModel.selectedObject = + this.$scope.domainObject; + } + if ((this.$scope.parameters || {}).callback) { + this.$scope.parameters.callback(this.$scope.domainObject); + } + }; + /** * This method should be called when a node is expanded * to record that this has occurred, to support one-time diff --git a/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js b/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js index f2e5d1ae2d..52a8271bf2 100644 --- a/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js +++ b/platform/commonUI/general/test/controllers/TreeNodeControllerSpec.js @@ -47,7 +47,6 @@ define( mockScope = jasmine.createSpyObj("$scope", ["$watch", "$on", "$emit"]); mockTimeout = jasmine.createSpy("$timeout"); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile", "isPhone", "getOrientation"]); - mockNgModel = jasmine.createSpyObj("ngModel", ["selectedObject"]); mockDomainObject = jasmine.createSpyObj( "domainObject", [ "getId", "getCapability", "getModel", "useCapability" ] @@ -196,6 +195,22 @@ define( expect(controller.isSelected()).toBeFalsy(); }); + + it("exposes selected objects in scope", function () { + mockScope.domainObject = mockDomainObject; + mockScope.ngModel = {}; + controller.select(); + expect(mockScope.ngModel.selectedObject) + .toEqual(mockDomainObject); + }); + + it("invokes optional callbacks upon selection", function () { + mockScope.parameters = + { callback: jasmine.createSpy('callback') }; + controller.select(); + expect(mockScope.parameters.callback).toHaveBeenCalled(); + }); + }); } );