mirror of
https://github.com/nasa/openmct.git
synced 2025-04-09 04:14:32 +00:00
commit
2161707954
@ -16,7 +16,7 @@
|
||||
{
|
||||
"key": "BrowseController",
|
||||
"implementation": "BrowseController.js",
|
||||
"depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService"]
|
||||
"depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService" ]
|
||||
},
|
||||
{
|
||||
"key": "BrowseObjectController",
|
||||
@ -77,12 +77,7 @@
|
||||
{
|
||||
"key": "navigationService",
|
||||
"implementation": "navigation/NavigationService.js"
|
||||
},
|
||||
{
|
||||
"key": "urlService",
|
||||
"implementation": "services/UrlService.js",
|
||||
"depends": [ "$location" ]
|
||||
},
|
||||
},
|
||||
{
|
||||
"key": "creationService",
|
||||
"implementation": "creation/CreationService.js",
|
||||
|
@ -55,10 +55,11 @@ define(
|
||||
$route.current = priorRoute;
|
||||
unlisten();
|
||||
});
|
||||
// urlService.urlFor used to adjust current
|
||||
// urlService.urlForLocation used to adjust current
|
||||
// path to new, addressed, path based on
|
||||
// domainObject
|
||||
$location.path(urlService.urlFor("browse", domainObject));
|
||||
$location.path(urlService.urlForLocation("browse", domainObject));
|
||||
|
||||
}
|
||||
|
||||
// Callback for updating the in-scope reference to the object
|
||||
|
@ -56,7 +56,7 @@ define(
|
||||
// (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()),
|
||||
$window.open(urlService.urlForNewTab("browse", getSelectedObject()),
|
||||
"_blank");
|
||||
}
|
||||
};
|
||||
|
@ -61,7 +61,7 @@ define(
|
||||
);
|
||||
mockUrlService = jasmine.createSpyObj(
|
||||
"urlService",
|
||||
["urlFor"]
|
||||
["urlForLocation"]
|
||||
);
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
@ -225,7 +225,7 @@ define(
|
||||
// location.path to be called with the urlService's
|
||||
// urlFor function with the next domainObject and mode
|
||||
expect(mockLocation.path).toHaveBeenCalledWith(
|
||||
mockUrlService.urlFor(mockMode, mockNextObject)
|
||||
mockUrlService.urlForLocation(mockMode, mockNextObject)
|
||||
);
|
||||
|
||||
// Exercise the Angular workaround
|
||||
|
@ -9,7 +9,6 @@
|
||||
"creation/LocatorController",
|
||||
"navigation/NavigateAction",
|
||||
"navigation/NavigationService",
|
||||
"services/UrlService",
|
||||
"windowing/FullscreenAction",
|
||||
"windowing/NewTabAction",
|
||||
"windowing/WindowTitler"
|
||||
|
@ -53,7 +53,7 @@ define(
|
||||
|
||||
// Mocks the urlService used to make the new tab's url from a
|
||||
// domainObject and mode
|
||||
mockUrlService = jasmine.createSpyObj("urlService", ["urlFor"]);
|
||||
mockUrlService = jasmine.createSpyObj("urlService", ["urlForNewTab"]);
|
||||
|
||||
// Action done using the current context or mockContextCurrent
|
||||
actionCurrent = new NewTabAction(mockUrlService, mockWindow,
|
||||
|
@ -67,7 +67,7 @@
|
||||
"implementation": "actions/SaveAction.js",
|
||||
"name": "Save",
|
||||
"description": "Save changes made to these objects.",
|
||||
"depends": [ "$location" ],
|
||||
"depends": [ "$location", "urlService" ],
|
||||
"priority": "mandatory"
|
||||
},
|
||||
{
|
||||
@ -76,7 +76,7 @@
|
||||
"implementation": "actions/CancelAction.js",
|
||||
"name": "Cancel",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": [ "$location" ]
|
||||
"depends": [ "$location", "urlService" ]
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
@ -116,7 +116,7 @@
|
||||
"key": "topbar-edit",
|
||||
"templateUrl": "templates/topbar-edit.html"
|
||||
}
|
||||
],
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": "representers/EditRepresenter.js",
|
||||
|
@ -30,7 +30,7 @@ define(
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
*/
|
||||
function CancelAction($location, context) {
|
||||
function CancelAction($location, urlService, context) {
|
||||
var domainObject = context.domainObject;
|
||||
|
||||
// Look up the object's "editor.completion" capability;
|
||||
@ -50,7 +50,10 @@ define(
|
||||
// Discard the current root view (which will be the editing
|
||||
// UI, which will have been pushed atop the Browise UI.)
|
||||
function returnToBrowse() {
|
||||
$location.path("/browse");
|
||||
$location.path($location.path(urlService.urlForLocation(
|
||||
"browse",
|
||||
domainObject
|
||||
)));
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -31,7 +31,7 @@ define(
|
||||
* Edit Mode. Exits the editing user interface and invokes object
|
||||
* capabilities to persist the changes that have been made.
|
||||
*/
|
||||
function SaveAction($location, context) {
|
||||
function SaveAction($location, urlService, context) {
|
||||
var domainObject = context.domainObject;
|
||||
|
||||
// Invoke any save behavior introduced by the editor capability;
|
||||
@ -45,7 +45,10 @@ define(
|
||||
// Discard the current root view (which will be the editing
|
||||
// UI, which will have been pushed atop the Browise UI.)
|
||||
function returnToBrowse() {
|
||||
return $location.path("/browse");
|
||||
return $location.path(urlService.urlForLocation(
|
||||
"browse",
|
||||
domainObject
|
||||
));
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -30,6 +30,7 @@ define(
|
||||
var mockLocation,
|
||||
mockDomainObject,
|
||||
mockEditorCapability,
|
||||
mockUrlService,
|
||||
actionContext,
|
||||
action;
|
||||
|
||||
@ -54,7 +55,10 @@ define(
|
||||
"editor",
|
||||
[ "save", "cancel" ]
|
||||
);
|
||||
|
||||
mockUrlService = jasmine.createSpyObj(
|
||||
"urlService",
|
||||
["urlForLocation"]
|
||||
);
|
||||
|
||||
actionContext = {
|
||||
domainObject: mockDomainObject
|
||||
@ -64,7 +68,7 @@ define(
|
||||
mockDomainObject.getCapability.andReturn(mockEditorCapability);
|
||||
mockEditorCapability.cancel.andReturn(mockPromise(true));
|
||||
|
||||
action = new CancelAction(mockLocation, actionContext);
|
||||
action = new CancelAction(mockLocation, mockUrlService, actionContext);
|
||||
|
||||
});
|
||||
|
||||
@ -91,7 +95,9 @@ define(
|
||||
|
||||
it("returns to browse when performed", function () {
|
||||
action.perform();
|
||||
expect(mockLocation.path).toHaveBeenCalledWith("/browse");
|
||||
expect(mockLocation.path).toHaveBeenCalledWith(
|
||||
mockUrlService.urlForLocation("browse", mockDomainObject)
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ define(
|
||||
var mockLocation,
|
||||
mockDomainObject,
|
||||
mockEditorCapability,
|
||||
mockUrlService,
|
||||
actionContext,
|
||||
action;
|
||||
|
||||
@ -54,6 +55,10 @@ define(
|
||||
"editor",
|
||||
[ "save", "cancel" ]
|
||||
);
|
||||
mockUrlService = jasmine.createSpyObj(
|
||||
"urlService",
|
||||
["urlForLocation"]
|
||||
);
|
||||
|
||||
|
||||
actionContext = {
|
||||
@ -64,7 +69,7 @@ define(
|
||||
mockDomainObject.getCapability.andReturn(mockEditorCapability);
|
||||
mockEditorCapability.save.andReturn(mockPromise(true));
|
||||
|
||||
action = new SaveAction(mockLocation, actionContext);
|
||||
action = new SaveAction(mockLocation, mockUrlService, actionContext);
|
||||
|
||||
});
|
||||
|
||||
@ -91,7 +96,9 @@ define(
|
||||
|
||||
it("returns to browse when performed", function () {
|
||||
action.perform();
|
||||
expect(mockLocation.path).toHaveBeenCalledWith("/browse");
|
||||
expect(mockLocation.path).toHaveBeenCalledWith(
|
||||
mockUrlService.urlForLocation("browse", mockDomainObject)
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,13 @@
|
||||
"description": "General UI elements, meant to be reused across modes",
|
||||
"resources": "res",
|
||||
"extensions": {
|
||||
"services": [
|
||||
{
|
||||
"key": "urlService",
|
||||
"implementation": "/services/UrlService.js",
|
||||
"depends": [ "$location" ]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": "StyleSheetLoader.js",
|
||||
|
@ -39,34 +39,52 @@ define(
|
||||
// is returned. The view is defaulted to
|
||||
// the current location's (current object's)
|
||||
// view set.
|
||||
function urlFor(mode, domainObject) {
|
||||
function urlForLocation(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,
|
||||
// Parses the path together. Starts with the
|
||||
// default index.html file, then the mode passed
|
||||
// into the service, followed by ids in the url
|
||||
// joined by '/', and lastly the view path from
|
||||
// the current location
|
||||
path = "index.html#/" + mode + "/" +
|
||||
ids.slice(1).join("/") + viewPath;
|
||||
|
||||
path = mode + "/" + ids.slice(1).join("/");
|
||||
return path;
|
||||
}
|
||||
|
||||
// Uses the Url for the current location
|
||||
// from the urlForLocation function and
|
||||
// includes the view and the index path
|
||||
function urlForNewTab(mode, domainObject) {
|
||||
var viewPath = "?view=" + $location.search().view,
|
||||
newTabPath =
|
||||
"index.html#" + urlForLocation(mode, domainObject) + viewPath;
|
||||
return newTabPath;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* without the index.html path and the view path
|
||||
* @param {value} value of the browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
*/
|
||||
urlFor: urlFor
|
||||
urlForNewTab: urlForNewTab,
|
||||
/**
|
||||
* Returns the Url path for a specific domain object
|
||||
* including the index.html path and the view path
|
||||
* allowing a new tab to hold the correct characteristics
|
||||
* @param {value} value of the browse or edit mode
|
||||
* for the path
|
||||
* @param {DomainObject} value of the domain object
|
||||
* to get the path of
|
||||
*/
|
||||
urlForLocation: urlForLocation
|
||||
};
|
||||
}
|
||||
|
@ -31,7 +31,11 @@ define(
|
||||
|
||||
describe("The url service", function () {
|
||||
var urlService,
|
||||
mockLocation;
|
||||
mockLocation,
|
||||
mockDomainObject,
|
||||
mockContext,
|
||||
mockMode,
|
||||
testViews;
|
||||
|
||||
beforeEach(function () {
|
||||
// Creates a mockLocation, used to
|
||||
@ -41,24 +45,20 @@ define(
|
||||
[ "path", "search" ]
|
||||
);
|
||||
|
||||
urlService = new UrlService(mockLocation);
|
||||
});
|
||||
|
||||
it("get url for a domainObject and mode", function () {
|
||||
// The mockDomainObject is initialized as a
|
||||
// The mockDomainObject is initialized as a
|
||||
// spy object to ultimately be passed into the
|
||||
// urlService urlFor function
|
||||
var mockDomainObject = jasmine.createSpyObj(
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability", "getModel", "useCapability" ]
|
||||
),
|
||||
mockContext = jasmine.createSpyObj('context', ['getPath']),
|
||||
testViews = [
|
||||
{ key: 'abc' },
|
||||
{ key: 'def', someKey: 'some value' },
|
||||
{ key: 'xyz' }
|
||||
],
|
||||
mockMode = "browse";
|
||||
);
|
||||
mockContext = jasmine.createSpyObj('context', ['getPath']);
|
||||
testViews = [
|
||||
{ key: 'abc' },
|
||||
{ key: 'def', someKey: 'some value' },
|
||||
{ key: 'xyz' }
|
||||
];
|
||||
mockMode = "browse";
|
||||
|
||||
// The mockContext is set a path
|
||||
// for the mockDomainObject
|
||||
@ -81,8 +81,17 @@ define(
|
||||
// Uses the mockLocation to get the current
|
||||
// "mock" website's view
|
||||
mockLocation.search.andReturn({ view: 'def' });
|
||||
urlService.urlFor(mockMode, mockDomainObject);
|
||||
|
||||
urlService = new UrlService(mockLocation);
|
||||
});
|
||||
|
||||
it("get url for a location using domainObject and mode", function () {
|
||||
urlService.urlForLocation(mockMode, mockDomainObject);
|
||||
});
|
||||
|
||||
it("get url for a new tab using domainObject and mode", function () {
|
||||
urlService.urlForNewTab(mockMode, mockDomainObject);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -13,5 +13,6 @@
|
||||
"directives/MCTDrag",
|
||||
"directives/MCTResize",
|
||||
"directives/MCTScroll",
|
||||
"services/UrlService",
|
||||
"StyleSheetLoader"
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user