[Windowing] UrlService

UrlService added which takes in a
mode (browse or edit), and also a
domainObject. Returns the url
path to that domainObject. WTD-16.
This commit is contained in:
Shivam Dave 2015-06-23 16:11:06 -07:00
parent 21462bf60d
commit 61d9545414
3 changed files with 78 additions and 24 deletions

View File

@ -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"
},

View File

@ -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;
}
);

View File

@ -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");
}
};
}