From fec6f06849bb947ae531c8202960a8bec31169a2 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 16 Jun 2015 14:58:03 -0700 Subject: [PATCH] [Addressability] Obey view query string param Obey the query string parameter for a view, if present. WTD-1149. --- platform/commonUI/browse/bundle.json | 5 ++ .../browse/res/templates/browse-object.html | 4 +- .../browse/src/BrowseObjectController.js | 55 +++++++++++++++++++ .../src/controllers/ViewSwitcherController.js | 16 +++--- 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 platform/commonUI/browse/src/BrowseObjectController.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index b367d02510..1f019991e9 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -16,6 +16,11 @@ "implementation": "BrowseController.js", "depends": [ "$scope", "$route", "$location", "objectService", "navigationService" ] }, + { + "key": "BrowseObjectController", + "implementation": "BrowseObjectController.js", + "depends": [ "$scope", "$location" ] + }, { "key": "CreateMenuController", "implementation": "creation/CreateMenuController", diff --git a/platform/commonUI/browse/res/templates/browse-object.html b/platform/commonUI/browse/res/templates/browse-object.html index d88f32c18b..6730d5a186 100644 --- a/platform/commonUI/browse/res/templates/browse-object.html +++ b/platform/commonUI/browse/res/templates/browse-object.html @@ -19,7 +19,7 @@ this source code distribution or the Licensing information page available at runtime from the About dialog for additional information. --> - +
@@ -44,4 +44,4 @@ mct-object="representation.selected.key && domainObject">
- \ No newline at end of file + diff --git a/platform/commonUI/browse/src/BrowseObjectController.js b/platform/commonUI/browse/src/BrowseObjectController.js new file mode 100644 index 0000000000..2385a153d1 --- /dev/null +++ b/platform/commonUI/browse/src/BrowseObjectController.js @@ -0,0 +1,55 @@ +/***************************************************************************** + * 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,Promise*/ + +define( + [], + function () { + "use strict"; + + /** + * Controller for the `browse-object` representation of a domain + * object (the right-hand side of Browse mode.) + * @constructor + */ + function BrowseObjectController($scope, $location) { + function setViewForDomainObject(domainObject) { + var locationViewKey = $location.search().view; + + function selectViewIfMatching(view) { + if (view.key === locationViewKey) { + $scope.representation.selected = view; + } + } + + if (locationViewKey) { + ((domainObject && domainObject.useCapability('view')) || []) + .forEach(selectViewIfMatching); + } + } + + $scope.$watch('domainObject', setViewForDomainObject); + } + + return BrowseObjectController; + } +); diff --git a/platform/commonUI/general/src/controllers/ViewSwitcherController.js b/platform/commonUI/general/src/controllers/ViewSwitcherController.js index a821d1f326..69674013d5 100644 --- a/platform/commonUI/general/src/controllers/ViewSwitcherController.js +++ b/platform/commonUI/general/src/controllers/ViewSwitcherController.js @@ -53,12 +53,14 @@ define( // Get list of views, read from capability function updateOptions(views) { - $timeout(function () { - $scope.ngModel.selected = findMatchingOption( - views || [], - ($scope.ngModel || {}).selected - ); - }, 0); + if (Array.isArray(views)) { + $timeout(function () { + $scope.ngModel.selected = findMatchingOption( + views, + ($scope.ngModel || {}).selected + ); + }, 0); + } } // Update view options when the in-scope results of using the @@ -68,4 +70,4 @@ define( return ViewSwitcherController; } -); \ No newline at end of file +);