diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index f8c230edd1..b4fad0dc56 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -78,11 +78,16 @@ "key": "navigationService", "implementation": "navigation/NavigationService.js" }, + { + "key": "urlService", + "implementation": "services/UrlService.js", + "depends": [ "$location" ] + }, { "key": "creationService", "implementation": "creation/CreationService.js", "depends": [ "persistenceService", "$q", "$log" ] - } + } ], "actions": [ { @@ -96,7 +101,7 @@ "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", "category": ["view-control", "contextual"], - "depends": [ "$window", "$route", "$location" ], + "depends": [ "urlService", "$window", "$route", "$location" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js new file mode 100644 index 0000000000..4fcf836d36 --- /dev/null +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -0,0 +1,59 @@ +/***************************************************************************** + * 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*/ + +/** + * Module defining UrlService. + */ +define( + [], + function () { + "use strict"; + + /** + * The navigation service maintains the application's current + * navigation state, and allows listening for changes thereto. + * @constructor + */ + function UrlService($location) { + function urlFor(mode, domainObject) { + var context = domainObject && + domainObject.getCapability('context'), + objectPath = context ? context.getPath() : [], + ids = objectPath.map(function (domainObject) { + return domainObject.getId();}), + viewPath = "?view=" + $location.search().view, + path = "index.html#/" + mode + "/" + + ids.slice(1).join("/") + viewPath; + return path; + } + + return { + + urlFor: urlFor + + }; + } + + return UrlService; + } +); \ No newline at end of file diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index e68696b273..5cad39686c 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -37,9 +37,11 @@ define( * the user interface.) * @constructor */ - function NewTabAction($window, $route, $location, context) { - - + function NewTabAction(urlService, $window, $route, $location, context) { + // Returns the selected domain object + // when using the context menu or the top right button + // based on the context and the existance of the object + // It is set to object an returned function getSelectedObject() { var object, newParent; @@ -53,25 +55,13 @@ define( } return { - /** - * Open the object in a new tab - */ - perform: function () { - var selectedDomainObject = getSelectedObject(), - mode = "browse", - context = selectedDomainObject && - selectedDomainObject.getCapability('context'), - objectPath = context ? context.getPath() : [], - ids = objectPath.map(function (selectedDomainObject) { - return selectedDomainObject.getId(); - }), - viewPath = "?view=" + $location.search().view, - partialPath = "index.html#/" + mode + "/" + - ids.slice(1).join("/") + viewPath; - - window.open(partialPath, "_blank"); - - + // Performs the open in new tab function + // By calling the url service, the mode needed + // (browse) and the domainObject is passed in and + // the path is returned and opened in a new tab + perform: function () { + window.open(urlService.urlFor("browse", getSelectedObject()), + "_blank"); } }; }