From 6a2bdd103bf5e00e51137bc34e5b50f0a6518591 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 24 Aug 2015 16:17:58 -0700 Subject: [PATCH] [Mobile] Hide Tree On selecting a node in the tree, if the user is on phone and in portrait, than emit up to the browse controller to call treeSlide(), which will hide the tree menu. Also adjusted the agent service to properly check for orientation using window.innerHeight/ Width. Also created function for the selection of an object in BrowseController. --- platform/commonUI/browse/src/BrowseController.js | 6 ++++++ platform/commonUI/general/bundle.json | 3 +-- .../commonUI/general/res/templates/tree-node.html | 5 ++--- .../general/src/controllers/TreeNodeController.js | 13 +++++++++++++ .../commonUI/general/src/services/AgentService.js | 6 +++--- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index c61260a400..65ac4467b8 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -187,6 +187,12 @@ define( navigationService.removeListener(setNavigation); }); + // If the user has selected an object (and is portrait + // on a phone), then hide the tree menu + $scope.$on("select-obj", function () { + $scope.treeSlide(); + }); + $scope.backArrow = navigateToParent; $scope.checkRoot = checkRoot; diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index f4ceed6ba1..7f5e2bfb86 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -11,8 +11,7 @@ }, { "key": "agentService", - "implementation": "/services/AgentService.js", - "depends": [ "$window" ] + "implementation": "/services/AgentService.js" } ], "runs": [ diff --git a/platform/commonUI/general/res/templates/tree-node.html b/platform/commonUI/general/res/templates/tree-node.html index 7f54b97180..9b094fe81d 100644 --- a/platform/commonUI/general/res/templates/tree-node.html +++ b/platform/commonUI/general/res/templates/tree-node.html @@ -29,15 +29,14 @@ key="'label'" mct-object="domainObject" ng-model="ngModel" - ng-click="!treeNode.checkMobile() ? ngModel.selectedObject = domainObject : - toggle.toggle(); treeNode.trackExpansion()" + ng-click="!treeNode.checkMobile() ? treeNode.setObject(ngModel, domainObject) : toggle.toggle(); treeNode.trackExpansion()" > diff --git a/platform/commonUI/general/src/controllers/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js index c55c3e2b6b..8d6becdfad 100644 --- a/platform/commonUI/general/src/controllers/TreeNodeController.js +++ b/platform/commonUI/general/src/controllers/TreeNodeController.js @@ -87,6 +87,17 @@ define( } } + // Sets the selected object in the tree, to be the + // currently represented object. If the user is on phone + // and in portrait mode, than, hide the tree menu + function setObject(ngModel, domainObject) { + ngModel.selectedObject = domainObject; + if (agentService.getOrientation() === "portrait" && + agentService.isPhone(navigator.userAgent)) { + $scope.$emit('select-obj'); + } + } + function checkMobile() { return agentService.isMobile(navigator.userAgent); } @@ -157,6 +168,8 @@ define( checkMobile: checkMobile, + setObject: setObject, + /** * Check if this not has ever been expanded. * @returns true if it has been expanded diff --git a/platform/commonUI/general/src/services/AgentService.js b/platform/commonUI/general/src/services/AgentService.js index 0d43cfdfa6..fa790e966f 100644 --- a/platform/commonUI/general/src/services/AgentService.js +++ b/platform/commonUI/general/src/services/AgentService.js @@ -35,7 +35,7 @@ define( * info using a comparison between the userAgent and key * device names */ - function AgentService($window) { + function AgentService() { // Gets the UA name if it is one of the following. // If it is not (a desktop for example) nothing is @@ -69,9 +69,9 @@ define( // Returns the orientation of the device based on the // device's window dimensions function getOrientation() { - if ($window.outerWidth > $window.outerHeight) { + if (window.innerWidth > window.innerHeight) { return "landscape"; - } else if ($window.outerWidth < $window.outerHeight) { + } else if (window.innerWidth < window.innerHeight) { return "portrait"; } }