mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 23:36:41 +00:00
[Browse] Separate out back-arrow behavior
Supports integration of changes for mobile, nasa/openmct#95
This commit is contained in:
parent
de6dfe1fdc
commit
d981e7bb1d
@ -16,7 +16,14 @@
|
||||
{
|
||||
"key": "BrowseController",
|
||||
"implementation": "BrowseController.js",
|
||||
"depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService" ]
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$route",
|
||||
"$location",
|
||||
"objectService",
|
||||
"navigationService",
|
||||
"urlService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "BrowseObjectController",
|
||||
@ -25,17 +32,22 @@
|
||||
},
|
||||
{
|
||||
"key": "CreateMenuController",
|
||||
"implementation": "creation/CreateMenuController",
|
||||
"implementation": "creation/CreateMenuController.js",
|
||||
"depends": [ "$scope" ]
|
||||
},
|
||||
{
|
||||
"key": "LocatorController",
|
||||
"implementation": "creation/LocatorController",
|
||||
"implementation": "creation/LocatorController.js",
|
||||
"depends": [ "$scope", "$timeout" ]
|
||||
},
|
||||
{
|
||||
"key": "MenuArrowController",
|
||||
"implementation": "MenuArrowController",
|
||||
"implementation": "MenuArrowController.js",
|
||||
"depends": [ "$scope" ]
|
||||
},
|
||||
{
|
||||
"key": "BackArrowController",
|
||||
"implementation": "BackArrowController.js",
|
||||
"depends": [ "$scope" ]
|
||||
}
|
||||
],
|
||||
|
@ -21,8 +21,7 @@
|
||||
-->
|
||||
|
||||
<!-- Back Arrow Icon used on mobile-->
|
||||
<a ng-controller="BrowseController"
|
||||
<a ng-controller="BackArrowController"
|
||||
class='type-icon icon ui-symbol s-back'
|
||||
ng-class="checkRoot(); atRoot ? 'hidden' : ''"
|
||||
ng-click='backArrow()'>{
|
||||
</a>
|
||||
ng-hide="atRoot"
|
||||
ng-click='navigateToParent()'>{</a>
|
||||
|
@ -22,7 +22,9 @@
|
||||
<span ng-controller="BrowseObjectController">
|
||||
<div class="object-browse-bar bar l-flex">
|
||||
<div class="items-select left">
|
||||
<mct-representation key="'back-arrow'" class="l-back"></mct-representation>
|
||||
<mct-representation key="'back-arrow'"
|
||||
mct-object="domainObject"
|
||||
class="l-back"></mct-representation>
|
||||
<mct-representation key="'object-header'" mct-object="domainObject">
|
||||
</mct-representation>
|
||||
</div>
|
||||
|
64
platform/commonUI/browse/src/BackArrowController.js
Normal file
64
platform/commonUI/browse/src/BackArrowController.js
Normal file
@ -0,0 +1,64 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
|
||||
/*global define*/
|
||||
define(
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
function BackArrowController($scope) {
|
||||
function navigateTo(parentObject) {
|
||||
var action =
|
||||
parentObject && parentObject.getCapability('action');
|
||||
if (action) {
|
||||
action.perform('navigate');
|
||||
}
|
||||
}
|
||||
|
||||
function navigateToParent() {
|
||||
var domainObject = $scope.domainObject,
|
||||
context =
|
||||
domainObject && domainObject.getCapability('context');
|
||||
if (context) {
|
||||
navigateTo(context.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
function checkRoot(domainObject) {
|
||||
var context =
|
||||
domainObject && domainObject.getCapability('context');
|
||||
|
||||
// We don't want to show the arrow if there is no context
|
||||
// for this object, or if there is not a meaningful parent
|
||||
// we can go back to.
|
||||
$scope.atRoot = (!context) || (context.getPath().length < 3);
|
||||
}
|
||||
|
||||
$scope.navigateToParent = navigateToParent;
|
||||
$scope.$watch("domainObject", checkRoot);
|
||||
}
|
||||
|
||||
return BackArrowController;
|
||||
|
||||
|
||||
}
|
||||
);
|
@ -128,78 +128,6 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
// Uses the current navigation to get the
|
||||
// current ContextCapability, then the
|
||||
// parent is gotten from that. If the parent
|
||||
// is not the root, then user is navigated to
|
||||
// parent
|
||||
function navigateToParent() {
|
||||
var context = navigationService.getNavigation().getCapability('context'),
|
||||
parentContext,
|
||||
parent,
|
||||
grandparentId;
|
||||
|
||||
// Checks if the current object has a context
|
||||
if (context) {
|
||||
|
||||
// Sets the parent and the parent context
|
||||
// which is checked
|
||||
parent = context.getParent();
|
||||
parentContext = parent.getCapability('context');
|
||||
|
||||
if ((parent.getId() !== ROOT_ID) && parentContext) {
|
||||
// Gets the grandparent id
|
||||
grandparentId = parentContext.getParent().getId();
|
||||
|
||||
// Navigates to the parent
|
||||
navigateTo(parent);
|
||||
|
||||
// Checks after navigation if the user is located at the
|
||||
// root (grandparent of original selected object, after
|
||||
// navigation, user is at parent of original object and
|
||||
// child of grandparent)
|
||||
if (grandparentId && grandparentId !== ROOT_ID) {
|
||||
$scope.atRoot = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Set at root if no grandparent exists and
|
||||
// if grandparent is ROOT, after navigation
|
||||
$scope.atRoot = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkRoot() {
|
||||
var context = navigationService.getNavigation().getCapability('context'),
|
||||
parentContext,
|
||||
parent,
|
||||
grandparent;
|
||||
|
||||
// Checks if the current object has a context
|
||||
if (context) {
|
||||
parent = context.getParent();
|
||||
parentContext = parent.getCapability('context');
|
||||
if ((parent.getId() !== ROOT_ID) && parentContext) {
|
||||
grandparent = parentContext.getParent();
|
||||
|
||||
// Checks if the grandparent exists
|
||||
// if it does not exist (for example in search),
|
||||
// than do not show the back button
|
||||
if (grandparent) {
|
||||
$scope.atRoot = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// In any other situation where the context or parent
|
||||
// context does not exist or the user is at ROOT, than
|
||||
// hide the back arrow
|
||||
$scope.atRoot = true;
|
||||
|
||||
}
|
||||
|
||||
// Load the root object, put it in the scope.
|
||||
// Also, load its immediate children, and (possibly)
|
||||
// navigate to one of them, so that navigation state has
|
||||
@ -236,11 +164,6 @@ define(
|
||||
$scope.$on("select-obj", function () {
|
||||
$scope.treeSlide();
|
||||
});
|
||||
|
||||
$scope.backArrow = navigateToParent;
|
||||
|
||||
$scope.checkRoot = checkRoot;
|
||||
|
||||
}
|
||||
|
||||
return BrowseController;
|
||||
|
@ -265,116 +265,6 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
it("checks if the user is current navigated to the root", function () {
|
||||
var mockContext = jasmine.createSpyObj('context', ['getParent']);
|
||||
|
||||
mockRoute.current.params.ids = "ROOT/mine";
|
||||
mockParent.getId.andReturn("ROOT");
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
return c === 'context' && mockContext;
|
||||
});
|
||||
|
||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockParent.getCapability.andCallFake(function (c) {
|
||||
return c === 'context' && mockParentContext;
|
||||
});
|
||||
mockParentContext.getParent.andReturn(mockGrandparent);
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.checkRoot();
|
||||
|
||||
mockRoute.current.params.ids = "mine/junk";
|
||||
mockParent.getId.andReturn("mine");
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.checkRoot();
|
||||
|
||||
mockDomainObject.getCapability.andReturn(undefined);
|
||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.checkRoot();
|
||||
});
|
||||
|
||||
// Mocks the back arrow call that
|
||||
// lets the html code know the back
|
||||
// arrow navigation needs to be done
|
||||
it("calls the backArrow function", function () {
|
||||
var mockContext = jasmine.createSpyObj('context', ['getParent']);
|
||||
|
||||
mockRoute.current.params.ids = "mine/junk";
|
||||
mockParent.getId.andReturn("mine");
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (c) {
|
||||
return c === 'context' && mockContext;
|
||||
});
|
||||
|
||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockParent.getCapability.andCallFake(function (c) {
|
||||
return c === 'context' && mockParentContext;
|
||||
});
|
||||
mockParentContext.getParent.andReturn(mockGrandparent);
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.backArrow();
|
||||
|
||||
mockRoute.current.params.ids = "mine/lessjunk/morejunk";
|
||||
mockGrandparent.getId.andReturn("mine");
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.backArrow();
|
||||
|
||||
mockRoute.current.params.ids = "ROOT/mine";
|
||||
mockParent.getId.andReturn("ROOT");
|
||||
|
||||
controller = new BrowseController(
|
||||
mockScope,
|
||||
mockRoute,
|
||||
mockLocation,
|
||||
mockObjectService,
|
||||
mockNavigationService
|
||||
);
|
||||
|
||||
mockScope.backArrow();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user