[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.
This commit is contained in:
Victor Woeltjen
2015-09-21 10:53:45 -07:00
parent ae4313253c
commit 0c1f77cfab
9 changed files with 75 additions and 65 deletions

View File

@@ -29,7 +29,7 @@
"key": "BrowseTreeController",
"implementation": "BrowseTreeController.js",
"priority": "preferred",
"depends": [ "$scope", "navigationService", "agentService" ]
"depends": [ "$scope", "agentService" ]
},
{
"key": "BrowseObjectController",

View File

@@ -41,6 +41,7 @@
ng-hide="treeModel.search">
<mct-representation key="'tree'"
mct-object="domainObject"
parameters="tree"
ng-model="treeModel">
</mct-representation>
</div>
@@ -51,7 +52,8 @@
<div class='split-pane-component items pane right-repr'>
<div class='holder abs l-mobile' id='content-area'>
<mct-representation mct-object="navigatedObject" key="'browse-object'">
<mct-representation mct-object="navigatedObject"
key="'browse-object'">
</mct-representation>
</div>
<div class="key-properties ui-symbol icon mobile-menu-icon desktop-hide"

View File

@@ -33,28 +33,29 @@ define(
* @constructor
* @memberof platform/commonUI/browse
*/
function BrowseTreeController($scope, navigationService, agentService) {
var object = navigationService.getNavigation(),
self = this;
function BrowseTreeController($scope, agentService) {
var self = this;
this.agentService = agentService;
this.state = true;
// Collapse tree when navigation changes
function changeObject(newObject) {
if (newObject !== object && agentService.isPortrait()) {
object = newObject;
/**
* Callback to invoke when any selection occurs in the tree.
* This controller can be passed in as the `parameters` object
* to the tree representation.
*
* @property {Function} callback
* @memberof platform/commonUI/browse.BrowseTreeController#
*/
this.callback = function () {
// Note that, since this is a callback to pass, this is not
// declared as a method but as a property which happens to
// be a function.
if (agentService.isPhone() && agentService.isPortrait()) {
// On phones, trees should collapse in portrait mode
// when something is navigated-to.
self.state = false;
}
}
// On phones, trees should collapse in portrait mode
// when something is navigated-to.
if (agentService.isPhone()) {
navigationService.addListener(changeObject);
$scope.$on("$destroy", function () {
navigationService.removeListener(changeObject);
});
}
this.state = true;
};
}
/**

View File

@@ -28,7 +28,6 @@ define(
describe("The BrowseTreeController", function () {
var mockScope,
mockNavigationService,
mockAgentService,
mockDomainObjects,
controller;
@@ -38,17 +37,12 @@ define(
function instantiateController() {
return new BrowseTreeController(
mockScope,
mockNavigationService,
mockAgentService
);
}
beforeEach(function () {
mockScope = jasmine.createSpyObj("$scope", [ "$on" ]);
mockNavigationService = jasmine.createSpyObj(
"navigationService",
[ "getNavigation", "addListener", "removeListener" ]
);
mockDomainObjects = ['a', 'b'].map(function (id) {
var mockDomainObject = jasmine.createSpyObj(
'domainObject-' + id,
@@ -64,8 +58,6 @@ define(
"agentService",
[ "isMobile", "isPhone", "isTablet", "isPortrait", "isLandscape" ]
);
mockNavigationService.getNavigation.andReturn(mockDomainObjects[0]);
});
it("is initially visible", function () {
@@ -87,37 +79,12 @@ define(
controller = instantiateController();
expect(controller.visible()).toBeTruthy();
// Simulate a navigation change
mockNavigationService.getNavigation.andReturn(mockDomainObjects[1]);
mockNavigationService.addListener.calls.forEach(function (call) {
call.args[0](mockDomainObjects[1]);
});
// Simulate a change from the tree by invoking controller's
controller.callback();
// Tree should have collapsed
expect(controller.visible()).toBeFalsy();
});
it("detaches registered listeners when the scope is destroyed", function () {
mockAgentService.isMobile.andReturn(true);
mockAgentService.isPhone.andReturn(true);
mockAgentService.isPortrait.andReturn(true);
controller = instantiateController();
// Verify precondition
expect(mockNavigationService.removeListener)
.not.toHaveBeenCalled();
mockScope.$on.calls.forEach(function (call) {
if (call.args[0] === '$destroy') {
call.args[1]();
}
});
expect(mockNavigationService.removeListener)
.toHaveBeenCalledWith(
mockNavigationService.addListener.mostRecentCall.args[0]
);
});
});
}
);